Skip to content

Commit 763fd06

Browse files
committed
fix: correctly reupload poll urls
1 parent 15dfeb1 commit 763fd06

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

hooks/fetchImages.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { HookContext } from '@feathersjs/feathers';
22
import Bluebird from 'bluebird';
33
import _ from 'lodash';
4+
import Debug from 'debug';
45

6+
const debug = Debug('s3-reuploads');
57

68
export default (paths: string[]) => async (context: HookContext): Promise<HookContext> => {
79
const {
@@ -19,10 +21,13 @@ export default (paths: string[]) => async (context: HookContext): Promise<HookCo
1921

2022
// If image is not from our s3, fetch it!
2123
if (!fileService.isS3url(url)) {
24+
debug('Found non-s3 url!');
2225
const filePath = await fileService.downloadFile(url);
2326
const s3Path = fileService.generateS3Path(user?.username);
2427
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;
2631
}
2732
return url;
2833
});

services/polls/polls.hooks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export default {
5555
},
5656
after: {
5757
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'])
5960
}
6061
};
6162

0 commit comments

Comments
 (0)