@@ -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+
2125class 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