@@ -8,10 +8,9 @@ const mime = require('mime-types');
8
8
9
9
const DEFAULT_IMAGE_EXTENSION = 'png' ;
10
10
11
- function processImage ( asset , { storage } ) {
11
+ function processImage ( asset , { getRepositoryStorage } ) {
12
12
const image = asset . data . url ;
13
13
const base64Pattern = / ^ d a t a : i m a g e \/ ( \w + ) ; b a s e 6 4 , / ;
14
-
15
14
if ( ! isString ( image ) || ( ! isUrl ( image ) && ! image . match ( base64Pattern ) ) ) {
16
15
return Promise . resolve ( asset ) ;
17
16
}
@@ -26,17 +25,20 @@ function processImage(asset, { storage }) {
26
25
const extension = image . match ( base64Pattern ) [ 1 ] || DEFAULT_IMAGE_EXTENSION ;
27
26
const hashString = `${ asset . id } ${ file } ` ;
28
27
const hash = crypto . createHash ( 'md5' ) . update ( hashString ) . digest ( 'hex' ) ;
29
- const storagePath = storage . getPath ( asset . repositoryId ) ;
30
- const key = `${ storagePath } /${ asset . id } /${ hash } .${ extension } ` ;
28
+ const key = `${ asset . id } /${ hash } .${ extension } ` ;
31
29
asset . data . url = key ;
32
- return saveFile ( key , file , storage ) . then ( ( ) => asset ) ;
30
+ const storage = getRepositoryStorage ( asset . repositoryId ) ;
31
+ return saveFile ( key , file , storage )
32
+ . then ( ( ) => asset ) ;
33
33
}
34
34
35
- function resolveImage ( asset , { storage , storageProxy } ) {
35
+ function resolveImage ( asset , { getRepositoryStorage , storageProxy } ) {
36
36
if ( ! asset . data || ! asset . data . url ) return Promise . resolve ( asset ) ;
37
+ const storage = getRepositoryStorage ( asset . repositoryId ) ;
37
38
38
39
function getUrl ( key ) {
39
- asset . data . url = storageProxy . getFileUrl ( key ) ;
40
+ const fullKey = storage . getFullKey ( key ) ;
41
+ asset . data . url = storageProxy . getFileUrl ( fullKey ) ;
40
42
return asset ;
41
43
}
42
44
0 commit comments