|
|
@ -18,14 +18,14 @@ type ImageResponse = {
|
|
|
|
imageBuffer: Buffer;
|
|
|
|
imageBuffer: Buffer;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const baseCacheDirectory = process.env.CONFIG_DIRECTORY
|
|
|
|
|
|
|
|
? `${process.env.CONFIG_DIRECTORY}/cache/images`
|
|
|
|
|
|
|
|
: path.join(__dirname, '../../config/cache/images');
|
|
|
|
|
|
|
|
|
|
|
|
class ImageProxy {
|
|
|
|
class ImageProxy {
|
|
|
|
public static async clearCache(key: string) {
|
|
|
|
public static async clearCache(key: string) {
|
|
|
|
let deletedImages = 0;
|
|
|
|
let deletedImages = 0;
|
|
|
|
const cacheDirectory = path.join(
|
|
|
|
const cacheDirectory = path.join(baseCacheDirectory, key);
|
|
|
|
__dirname,
|
|
|
|
|
|
|
|
'../../config/cache/images/',
|
|
|
|
|
|
|
|
key
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const files = await promises.readdir(cacheDirectory);
|
|
|
|
const files = await promises.readdir(cacheDirectory);
|
|
|
|
|
|
|
|
|
|
|
@ -57,11 +57,7 @@ class ImageProxy {
|
|
|
|
public static async getImageStats(
|
|
|
|
public static async getImageStats(
|
|
|
|
key: string
|
|
|
|
key: string
|
|
|
|
): Promise<{ size: number; imageCount: number }> {
|
|
|
|
): Promise<{ size: number; imageCount: number }> {
|
|
|
|
const cacheDirectory = path.join(
|
|
|
|
const cacheDirectory = path.join(baseCacheDirectory, key);
|
|
|
|
__dirname,
|
|
|
|
|
|
|
|
'../../config/cache/images/',
|
|
|
|
|
|
|
|
key
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const imageTotalSize = await ImageProxy.getDirectorySize(cacheDirectory);
|
|
|
|
const imageTotalSize = await ImageProxy.getDirectorySize(cacheDirectory);
|
|
|
|
const imageCount = await ImageProxy.getImageCount(cacheDirectory);
|
|
|
|
const imageCount = await ImageProxy.getImageCount(cacheDirectory);
|
|
|
@ -263,7 +259,7 @@ class ImageProxy {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private getCacheDirectory() {
|
|
|
|
private getCacheDirectory() {
|
|
|
|
return path.join(__dirname, '../../config/cache/images/', this.key);
|
|
|
|
return path.join(baseCacheDirectory, this.key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|