diff --git a/server/src/lib/image-resize.js b/server/src/lib/image-resize.js index 4bd7c0f..e6378cc 100644 --- a/server/src/lib/image-resize.js +++ b/server/src/lib/image-resize.js @@ -77,13 +77,14 @@ export async function generateAllSizes(uuid, subdir, originalPath) { await fs.promises.mkdir(cacheDir, { recursive: true }) const sharp = (await import('sharp')).default + const source = sharp(originalPath) for (const width of VALID_WIDTHS) { for (const format of SUPPORTED_FORMATS) { const cacheFileName = `${uuid}_w${width}.${format}` const cachePath = path.join(CACHE_DIR, cacheSubdir, cacheFileName) - const pipeline = sharp(originalPath).resize(width, null, { withoutEnlargement: true }) + const pipeline = source.clone().resize(width, null, { withoutEnlargement: true }) const options = format === 'avif' ? { quality: 75, effort: 4 } : { quality: 80 } await pipeline[format](options).toFile(cachePath) } @@ -97,8 +98,7 @@ export async function generateAllSizes(uuid, subdir, originalPath) { * @returns {string} New URL path like `/uploads/.webp` */ export async function convertOriginalToWebp(uuid, subdir) { - const uploadsDir = path.join(process.cwd(), 'uploads') - const targetDir = subdir ? path.join(uploadsDir, subdir) : uploadsDir + const targetDir = subdir ? path.join(UPLOADS_DIR, subdir) : UPLOADS_DIR const originalPath = await findOriginalFile(uuid, subdir) if (!originalPath) {