From cbc808e6254d2e4a7b134e723d3fce701da6dd6d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 29 May 2024 18:25:02 -0300 Subject: thumbs, upd8: adapt media cache path to always-present wiki cache --- src/gen-thumbs.js | 79 +++++++++++++++++++++++-------------------------------- src/upd8.js | 12 ++++----- 2 files changed, 38 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/gen-thumbs.js b/src/gen-thumbs.js index c5c5ee4f..1c34994f 100644 --- a/src/gen-thumbs.js +++ b/src/gen-thumbs.js @@ -630,6 +630,13 @@ export async function determineMediaCachePath({ }; } + if (!wikiCachePath) { + return { + annotation: 'wiki cache path not provided', + mediaCachePath: null, + }; + } + let mediaIncludesThumbnailCache; try { @@ -648,24 +655,33 @@ export async function determineMediaCachePath({ // Two inferred paths are possible - "adjacent" and "contained". // "Contained" is the preferred format and we'll create it if - // wikiCachePath is provided, but if it *isn't* we won't know - // where to create it. Since "adjacent" isn't preferred we don't - // ever generate it, and we'd prefer not to *newly* generate - // thumbs in-place with mediaPath, so give up - we've already - // determined mediaPath doesn't include in-place thumbs. - - const adjacentInferredPath = - path.join( - path.dirname(mediaPath), - path.basename(mediaPath) + '-cache'); + // neither of the inferred paths exists. (Of course, by this + // point we've already determined that the media path itself + // isn't doubling as the thumbnail cache.) const containedInferredPath = (wikiCachePath ? path.join(wikiCachePath, 'media-cache') : null); - let adjacentIncludesThumbnailCache; + const adjacentInferredPath = + path.join( + path.dirname(mediaPath), + path.basename(mediaPath) + '-cache'); + let containedIncludesThumbnailCache; + let adjacentIncludesThumbnailCache; + + try { + const files = await readdir(containedInferredPath); + containedIncludesThumbnailCache = files.includes(CACHE_FILE); + } catch (error) { + if (error.code === 'ENOENT') { + containedIncludesThumbnailCache = null; + } else { + containedIncludesThumbnailCache = undefined; + } + } try { const files = await readdir(adjacentInferredPath); @@ -678,19 +694,6 @@ export async function determineMediaCachePath({ } } - if (wikiCachePath) { - try { - const files = await readdir(containedInferredPath); - containedIncludesThumbnailCache = files.includes(CACHE_FILE); - } catch (error) { - if (error.code === 'ENOENT') { - containedIncludesThumbnailCache = null; - } else { - containedIncludesThumbnailCache = undefined; - } - } - } - // Go ahead with the contained path if it exists and contains a cache - // no other conditions matter. if (containedIncludesThumbnailCache === true) { @@ -712,7 +715,7 @@ export async function determineMediaCachePath({ // Throw a very high-priority tantrum if the contained cache exists but // isn't readable. It's the preferred cache and we can't tell if it's // available for use or not! - if (wikiCachePath && containedIncludesThumbnailCache === undefined) { + if (containedIncludesThumbnailCache === undefined) { return { annotation: `contained path not readable`, mediaCachePath: null, @@ -764,28 +767,12 @@ export async function determineMediaCachePath({ } } - // If wikiCachePath was provided and the contained cache just doesn't - // exist yet, we'll create it during this run. - if (wikiCachePath && containedIncludesThumbnailCache === null) { - return { - annotation: `contained path will be created`, - mediaCachePath: containedInferredPath, - }; - } - - // If the adjacent cache doesn't exist, too dang bad! - // We aren't interested in newly creating it, so - // don't count it as an option. - - // Similarly, we've already established mediaPath isn't - // currently doubling as the thumbnail cache, and we won't - // newly start generating thumbnails here either. - - // All options aside struck out, there's no way to continue. - + // If we haven't found any information about either inferred + // location (and so have fallen back to this base case), we'll + // create the contained cache during this run. return { - annotation: `missing wiki cache to create media cache inside`, - mediaCachePath: null, + annotation: `contained path will be created`, + mediaCachePath: containedInferredPath, }; } diff --git a/src/upd8.js b/src/upd8.js index 11ebbd72..c18a0c54 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -890,17 +890,15 @@ async function main() { logError`a new path with ${'--media-cache-path'} or ${'HSMUSIC_MEDIA_CACHE'}.`; break; - case `missing wiki cache to create media cache inside`: + case `media path not provided`: /* unreachable */ console.error(''); - logError`It looks like you're starting totally fresh, so please`; - logError`create a ${'cache'} folder and provide it with ${'--cache-path'}`; - logError`or ${'HSMUSIC_CACHE'}. The media cache will automatically be`; - logError`generated inside of this folder!`; + logError`It seems a ${'--media-path'} (or ${'HSMUSIC_MEDIA'}) wasn't provided.`; + logError`Make sure one of these is actually pointing to a path that exists.`; break; - case `media path not provided`: /* unreachable */ + case `cache path not provided`: /* unreachable */ console.error(''); - logError`It seems a ${'--media-path'} (or ${'HSMUSIC_MEDIA'}) wasn't provided.`; + logError`It seems a ${'--cache-path'} (or ${'HSMUSIC_CACHE'}) wasn't provided.`; logError`Make sure one of these is actually pointing to a path that exists.`; break; } -- cgit 1.3.0-6-gf8a5