« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/upd8.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/upd8.js b/src/upd8.js
index 0c52dc06..a504275c 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,