@@ -8,7 +8,7 @@ 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 , / ;
1414
@@ -22,21 +22,24 @@ function processImage(asset, { storage }) {
2222 return Promise . resolve ( asset ) ;
2323 }
2424
25+ const storage = getRepositoryStorage ( asset . repositoryId ) ;
2526 const file = Buffer . from ( image . replace ( base64Pattern , '' ) , 'base64' ) ;
2627 const extension = image . match ( base64Pattern ) [ 1 ] || DEFAULT_IMAGE_EXTENSION ;
2728 const hashString = `${ asset . id } ${ file } ` ;
2829 const hash = crypto . createHash ( 'md5' ) . update ( hashString ) . digest ( 'hex' ) ;
29- const storagePath = storage . getPath ( asset . repositoryId ) ;
30- const key = `${ storagePath } /${ asset . id } /${ hash } .${ extension } ` ;
30+ const key = `${ asset . id } /${ hash } .${ extension } ` ;
3131 asset . data . url = key ;
3232 return saveFile ( key , file , storage ) . 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 ) ;
3737
38+ const storage = getRepositoryStorage ( asset . repositoryId ) ;
39+
3840 function getUrl ( key ) {
39- asset . data . url = storageProxy . getFileUrl ( key ) ;
41+ const fullKey = storage . getFullKey ( key ) ;
42+ asset . data . url = storageProxy . getFileUrl ( fullKey ) ;
4043 return asset ;
4144 }
4245
0 commit comments