|
@ -79,58 +79,6 @@ class File { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
formatDateToCustomFormat(date) { |
|
|
|
|
|
// Obtenir les composantes de la date et de l'heure
|
|
|
|
|
|
const year = date.getFullYear(); |
|
|
|
|
|
const month = String(date.getMonth() + 1).padStart(2, "0"); // Janvier est 0, février est 1, etc.
|
|
|
|
|
|
const day = String(date.getDate()).padStart(2, "0"); |
|
|
|
|
|
const hours = String(date.getHours()).padStart(2, "0"); |
|
|
|
|
|
const minutes = String(date.getMinutes()).padStart(2, "0"); |
|
|
|
|
|
const seconds = String(date.getSeconds()).padStart(2, "0"); |
|
|
|
|
|
|
|
|
|
|
|
// Créer la chaîne au format personnalisé
|
|
|
|
|
|
const formattedDate = `${year}-${month}-${day}_${hours}-${minutes}-${seconds}`; |
|
|
|
|
|
|
|
|
|
|
|
return formattedDate; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Create a generateFilePath function witch returns a path with a filename and datetime
|
|
|
|
|
|
generateFilePath(filename) { |
|
|
|
|
|
const date = new Date(); |
|
|
|
|
|
return { |
|
|
|
|
|
filepath: path.join( |
|
|
|
|
|
dest, |
|
|
|
|
|
`${filename}-${this.formatDateToCustomFormat(date)}.csv` |
|
|
|
|
|
), |
|
|
|
|
|
generatedpath: path.join( |
|
|
|
|
|
dest, |
|
|
|
|
|
`${filename}-generated-${this.formatDateToCustomFormat(date)}.csv` |
|
|
|
|
|
), |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Download a file from a url |
|
|
|
|
|
* @returns {Promise<string>} filepath |
|
|
|
|
|
*/ |
|
|
|
|
|
async fakeDownload() { |
|
|
|
|
|
const url = URL.parse(this.url); |
|
|
|
|
|
this.filename = slugify(url.hostname, { lower: true }); |
|
|
|
|
|
const filepath = path.join( |
|
|
|
|
|
dest, |
|
|
|
|
|
`bodacc-datadila.opendatasoft.com-1697536785170.csv` |
|
|
|
|
|
); |
|
|
|
|
|
const generatedpath = path.join( |
|
|
|
|
|
dest, |
|
|
|
|
|
`bodacc-datadila.opendatasoft.com-generated-1697536785170-2.csv` |
|
|
|
|
|
); |
|
|
|
|
|
this.filepath = filepath; |
|
|
|
|
|
this.generatedpath = generatedpath; |
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
resolve(filepath); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Download a file from a url |
|
|
* Download a file from a url |
|
|
* @returns {Promise<string>} filepath |
|
|
* @returns {Promise<string>} filepath |
|
|