@@ -8,10 +8,9 @@ const mime = require('mime-types');
88
99const DEFAULT_IMAGE_EXTENSION = 'png' ;
1010
11- function processImage ( asset , { storage } ) {
11+ function processImage ( asset , { getRepositoryStorage } ) {
1212 const image = asset . data . url ;
1313 const base64Pattern = / ^ d a t a : i m a g e \/ ( \w + ) ; b a s e 6 4 , / ;
14-
1514 if ( ! isString ( image ) || ( ! isUrl ( image ) && ! image . match ( base64Pattern ) ) ) {
1615 return Promise . resolve ( asset ) ;
1716 }
@@ -26,17 +25,20 @@ function processImage(asset, { storage }) {
2625 const extension = image . match ( base64Pattern ) [ 1 ] || DEFAULT_IMAGE_EXTENSION ;
2726 const hashString = `${ asset . id } ${ file } ` ;
2827 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 } ` ;
3129 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 ) ;
3333}
3434
35- function resolveImage ( asset , { storage , storageProxy } ) {
35+ function resolveImage ( asset , { getRepositoryStorage , storageProxy } ) {
3636 if ( ! asset . data || ! asset . data . url ) return Promise . resolve ( asset ) ;
37+ const storage = getRepositoryStorage ( asset . repositoryId ) ;
3738
3839 function getUrl ( key ) {
39- asset . data . url = storageProxy . getFileUrl ( key ) ;
40+ const fullKey = storage . getFullKey ( key ) ;
41+ asset . data . url = storageProxy . getFileUrl ( fullKey ) ;
4042 return asset ;
4143 }
4244
0 commit comments