From c93467b3acf2c256324297e7e8f21e9944005dd4 Mon Sep 17 00:00:00 2001 From: Ryan Cohen Date: Tue, 31 Jan 2023 01:31:39 +0900 Subject: [PATCH] fix(snapcraft): use the correct config folder for image cache (#3302) --- server/lib/imageproxy.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/server/lib/imageproxy.ts b/server/lib/imageproxy.ts index 4ba6b97a7..38203b7b3 100644 --- a/server/lib/imageproxy.ts +++ b/server/lib/imageproxy.ts @@ -18,14 +18,14 @@ type ImageResponse = { imageBuffer: Buffer; }; +const baseCacheDirectory = process.env.CONFIG_DIRECTORY + ? `${process.env.CONFIG_DIRECTORY}/cache/images` + : path.join(__dirname, '../../config/cache/images'); + class ImageProxy { public static async clearCache(key: string) { let deletedImages = 0; - const cacheDirectory = path.join( - __dirname, - '../../config/cache/images/', - key - ); + const cacheDirectory = path.join(baseCacheDirectory, key); const files = await promises.readdir(cacheDirectory); @@ -57,11 +57,7 @@ class ImageProxy { public static async getImageStats( key: string ): Promise<{ size: number; imageCount: number }> { - const cacheDirectory = path.join( - __dirname, - '../../config/cache/images/', - key - ); + const cacheDirectory = path.join(baseCacheDirectory, key); const imageTotalSize = await ImageProxy.getDirectorySize(cacheDirectory); const imageCount = await ImageProxy.getImageCount(cacheDirectory); @@ -263,7 +259,7 @@ class ImageProxy { } private getCacheDirectory() { - return path.join(__dirname, '../../config/cache/images/', this.key); + return path.join(baseCacheDirectory, this.key); } }