Skip to content

Commit c93467b

Browse files
authored
fix(snapcraft): use the correct config folder for image cache (#3302)
1 parent d954328 commit c93467b

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

server/lib/imageproxy.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ type ImageResponse = {
1818
imageBuffer: Buffer;
1919
};
2020

21+
const baseCacheDirectory = process.env.CONFIG_DIRECTORY
22+
? `${process.env.CONFIG_DIRECTORY}/cache/images`
23+
: path.join(__dirname, '../../config/cache/images');
24+
2125
class ImageProxy {
2226
public static async clearCache(key: string) {
2327
let deletedImages = 0;
24-
const cacheDirectory = path.join(
25-
__dirname,
26-
'../../config/cache/images/',
27-
key
28-
);
28+
const cacheDirectory = path.join(baseCacheDirectory, key);
2929

3030
const files = await promises.readdir(cacheDirectory);
3131

@@ -57,11 +57,7 @@ class ImageProxy {
5757
public static async getImageStats(
5858
key: string
5959
): Promise<{ size: number; imageCount: number }> {
60-
const cacheDirectory = path.join(
61-
__dirname,
62-
'../../config/cache/images/',
63-
key
64-
);
60+
const cacheDirectory = path.join(baseCacheDirectory, key);
6561

6662
const imageTotalSize = await ImageProxy.getDirectorySize(cacheDirectory);
6763
const imageCount = await ImageProxy.getImageCount(cacheDirectory);
@@ -263,7 +259,7 @@ class ImageProxy {
263259
}
264260

265261
private getCacheDirectory() {
266-
return path.join(__dirname, '../../config/cache/images/', this.key);
262+
return path.join(baseCacheDirectory, this.key);
267263
}
268264
}
269265

0 commit comments

Comments
 (0)