@@ -33,6 +33,7 @@ function makeAssetCachePath(cacheDir, cacheKey) {
33
33
return {
34
34
dir1 : bucket1HexString ,
35
35
dir2 : bucket2HexString ,
36
+ dir3 : hash . toString ( ) ,
36
37
path : path . join (
37
38
cacheDir ,
38
39
bucket1HexString ,
@@ -61,17 +62,17 @@ const middleWare = (module.exports = function(options) {
61
62
? options . cacheDir
62
63
: path . join ( process . cwd ( ) , "/tmp" ) ;
63
64
64
- const { dir1, dir2, path : assetCachePath } = middleWare . makeAssetCachePath (
65
+ const {
66
+ dir1,
67
+ dir2,
68
+ dir3,
69
+ path : assetCachePath
70
+ } = middleWare . makeAssetCachePath (
65
71
options . cacheDir ,
66
72
res . locals . cacheKey || res . locals . fetchUrl
67
73
) ;
68
74
69
75
try {
70
- // node 10 supports recursive: true, but who knows?
71
- middleWare . makeDirIfNotExists ( options . cacheDir ) ;
72
- middleWare . makeDirIfNotExists ( path . join ( options . cacheDir , dir1 ) ) ;
73
- middleWare . makeDirIfNotExists ( path . join ( options . cacheDir , dir1 , dir2 ) ) ;
74
-
75
76
if ( fs . existsSync ( assetCachePath ) ) {
76
77
const firstFile = fs . readdirSync ( assetCachePath ) [ 0 ] ;
77
78
@@ -89,6 +90,14 @@ const middleWare = (module.exports = function(options) {
89
90
90
91
res . locals . buffer = fs . readFileSync ( `${ assetCachePath } /${ firstFile } ` ) ;
91
92
} else {
93
+ // node 10 supports recursive: true, but who knows?
94
+ middleWare . makeDirIfNotExists ( options . cacheDir ) ;
95
+ middleWare . makeDirIfNotExists ( path . join ( options . cacheDir , dir1 ) ) ;
96
+ middleWare . makeDirIfNotExists ( path . join ( options . cacheDir , dir1 , dir2 ) ) ;
97
+ middleWare . makeDirIfNotExists (
98
+ path . join ( options . cacheDir , dir1 , dir2 , dir3 )
99
+ ) ;
100
+
92
101
const blob = await ( await fetch ( res . locals . fetchUrl ) ) . blob ( ) ;
93
102
94
103
const fileName = middleWare . encodeAssetCacheName ( blob . type , blob . size ) ;
0 commit comments