« get me outta code hell

upd8: integrate --migrate-thumbs option - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-10-29 15:27:11 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-10-29 15:43:29 -0300
commit1a92f5e8198e5d1a56d0d9f7272f731f4e98bfce (patch)
tree1f96c760946a4a362b6fffb95fdd821270b016f6
parent8b081bd9a470e108688f755f7ee6e8acf95979c0 (diff)
upd8: integrate --migrate-thumbs option
-rwxr-xr-xsrc/upd8.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/upd8.js b/src/upd8.js
index 0c52dc0..a504275 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -64,6 +64,7 @@ import genThumbs, {
   defaultMagickThreads,
   determineMediaCachePath,
   isThumb,
+  migrateThumbsIntoDedicatedCacheDirectory,
   verifyImagePaths,
 } from '#thumbs';
 
@@ -116,6 +117,9 @@ async function main() {
     loadThumbnailCache:
       {...defaultStepStatus, name: `load thumbnail cache file`},
 
+    migrateThumbnails:
+      {...defaultStepStatus, name: `migrate thumbnails`},
+
     generateThumbnails:
       {...defaultStepStatus, name: `generate thumbnails`},
 
@@ -260,6 +264,11 @@ async function main() {
       type: 'flag',
     },
 
+    'migrate-thumbs': {
+      help: `Transfer automatically generated thumbnail files out of an existing media directory and into the easier-to-manage media-cache directory`,
+      type: 'flag',
+    },
+
     // Just working on data entries and not interested in actually
     // generating site HTML yet? This flag will cut execution off right
     // 8efore any site 8uilding actually happens.
@@ -429,6 +438,7 @@ async function main() {
   const mediaPath = cliOptions['media-path'] || process.env.HSMUSIC_MEDIA;
   const langPath = cliOptions['lang-path'] || process.env.HSMUSIC_LANG; // Can 8e left unset!
 
+  const migrateThumbs = cliOptions['migrate-thumbs'] ?? false;
   const skipThumbs = cliOptions['skip-thumbs'] ?? false;
   const thumbsOnly = cliOptions['thumbs-only'] ?? false;
   const noBuild = cliOptions['no-build'] ?? false;
@@ -505,6 +515,35 @@ async function main() {
 
   logInfo`Using media cache at: ${mediaCachePath} (${mediaCachePathAnnotation})`;
 
+  if (migrateThumbs) {
+    stepStatusSummary.migrateThumbnails.status = STATUS_STARTED_NOT_DONE;
+
+    const result = await migrateThumbsIntoDedicatedCacheDirectory({
+      mediaPath,
+      mediaCachePath,
+      queueSize,
+    });
+
+    if (result.succses) {
+      Object.assign(stepStatusSummary.migrateThumbnails, {
+        status: STATUS_FATAL_ERROR,
+        annotation: `view log for details`,
+      });
+      return false;
+    }
+
+    stepStatusSummary.migrateThumbnails.status = STATUS_DONE_CLEAN;
+
+    logInfo`Good to go! Run hsmusic again without ${'--migrate-thumbs'} to start`;
+    logInfo`using the migrated media cache.`;
+    return true;
+  } else {
+    Object.assign(stepStatusSummary.migrateThumbnails, {
+      status: STATUS_NOT_APPLICABLE,
+      annotation: `--migrate-thumbs not provided`,
+    });
+  }
+
   const niceShowAggregate = (error, ...opts) => {
     showAggregate(error, {
       showTraces: showAggregateTraces,