From e41eaa096661e86a68b4282de2424125634dc419 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 19 Jul 2023 10:04:08 +0200 Subject: [PATCH] split config files --- README.md | 3 +++ conf/configs.js | 40 +++++++++++++++++++++++++++++ conf/folders.js | 22 ++++++++++++++++ conf/mainTemplates.mjs | 46 ++++++++++++++++++++++++++++++++++ configs.mjs | 57 ------------------------------------------ create_folders.mjs | 4 +-- finder.mjs | 2 +- index.mjs | 2 +- package.json | 1 + setup.mjs | 5 ++-- 10 files changed, 119 insertions(+), 63 deletions(-) create mode 100644 conf/configs.js create mode 100644 conf/folders.js create mode 100644 conf/mainTemplates.mjs delete mode 100644 configs.mjs diff --git a/README.md b/README.md index 180047f..e547dff 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ Ce script s'utilise selon la méthode de rangement détaillée ici: https://www.cipherbliss.com/organiser-ses-fichiers-avec-des-tags-avec-filetags mais ce n'est pas encore prêt à être utilisé en production. +# mise en place + +utiliser le setup pour mettre en place l'architecture de dossiers de rangement. Différentes questions vont vous être posées afin de personnaliser les dossiers et vérifier l'intégrité. # lancement de renommage `devine mon_fichier.jpg mon_autre_fichier.pdf` diff --git a/conf/configs.js b/conf/configs.js new file mode 100644 index 0000000..aed2b6e --- /dev/null +++ b/conf/configs.js @@ -0,0 +1,40 @@ +import mainTemplates from './mainTemplates.mjs' +import constants from './folders.js' + +/** + * configuration générale à importer dans les utilitaires + */ +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 + constants = constants + base_archive_folder = constants.base_archive_folder + templates = mainTemplates; + + /** + * override config if we want + * @param overridingConfig + */ + constructor (overridingConfig) { + console.log('overridingConfig', overridingConfig) + let keys = Object.keys(overridingConfig) + let self = this; + keys.forEach(elem=>{ + if(self[key]){ + self[key] = elem + } + }) + } +} + +const rangement_instance = new config_rangement({}); +export default rangement_instance \ No newline at end of file diff --git a/conf/folders.js b/conf/folders.js new file mode 100644 index 0000000..e8554f6 --- /dev/null +++ b/conf/folders.js @@ -0,0 +1,22 @@ +/** + * constantes de dossier à utiliser pour la mise en place de l'architecture et la config + */ +const base_archive_folder = '/home/poule/encrypted/stockage-syncable/' +const syncronized_folder = '~/Nextcloud/' + +const folders = { + base_archive_folder, + photos_sub_folder: base_archive_folder + 'photos/', + photos_sorting_base_sub_folder: base_archive_folder + 'photos/a_dispatcher/', + bazar_sub_folder: base_archive_folder + 'BAZAR/', + gopro_capture_folder: base_archive_folder + 'photos/gopro/bazar/', + panoramax_captures_folder: base_archive_folder + 'photos/imagerie kartaview carto tel/open camera/', + + syncronized_folder, + workflow_folder_secrets: syncronized_folder + '/ressources/workflow_nextcloud', + workflow_folder_public: syncronized_folder + '/ressources/workflow_nextcloud/public_workflow', + syncronized_phone_inbox: syncronized_folder + 'InstantUpload', + orgmode_folder: syncronized_folder + 'textes/orgmode', +} + +export default folders \ No newline at end of file diff --git a/conf/mainTemplates.mjs b/conf/mainTemplates.mjs new file mode 100644 index 0000000..386be56 --- /dev/null +++ b/conf/mainTemplates.mjs @@ -0,0 +1,46 @@ +import constants from './folders.js' + +export default { + 'downloaded_pic': { + 'example': 'FyB8cZnWIAc21rw.jpg', + 'pattern': /^\-\w{15}\.jpg/, + 'auto_tag':'', + 'auto_sort_folder': constants.bazar_sub_folder + }, + 'telegram_pic': { + 'example': '-4900281569878475578_1109.jpg', + 'pattern': /^\-\d{19}_\d{4}/, + 'auto_tag':'', + 'auto_sort_folder': constants.bazar_sub_folder + }, + 'open_camera_default': { + 'example': 'IMG_20230617_092120_3.jpg', + 'pattern': /^IMG_\d{8}/i, + 'auto_tag':'', + 'auto_sort_folder': constants.panoramax_captures_folder + }, + 'open_camera_custom': { + 'example': 'IMG_OC_20230617_092120_3.jpg', + 'pattern': /^IMG_OC_\d{8}/i, + 'auto_tag':'', + 'auto_sort_folder': constants.panoramax_captures_folder + }, + 'screenshot': { + 'example': 'Screenshot 2023-06-15 at 15-26-04 Instance Panoramax OSM-FR.png', + 'pattern': /^Screenshot/i, + 'auto_tag':'screenshots', + 'auto_sort_folder': 'photos/captures écran screenshots' + }, + 'gopro_front': { + 'example': 'GF010041.jpg', + 'pattern': /^GP?F\d+\.jpg/i, + 'auto_tag':'gopro-front gopro', + 'auto_sort_folder': constants.gopro_capture_folder + }, + 'gopro_back': { + 'example': 'GB010041.jpg', + 'pattern': /^GP?B\d+\.jpg/i, + 'auto_tag':'gopro-back gopro', + 'auto_sort_folder': constants.gopro_capture_folder + }, +} \ No newline at end of file diff --git a/configs.mjs b/configs.mjs deleted file mode 100644 index da79b8f..0000000 --- a/configs.mjs +++ /dev/null @@ -1,57 +0,0 @@ -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' - }, - } - ; -} - -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/create_folders.mjs b/create_folders.mjs index fb86109..2819eae 100644 --- a/create_folders.mjs +++ b/create_folders.mjs @@ -2,8 +2,8 @@ handles creation of global hierarchy of folders from config file */ -import config_rangement from './configs.mjs' -let my_conf = new config_rangement() +import config_rangement from './conf/configs.js' +let my_conf = new config_rangement({}) console.log('config', my_conf.version) diff --git a/finder.mjs b/finder.mjs index ccc4992..506faac 100644 --- a/finder.mjs +++ b/finder.mjs @@ -1,7 +1,7 @@ /** * la classe qui repère des patterns */ -import rangement_instance from './configs.mjs' +import rangement_instance from './conf/configs' import exifr from 'exifr' import moment from 'moment' import log from 'loglevel' diff --git a/index.mjs b/index.mjs index df38529..2535892 100644 --- a/index.mjs +++ b/index.mjs @@ -13,7 +13,7 @@ import path from 'node:path' /** --------------------- custom utilities and configuration --------------------- */ -import rangement_instance from './configs.mjs' +import rangement_instance from './conf/configs.js' import { TestFindFormattedDate, TestScreenShotIsFoundAndRenamed, diff --git a/package.json b/package.json index 1556b9f..7402cd0 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "sorting utilities and file tagging using PIM methodology of Karl Voit", "main": "index.mjs", + "type": "module", "scripts": { "start": "node index.mjs", "devine": "node index.mjs", diff --git a/setup.mjs b/setup.mjs index f01eac3..44f1359 100644 --- a/setup.mjs +++ b/setup.mjs @@ -2,7 +2,7 @@ création de la config */ // import i18next from 'i18next' -import config_rangement from "./configs"; +import config_rangement from "./conf/configs.js"; const { stdin, stdout } = process; @@ -24,7 +24,8 @@ async function main() { // 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); + console.log('le dossier de base des archives est : ',name); + stdin.pause(); } catch(error) { console.log("There's an error!");