diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-12 21:12:02 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-12 21:14:37 +0300 |
commit | 763fd06f3076c96c7fa45ddd6efcc246520c8fbb (patch) | |
tree | 11dbf2c79e99101f400a3831471ba3e7de5d2a80 | |
parent | 15dfeb17076f1a25f564fbf5f694c3bfafb25c45 (diff) | |
download | which-api-763fd06f3076c96c7fa45ddd6efcc246520c8fbb.tar.gz |
fix: correctly reupload poll urls
-rw-r--r-- | hooks/fetchImages.ts | 7 | ||||
-rw-r--r-- | services/polls/polls.hooks.ts | 3 |
2 files changed, 8 insertions, 2 deletions
diff --git a/hooks/fetchImages.ts b/hooks/fetchImages.ts index 44aac6c..a7eb30c 100644 --- a/hooks/fetchImages.ts +++ b/hooks/fetchImages.ts @@ -1,7 +1,9 @@ import { HookContext } from '@feathersjs/feathers'; import Bluebird from 'bluebird'; import _ from 'lodash'; +import Debug from 'debug'; +const debug = Debug('s3-reuploads'); export default (paths: string[]) => async (context: HookContext): Promise<HookContext> => { const { @@ -19,10 +21,13 @@ export default (paths: string[]) => async (context: HookContext): Promise<HookCo // If image is not from our s3, fetch it! if (!fileService.isS3url(url)) { + debug('Found non-s3 url!'); const filePath = await fileService.downloadFile(url); const s3Path = fileService.generateS3Path(user?.username); const s3Url = await fileService.uploadFileToS3(filePath, s3Path); - return model.findOneAndUpdate({ _id: result._id }, { [path]: s3Url }); + await model.findOneAndUpdate({ _id: result._id }, { $set: { [path]: s3Url } }); + debug(`Fetched and updated: from ${url} to ${s3Url}`); + return s3Url; } return url; }); diff --git a/services/polls/polls.hooks.ts b/services/polls/polls.hooks.ts index 7a5b1da..7853c54 100644 --- a/services/polls/polls.hooks.ts +++ b/services/polls/polls.hooks.ts @@ -55,7 +55,8 @@ export default { }, after: { all: convertPoll, - create: fetchImages(['contents.left.url', 'contents.right.url']) + create: fetchImages(['contents.left.url', 'contents.right.url']), + patch: fetchImages(['contents.left.url', 'contents.right.url']) } }; |