diff --git a/README.md b/README.md index 0367ca8..180047f 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,22 @@ mais ce n'est pas encore prêt à être utilisé en production. "npm start" gives you a demo of what Rangement can do, but this is not a production ready package yet. +# done + +* Handle verbosity levels in logs + - log.trace(msg) + - log.debug(msg) + - log.info(msg) + - log.warn(msg) + - log.error(msg) + + # Roadmap +* Internationalisation of console texts * Proper testing -* Handle verbosity levels +* Template configuration for auto dispatching of files after rename * Handle a configuration file - * create config file if needed +- * create config file if needed * batch rename like the python pip script "guessfilename" * revert renaming actions - * Log renaming actions +- * Log renaming actions diff --git a/configs.mjs b/configs.mjs index f9c8fd9..da79b8f 100644 --- a/configs.mjs +++ b/configs.mjs @@ -1,45 +1,57 @@ - -export default class config_rangement{ - log_level ='debug' // [ 'debug' 'none'] - version = '1.0.0' - tagSeparator = '1.0.0' - tagSectionSeparator = '1.0.0' - enableTestsLocally= false - reportStatistics= false - base_archive_folder= '/home/poule/encrypted/stockage-syncable/' - photos_sub_folder= 'photos' - photos_sorting_base_sub_folder= 'photos/a_dispatcher' - bazar_sub_folder= 'BAZAR' - panoramax_captures_folder= 'photos/imagerie kartaview carto tel/open camera' - templates = { - // example FyB8cZnWIAc21rw.jpg - 'downloaded_pic': { - 'pattern' : /^\-\w{15}\.jpg/, - 'auto_sort_folder' : this.bazar_sub_folder - }, - // example -4900281569878475578_1109.jpg - 'telegram_pic': { - 'pattern' : /^\-\d{19}_\d{4}/, - 'auto_sort_folder' : '' - }, - // example IMG_20230617_092120_3.jpg - 'open_camera_default': { - 'pattern' : /^IMG_\d{8}/i, - 'auto_sort_folder' : this.panoramax_captures_folder - }, - // example IMG_OC_20230617_092120_3.jpg - 'open_camera_custom': { - 'pattern' : /^IMG_OC_\d{8}/i, - 'auto_sort_folder' : this.panoramax_captures_folder - }, - // example "Screenshot 2023-06-15 at 15-26-04 Instance Panoramax OSM-FR.png" - 'screenshot': { - 'pattern' : /^Screenshot/i, - 'auto_sort_folder': 'photos/captures écran screenshots' - } , - } +class config_rangement { + log_level = 'info' // 'debug' | 'warn' |'info' + version = '1.0.0' + iso_date_format = 'yyyy-MM-DDTHH.mm.ss' // target format for dates in file names + tagSeparator = ' ' + tagSectionSeparator = '--' + keepFreeText = true + keepTags = true + replaceUnderscoreWithSpaces = true + renameFolders = false + enableTestsLocally = false + reportStatistics = false + base_archive_folder = '/home/poule/encrypted/stockage-syncable/' + photos_sub_folder = this.base_archive_folder + 'photos/' + photos_sorting_base_sub_folder = this.base_archive_folder + 'photos/a_dispatcher/' + bazar_sub_folder = this.base_archive_folder + 'BAZAR/' + panoramax_captures_folder = 'photos/imagerie kartaview carto tel/open camera/' + templates = { + // example FyB8cZnWIAc21rw.jpg + 'downloaded_pic': { + 'pattern': /^\-\w{15}\.jpg/, + 'auto_sort_folder': this.bazar_sub_folder + }, + // example -4900281569878475578_1109.jpg + 'telegram_pic': { + 'pattern': /^\-\d{19}_\d{4}/, + 'auto_sort_folder': this.bazar_sub_folder + }, + // example IMG_20230617_092120_3.jpg + 'open_camera_default': { + 'pattern': /^IMG_\d{8}/i, + 'auto_sort_folder': this.panoramax_captures_folder + }, + // example IMG_OC_20230617_092120_3.jpg + 'open_camera_custom': { + 'pattern': /^IMG_OC_\d{8}/i, + 'auto_sort_folder': this.panoramax_captures_folder + }, + // example "Screenshot 2023-06-15 at 15-26-04 Instance Panoramax OSM-FR.png" + 'screenshot': { + 'pattern': /^Screenshot/i, + 'auto_sort_folder': 'photos/captures écran screenshots' + }, + } + ; } -export const tagSeparator = ' ' -export const tagSectionSeparator = '--' -export const enableTestsLocally = false -export const reportStatistics = false \ No newline at end of file + +const rangement_instance = new config_rangement(); + +export const tagSeparator = rangement_instance.tagSeparator +export const tagSectionSeparator = rangement_instance.tagSectionSeparator +export const enableTestsLocally = rangement_instance.enableTestsLocally +export const reportStatistics = rangement_instance.reportStatistics + + +export default rangement_instance + diff --git a/finder.mjs b/finder.mjs index 5ed233a..60e0f49 100644 --- a/finder.mjs +++ b/finder.mjs @@ -1,11 +1,12 @@ /** * la classe qui repère des patterns */ -import { tagSectionSeparator, tagSeparator } from './configs.mjs' +import rangement_instance from './configs.mjs' import exifr from 'exifr' import moment from 'moment' -import log from 'log_level' +import log from 'loglevel' +log.setLevel(rangement_instance.log_level) /** * finds patterns for file name @@ -17,7 +18,7 @@ export default class finder { } static reportStatistics () { - console.log('statistics', + log.info('statistics', this.statistics) } @@ -27,7 +28,7 @@ export default class finder { static findFormattedDate (filepath) { let match = filepath.match(/\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}/ig) - log.debug('match findFormattedDate', match) + log.debug(' finder - match findFormattedDate', match) let result = '' if (match && match[0]) { result = match[0] @@ -36,11 +37,8 @@ export default class finder { } static findFileExtension (inputString) { - if(!inputString){ - return ''; - } let result = inputString.match(/\.\w{3,4}$/i) - return result.shift() + return result } /** @@ -50,10 +48,10 @@ export default class finder { */ static findFileNameFreeTextPart (fileName) { fileName = fileName.replace(this.findFileExtension(fileName), '') - let boom = fileName.split(tagSectionSeparator) + let boom = fileName.split(rangement_instance.tagSectionSeparator) if (boom.length) { let freeTextPart = boom[0].trim() - console.log('freeTextPart', freeTextPart) + log.debug(' finder - freeTextPart', freeTextPart) return freeTextPart } return fileName.trim() @@ -72,24 +70,24 @@ export default class finder { if (extensionFile) { extensionFile = extensionFile[0] } else { - console.log('no extensionFile', extensionFile, inputString) + log.debug(' finder - no extensionFile', extensionFile, inputString) extensionFile = '' } inputString = inputString.replace(extensionFile, '') - log.debug('extensionFile', extensionFile) - if (inputString.includes(tagSectionSeparator)) { - log.debug('inputString', inputString) + log.debug(' finder - extensionFile', extensionFile) + if (inputString.includes(rangement_instance.tagSectionSeparator)) { + log.debug(' finder - inputString', inputString) if (inputString.length) { - let boom = inputString.split(tagSectionSeparator) - log.debug('boom', boom) + let boom = inputString.split(rangement_instance.tagSectionSeparator) + log.debug(' finder - boom', boom) if (boom.length) { - let fileSectionsName = boom.splice(tagSeparator) - listOfTags = [...fileSectionsName[1].trim().split(tagSeparator)] - log.debug('listOfTags', listOfTags) + let fileSectionsName = boom.splice(rangement_instance.tagSeparator) + listOfTags = [...fileSectionsName[1].trim().split(rangement_instance.tagSeparator)] + log.debug(' finder - listOfTags', listOfTags) } else { - console.log('no boom', boom) + log.debug(' finder - no boom', boom) } } } @@ -110,15 +108,15 @@ export default class finder { static searchAndRenameScreenshots (fileName) { if (finder.findScreenshot(fileName)) { let tags = this.findTagSectionInString(fileName) - console.log('tags', tags) + log.debug(' finder - tags', tags) if (!tags.includes('screenshot')) { fileName = this.addTagInFileName('screenshot', fileName) fileName = this.searchAndReplaceInFileName('Screenshot', '', fileName) - console.log('screenShotMockFileName:', fileName) + log.debug(' finder - screenShotMockFileName:', fileName) return this.cleanSpaces(fileName) } - console.log('is a screenshot, remove screenshot in name, and add tag screenshot') + log.debug(' finder - is a screenshot, remove screenshot in name, and add tag screenshot') } else { return null } @@ -132,7 +130,7 @@ export default class finder { tags.push(tagName) let uniqueArray = [...new Set(tags)] - let newFileName = firstPart + ' ' + tagSectionSeparator + ' ' + tags.join(tagSeparator) + let newFileName = firstPart + ' ' + rangement_instance.tagSectionSeparator + ' ' + tags.join(rangement_instance.tagSeparator) newFileName = newFileName.replace(/ {*}/, '') + this.findFileExtension(fileName) return this.cleanSpaces(newFileName) } @@ -143,7 +141,7 @@ export default class finder { * @returns {{extension: *, dateStamp: string, freeText: (*|string), tags: *[]}} */ static destructurateFileName (fullPath) { - let [folderPath, fileNameOriginal] = this.findFolderPath(fullPath) + let [folderPath, fileNameOriginal] = this.findFolderPath(fullPath) let dateStampInFileNameOriginal = this.findFormattedDate(fileNameOriginal) return { fullPath, @@ -168,17 +166,17 @@ export default class finder { let moments = [] - log.debug('exif data : ', exifData) // Do something with your data! + log.debug(' finder - exif data : ', exifData) // Do something with your data! if (exifData.DateTimeOriginal) { - log.debug('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data! + log.debug(' finder - image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data! moments.push(exifData.DateTimeOriginal) } if (exifData.ModificationDateTime) { - log.debug('image créée le : ModificationDateTime : ', exifData.ModificationDateTime) // Do something with your data! + log.debug(' finder - image créée le : ModificationDateTime : ', exifData.ModificationDateTime) // Do something with your data! moments.push(exifData.ModificationDateTime) } if (exifData.ModifyDate) { - log.debug('image créée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data! + log.debug(' finder - image créée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data! moments.push(exifData.ModifyDate) } if (exifData.FileAccessDateTime) { @@ -188,11 +186,11 @@ export default class finder { moments.push(exifData.FileInodeChangeDateTime) } if (exifData.FileModificationDateTime) { - log.debug('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data! + log.debug(' finder - image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data! moments.push(exifData.FileModificationDateTime) } if (exifData.CreateDate) { - log.debug('image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data! + log.debug(' finder - image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data! moments.push(exifData.CreateDate) } @@ -202,27 +200,31 @@ export default class finder { }) let minDate = moment.min(moments) - log.debug('minDate :::::::::', minDate) - console.log('minDate :::::::::', minDate.format('yyyy-MM-DDTHH:mm:ss')) + log.debug(' finder - minDate :::::::::', minDate) + log.info(' finder - minDate :::::::::', minDate.format(rangement_instance.iso_date_format)) - return minDate.format('yyyy-MM-DDTHH:mm:ss') + return minDate.format(rangement_instance.iso_date_format) } else { - console.log('pas de exif data') + log.debug(' finder - pas de exif data') return '' } } + static findTemplateInFileName (fileName) { + // test all templates from configuration + } + /** * examine plusieurs propriétés exif de date et retourne la plus ancienne * @param filepath */ static async findExifCreationDate (filepath) { - console.log('filepath', filepath) + log.debug(' finder - filepath', filepath) let dateAlreadyInFileName = finder.findFormattedDate(filepath) if (dateAlreadyInFileName) { - console.log('------ dateAlreadyInFileName', dateAlreadyInFileName) + log.debug(' finder - ------ dateAlreadyInFileName', dateAlreadyInFileName) } return await exifr.parse(filepath) @@ -234,9 +236,9 @@ export default class finder { let fileName = folders.pop() folders = filePath.replace(fileName, '') - console.log('\n - folders', folders) - console.log(' - fileName', fileName, '\n') - return [folders, fileName] + log.debug(' finder - \n - folders', folders) + log.debug(' finder - - fileName', fileName, '\n') + return [folders, fileName] } } \ No newline at end of file diff --git a/index.mjs b/index.mjs index 4175b49..6546801 100644 --- a/index.mjs +++ b/index.mjs @@ -2,138 +2,238 @@ * @name tykayn Rangement * @description Rangement sorts and rename files depending on their exif data * @contact contact@cipherbliss.com - --------------------- */ + --------------------- */ /** --------------------- - libs - --------------------- */ + libs + --------------------- */ import fs from 'node-fs' import minimist from 'minimist' +import log from 'loglevel'; +import path from "node:path"; /** --------------------- - custom utilities and configuration + custom utilities and configuration --------------------- */ -import { enableTestsLocally, reportStatistics, tagSectionSeparator, tagSeparator } from './configs.mjs' +import rangement_instance from './configs.mjs' import { - TestFindFormattedDate, - TestScreenShotIsFoundAndRenamed, - TestTagsAreDetectedInFileName + TestFindFormattedDate, + TestScreenShotIsFoundAndRenamed, + TestTagsAreDetectedInFileName } from './testFunctions.mjs' import finder from './finder.mjs' -let mini_arguments -console.log(' ') +import exiftool from "node-exiftool"; -function parseArguments () { - mini_arguments = minimist(process.argv.slice(2)) - console.log('arguments', mini_arguments) +let mini_arguments + +log.setLevel(rangement_instance.log_level) +log.info(' ') + +function parseArguments() { + mini_arguments = minimist(process.argv.slice(2)) + log.debug('arguments', mini_arguments) +} + +function addOriginalFileNameIfMissing(originalFileName, fileMixedNewName) { + + // const ep = new exiftool.ExiftoolProcess() + // + // ep + // .open(fileMixedNewName) + // .then(() => ep.writeMetadata(fileMixedNewName, { + // 'OriginalFileName+': originalFileName, + // })) + // .then(console.log, console.error) + // .then(() => ep.close()) + // .catch(console.error) +} + +function renameFile(originalFileName, fileMixedNewName) { + fs.rename(originalFileName, fileMixedNewName, function (err) { + log.info('name changed', fileMixedNewName) + if (err) { + log.info('rename ERROR: ' + err) + } else { + // otherRenames.push(originalFileName) + otherRenames.push(fileMixedNewName) + + addOriginalFileNameIfMissing(originalFileName, fileMixedNewName) + // rangement_instance.statistics['filesModified']++ + } + }) +} + +function appendFileName(fileProperties, newText) { + fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText) + return fileProperties +} + +function prependFileName(fileProperties, newText) { + fileProperties.freeText = finder.cleanSpaces(newText + ' ' + fileProperties.freeText) + return fileProperties +} + +function makeFileNameFromProperties(fileProperties) { + + let tagPlace = '' + log.info('fileProperties.tags',fileProperties.tags) + if (fileProperties.tags.length && rangement_instance.keepTags) { + tagPlace = ' ' + rangement_instance.tagSectionSeparator + ' '+ fileProperties.tags.join(rangement_instance.tagSeparator) + } + console.log('fileProperties.dateStampExif', fileProperties.dateStampExif) + let newName = '' + + fileProperties.dateStampExif + + ' ' + + (rangement_instance.keepFreeText? fileProperties.freeText : '') + + tagPlace + + fileProperties.extension; + + if(rangement_instance.replaceUnderscoreWithSpaces){ + newName = newName.replace('_', ' ') + } + + newName = newName.replace(' ', '') + + return newName +} + +let otherRenames = []; + +function shouldWeChangeName(structureForFile) { + log.info(' ______ shouldWeChangeName ', structureForFile.fileNameOriginal) + let newName = makeFileNameFromProperties(structureForFile) + log.debug('newName', newName) + if (structureForFile.fileNameOriginal !== newName && !otherRenames.includes(newName)) { + + log.info('\n ancien nom :', structureForFile.fileNameOriginal) + + log.info(' nouveau nom:', newName) + if (!mini_arguments['dry-run']) { + renameFile(structureForFile.fullPath, structureForFile.folderPath + newName) + } else { + log.info('no renaming for real, this is a dry run') + } + } else { + log.info(' rien à changer') + } +} + +/** + * guess file name on one file which is not a directory + * @param fullPath + */ +function guessFileNameOnOnefile(fullPath) { + + log.info('go guess file name on file: ', fullPath ) + fs.stat(fullPath, (err, stats) => { + + if (err) { + log.error('échec fichier', err) + log.error('ce fichier n existe pas: ', fullPath) + return; + } else { + + let structureForFile = finder.destructurateFileName(fullPath) + + // examiner les infos exif de chaque fichier pour proposer un nouveau nom + if (!structureForFile.dateStampInFileNameOriginal) { + log.info(' le nom de fichier "'+structureForFile.freeText +'" ne contient pas de date formatée au début') + + finder.findExifCreationDate(structureForFile.fullPath) + .then(data => { + log.info(' ... chercher la date de création : "'+structureForFile.freeText +'"') + let foundDate = finder.findEarliestDateInExifData(data) + + log.info(' =>>>>>>> foundDate : ', foundDate) + if (foundDate) { + structureForFile.dateStampExif = foundDate + } else { + log.info('pas de date trouvée dans le nom') + } + shouldWeChangeName(structureForFile) + } + , + (error) => { + log.warn('/////////// Error in reading exif of file: ' + error.message) + return '' + }) + } + + } + }) +} + +let expandedFileList = [] +let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd()); +console.log('cwd', cwd) + +function guessFileNameOnAllFilesFromArguments() { + + + // parcourir les fichiers + log.debug('liste des fichiers', mini_arguments._) + let fileList = mini_arguments._ + + + // test file exists + fileList.forEach(fullPath => { + // parcourir les dossiers + isFolderOrFile(`${fullPath}`) + } + ) + + log.info('expanded file list :', expandedFileList) + expandedFileList.forEach(filePath => guessFileNameOnOnefile(filePath)) + +} + +function readSubdirectories(baseDir) { + const newGlob = baseDir; + fs.readdir(baseDir, (err, files) => { + if (err) throw err; + + console.log('readSubdirectories - files', files) + files.forEach((subDirOrFile) => { + const newFullPath = cwd +'/'+ subDirOrFile; + + if (fs.existsSync(newFullPath)) { + const s = fs.statSync(newFullPath); + + if (s.isFile()) { + expandedFileList.push(cwd+'/'+subDirOrFile) + } + } + }); + }); +} + +function isFolderOrFile(fileName) { + // const stat = fs.statSync(cwd + '/' + fileName); + const stat = fs.statSync( fileName); + + if (stat.isDirectory()) { + let fileList = readSubdirectories(fileName); + console.log('fileList in directory ',fileName, '\n', fileList) + if (fileList) { + expandedFileList.push(...fileList) + } + } + else if (stat.isFile()) { + expandedFileList.push(cwd + '/' + fileName) + } } parseArguments() -function renameFile (originalFileName, fileMixedNewName) { - fs.rename(originalFileName, fileMixedNewName, function (err) { - console.log('name changed', fileMixedNewName) - if (err) console.log('rename ERROR: ' + err) - }) -} - -function appendFileName (fileProperties, newText) { - fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText) - return fileProperties -} - -function prependFileName (fileProperties, newText) { - fileProperties.freeText = finder.cleanSpaces(newText + ' ' + fileProperties.freeText) - return fileProperties -} - -function makeFileNameFromProperties (fileProperties) { - - let tagPlace = '' - if (fileProperties.tags.length) { - tagPlace = ' ' + tagSectionSeparator + ' ' - } - // return finder.cleanSpaces(fileProperties.dateStamp + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension).replace(+' ' + tagSectionSeparator + ' ' + '.', '.') - return '' + fileProperties.dateStampExif + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension -} - -function shouldWeChangeName (structureForFile) { - console.log(' ______ allez hop fini la recherche on fait un nouveau nom') - console.log('structureForFile', structureForFile) - let newName = makeFileNameFromProperties(structureForFile) - if (structureForFile.fileNameOriginal !== newName) { - - console.log('\n ancien nom :', structureForFile.fileNameOriginal) - // console.log(' nouveau nom:', foundDate +structureForFile.freeText + structureForFile.tags.join(tagSeparator) + structureForFile.extension ) - console.log(' nouveau nom:', newName) - if (!mini_arguments.dryRun) { - renameFile(structureForFile.fullPath, structureForFile.folderPath + newName) - } else { - console.log('no renaming for real, this is a dry run') - } - } else { - console.log(' rien à changer') - } - -} - -async function guessFileNameOnAllFilesFromArguments () { - - // parcourir les dossiers - // parcourir les fichiers - - console.log('liste des fichiers', mini_arguments._) - let fileList = mini_arguments._ - - fileList.forEach(fullPath => { - - let structureForFile = finder.destructurateFileName(fullPath) - - // examiner les infos exif de chaque fichier pour proposer un nouveau nom - if (!structureForFile.dateStampInFileNameOriginal) { - console.log(' le nom de fichier ne contient pas de date formatée au début') - - finder.findExifCreationDate(structureForFile.fullPath) - .then(data => { - console.log(' ... chercher la date de création') - let foundDate = finder.findEarliestDateInExifData(data) - - console.log(' =>>>>>>> foundDate : ', foundDate) - if (foundDate) { - - // finder.findEarliestDateInExifData(fullPath).then(response => { - // console.log(' ... trouvée') - // if (response) { - structureForFile.dateStampExif = foundDate - - shouldWeChangeName(structureForFile) - // } - // }) - - } else { - console.log('pas de date trouvée dans le nom') - } - - } - , - (error) => { - console.log('/////////// Error in reading exif of file: ' + error.message) - return '' - }) - } - } - ) - -} - guessFileNameOnAllFilesFromArguments() -// run tests -if (enableTestsLocally) { - TestTagsAreDetectedInFileName() - TestFindFormattedDate() - TestScreenShotIsFoundAndRenamed() +// run tests +if (rangement_instance.enableTestsLocally) { + + TestTagsAreDetectedInFileName() + TestFindFormattedDate() + TestScreenShotIsFoundAndRenamed() } -if (reportStatistics || mini_arguments.stats) { - finder.reportStatistics() +if (rangement_instance.reportStatistics || mini_arguments.stats) { + finder.reportStatistics() } diff --git a/testFiles/un_document.pdf b/locales/en/en.json similarity index 100% rename from testFiles/un_document.pdf rename to locales/en/en.json diff --git a/testFiles/une_photo.jpg b/locales/fr/fr.json similarity index 100% rename from testFiles/une_photo.jpg rename to locales/fr/fr.json diff --git a/main.test.js b/main.test.js index 5205ae5..d930614 100644 --- a/main.test.js +++ b/main.test.js @@ -1,4 +1,5 @@ -import finder from "./finder.mjs"; +// import finder from "./finders.mjs"; +const finders = require('./finders.mjs') describe('rangement file name', () => { @@ -6,6 +7,16 @@ describe('rangement file name', () => { expect(finder.findFormattedDate('2023-06-23T18.36.47 -- machin bidule.jpg')).toBe('2023-06-23T18.36.47'); }); test('detects file extension in file name', () => { - expect(finder.findFileExtension('2023-06-23T18.36.47 -- machin bidule.jpg')).toBe('.jpg'); + expect(finder.findFileExtension()('2023-06-23T18.36.47 -- machin bidule.jpg')).toBe('jpg'); }); -}) \ No newline at end of file +}) +console.log('finders', finder) + +test('adding positive numbers is not zero', () => { + for (let a = 1; a < 10; a++) { + for (let b = 1; b < 10; b++) { + expect(a + b).not.toBe(0); + } + } +}); + diff --git a/package-lock.json b/package-lock.json index f011e8c..f17b9f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,10 @@ "license": "AGPL-3.0-or-later", "dependencies": { "exifr": "^7.1.3", + "i18next": "^23.2.6", "minimist": "^1.2.8", "moment": "^2.29.4", + "node-exiftool": "^2.3.0", "node-fs": "^0.1.7" }, "devDependencies": { @@ -21,6 +23,7 @@ "@jest/globals": "^29.5.0", "babel-jest": "^29.5.0", "jest": "^29.5.0", + "loglevel": "^1.8.1", "nodemon": "^2.0.22", "ts-node": "^10.9.1" } @@ -1798,7 +1801,6 @@ "version": "7.22.5", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.22.5.tgz", "integrity": "sha512-ecjvYlnAaZ/KVneE/OdKYBYfgXV3Ptu6zQWmgEF7vwKhQnvVS6bjMD2XYgj+SNvQ1GfK/pjgokfPkC/2CO8CuA==", - "dev": true, "dependencies": { "regenerator-runtime": "^0.13.11" }, @@ -2741,6 +2743,11 @@ } ] }, + "node_modules/catchment": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/catchment/-/catchment-1.0.0.tgz", + "integrity": "sha512-6sTXWtTXI+MTHrHVnvZnOM8q2ujbQ+qJF0Mu8NM3jifMBCiZssjol/nBHQqOEiKSZKf1e4+wCrgmTXzWzvZs5w==" + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -3280,6 +3287,28 @@ "node": ">=10.17.0" } }, + "node_modules/i18next": { + "version": "23.2.6", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-23.2.6.tgz", + "integrity": "sha512-i0P2XBisewaICJ7UQtwymeJj6cXUigM+s8XNIXmWk4oJ8iTok2taCbOTX0ps+u9DFcQ6FWH6xLIU0dLEnMaNbA==", + "funding": [ + { + "type": "individual", + "url": "https://locize.com" + }, + { + "type": "individual", + "url": "https://locize.com/i18next.html" + }, + { + "type": "individual", + "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project" + } + ], + "dependencies": { + "@babel/runtime": "^7.22.5" + } + }, "node_modules/ignore-by-default": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", @@ -4174,6 +4203,19 @@ "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==", "dev": true }, + "node_modules/loglevel": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.8.1.tgz", + "integrity": "sha512-tCRIJM51SHjAayKwC+QAg8hT8vg6z7GSgLJKGvzuPb1Wc+hLzqtuVLxp6/HzSPOozuK+8ErAhy7U/sVzw8Dgfg==", + "dev": true, + "engines": { + "node": ">= 0.6.0" + }, + "funding": { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/loglevel" + } + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -4213,6 +4255,11 @@ "tmpl": "1.0.5" } }, + "node_modules/makepromise": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/makepromise/-/makepromise-1.0.0.tgz", + "integrity": "sha512-M1q31Q56rlA+gwvmfWj7QFDMIJOuj527fQx/rN3dlzUtsopC9ZjtyekIBW4Fw0HZP6O6Azuw3/Vtk5O59bXz7A==" + }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -4281,6 +4328,24 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, + "node_modules/node-exiftool": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/node-exiftool/-/node-exiftool-2.3.0.tgz", + "integrity": "sha512-UZd+k07thqXqp/1udsZghAFrjrsYfP8Kg48I9uv02FZAmT1Wasr8aAPMCObnYkJiWoD/V8UrGjiSzgfNQy9zBw==", + "dependencies": { + "is-stream": "1.1.0", + "restream": "1.2.0", + "wrote": "0.6.1" + } + }, + "node_modules/node-exiftool/node_modules/is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/node-fs": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/node-fs/-/node-fs-0.1.7.tgz", @@ -4677,8 +4742,7 @@ "node_modules/regenerator-runtime": { "version": "0.13.11", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", - "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", - "dev": true + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" }, "node_modules/regenerator-transform": { "version": "0.15.1", @@ -4783,6 +4847,11 @@ "node": ">=10" } }, + "node_modules/restream": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/restream/-/restream-1.2.0.tgz", + "integrity": "sha512-RpnOjVCRrc/jO6j1U+E0X9mPjMUUitjEms/IaR18wb8AdPHg46UBmB2aEA6JKgpGbhOcHsDLyurmeZhd4kQXgg==" + }, "node_modules/semver": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", @@ -5278,6 +5347,15 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/wrote": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/wrote/-/wrote-0.6.1.tgz", + "integrity": "sha512-5vDwEuRou4yCOzR08bUdY+n/HuOA21L7A4tVsm/kEu2R2APN8tYWvxQbM1hFJk49lR7x47KZMtCu2k8S9WISUA==", + "dependencies": { + "catchment": "1.0.0", + "makepromise": "1.0.0" + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index 7f5a860..b831358 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,10 @@ "license": "AGPL-3.0-or-later", "dependencies": { "exifr": "^7.1.3", + "i18next": "^23.2.6", "minimist": "^1.2.8", "moment": "^2.29.4", + "node-exiftool": "^2.3.0", "node-fs": "^0.1.7" }, "devDependencies": { @@ -36,6 +38,7 @@ "@jest/globals": "^29.5.0", "babel-jest": "^29.5.0", "jest": "^29.5.0", + "loglevel": "^1.8.1", "nodemon": "^2.0.22", "ts-node": "^10.9.1" } diff --git a/setup.mjs b/setup.mjs new file mode 100644 index 0000000..f01eac3 --- /dev/null +++ b/setup.mjs @@ -0,0 +1,37 @@ +/** + création de la config + */ +// import i18next from 'i18next' +import config_rangement from "./configs"; + +const { stdin, stdout } = process; + +function prompt(question) { + return new Promise((resolve, reject) => { + stdin.resume(); + stdout.write(question); + + stdin.on('data', data => resolve(data.toString().trim())); + stdin.on('error', err => reject(err)); + }); +} + + +async function main() { + try { + // const name = await prompt(i18next.t("home.title")) + const name = await prompt(`squoi le dossier de base des archives? [${config_rangement.base_archive_folder}]`) + // const age = await prompt("What's your age? "); + // const email = await prompt("What's your email address? "); + // const user = { name, age, email }; + console.log(name); + stdin.pause(); + } catch(error) { + console.log("There's an error!"); + console.log(error); + } + process.exit(); +} + +main(); + diff --git a/testFiles/2020-06-21T14:27:19 2sqdf45s5g456ghdf.jpg b/testFiles/image.jpg similarity index 100% rename from testFiles/2020-06-21T14:27:19 2sqdf45s5g456ghdf.jpg rename to testFiles/image.jpg diff --git a/testFiles/meme/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg b/testFiles/meme/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg new file mode 100644 index 0000000..b150550 Binary files /dev/null and b/testFiles/meme/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg differ diff --git a/testFiles/meme/eueueu -- meme.jpg b/testFiles/meme/eueueu -- meme.jpg new file mode 100644 index 0000000..ed40ffb Binary files /dev/null and b/testFiles/meme/eueueu -- meme.jpg differ diff --git a/testFiles/meme_base/2023-06-14T13.29.22 FyB8cZnWIAc21rw -- meme.jpg b/testFiles/meme_base/2023-06-14T13.29.22 FyB8cZnWIAc21rw -- meme.jpg new file mode 100644 index 0000000..ed40ffb Binary files /dev/null and b/testFiles/meme_base/2023-06-14T13.29.22 FyB8cZnWIAc21rw -- meme.jpg differ diff --git a/testFiles/meme_base/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg b/testFiles/meme_base/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg new file mode 100644 index 0000000..b150550 Binary files /dev/null and b/testFiles/meme_base/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg differ diff --git a/testFiles/une_photo_pas_pareil.jpg b/testFiles/une_photo_pas_pareil.jpg deleted file mode 100644 index e69de29..0000000 diff --git a/testFiles/une_photo_pas_pareil.png b/testFiles/une_photo_pas_pareil.png deleted file mode 100644 index e69de29..0000000