File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { HookContext } from '@feathersjs/feathers' ;
2
2
import Bluebird from 'bluebird' ;
3
3
import _ from 'lodash' ;
4
+ import Debug from 'debug' ;
4
5
6
+ const debug = Debug ( 's3-reuploads' ) ;
5
7
6
8
export default ( paths : string [ ] ) => async ( context : HookContext ) : Promise < HookContext > => {
7
9
const {
@@ -19,10 +21,13 @@ export default (paths: string[]) => async (context: HookContext): Promise<HookCo
19
21
20
22
// If image is not from our s3, fetch it!
21
23
if ( ! fileService . isS3url ( url ) ) {
24
+ debug ( 'Found non-s3 url!' ) ;
22
25
const filePath = await fileService . downloadFile ( url ) ;
23
26
const s3Path = fileService . generateS3Path ( user ?. username ) ;
24
27
const s3Url = await fileService . uploadFileToS3 ( filePath , s3Path ) ;
25
- return model . findOneAndUpdate ( { _id : result . _id } , { [ path ] : s3Url } ) ;
28
+ await model . findOneAndUpdate ( { _id : result . _id } , { $set : { [ path ] : s3Url } } ) ;
29
+ debug ( `Fetched and updated: from ${ url } to ${ s3Url } ` ) ;
30
+ return s3Url ;
26
31
}
27
32
return url ;
28
33
} ) ;
Original file line number Diff line number Diff line change @@ -55,7 +55,8 @@ export default {
55
55
} ,
56
56
after : {
57
57
all : convertPoll ,
58
- create : fetchImages ( [ 'contents.left.url' , 'contents.right.url' ] )
58
+ create : fetchImages ( [ 'contents.left.url' , 'contents.right.url' ] ) ,
59
+ patch : fetchImages ( [ 'contents.left.url' , 'contents.right.url' ] )
59
60
}
60
61
} ;
61
62
You can’t perform that action at this time.
0 commit comments