wow
This commit is contained in:
parent
d5c9469624
commit
3c601295b1
5 changed files with 82 additions and 13 deletions
|
|
@ -256,6 +256,8 @@ export default new Elysia({ prefix: "/post" })
|
|||
} : undefined,
|
||||
mediaUrl: post.mediaUrl,
|
||||
mediaIndex: post.mediaIndex,
|
||||
mediaType: post.mediaType,
|
||||
thumbnailUrl: post.thumbnailUrl,
|
||||
};
|
||||
}, {
|
||||
params: t.Object({
|
||||
|
|
@ -558,12 +560,11 @@ export default new Elysia({ prefix: "/post" })
|
|||
let savedCount = 0;
|
||||
let failedCount = 0;
|
||||
if (tweetData.tweet) {
|
||||
const media = tweetData.tweet.media.photos || [];
|
||||
const media = tweetData.tweet.media.all || tweetData.tweet.media.photos || [];
|
||||
if (media.length > 0) {
|
||||
const mediaUrls = media.map((m: any) => m.url);
|
||||
const hasExplicitSelection = body.selected.length > 0;
|
||||
const savedIds: string[] = [];
|
||||
for (const [index, url] of mediaUrls.entries()) {
|
||||
for (const [index, mediaItem] of media.entries()) {
|
||||
const isSelected = hasExplicitSelection
|
||||
? body.selected[index] === true
|
||||
: true;
|
||||
|
|
@ -572,13 +573,15 @@ export default new Elysia({ prefix: "/post" })
|
|||
continue;
|
||||
}
|
||||
|
||||
const fileName = makeS3FileName(tweetData.tweet.author.id, tweetData.tweet.id, url, index);
|
||||
const fileName = makeS3FileName(tweetData.tweet.author.id, tweetData.tweet.id, mediaItem.url, index);
|
||||
|
||||
const { media: _media, ...tweetWithoutMedia } = tweetData.tweet;
|
||||
const normalizedTags = normalizeTags(body.tag || ["미분류"]);
|
||||
const mediaType = (mediaItem.type === "video" || mediaItem.type === "gif") ? "video" : "image";
|
||||
|
||||
const result = await uploadAndCreateWithRetry({
|
||||
fileName,
|
||||
mediaUrl: url,
|
||||
mediaUrl: mediaItem.url,
|
||||
mediaIndex: index,
|
||||
createDocument: async () => {
|
||||
return await MediaUpload.create({
|
||||
|
|
@ -587,6 +590,8 @@ export default new Elysia({ prefix: "/post" })
|
|||
mediaIndex: index,
|
||||
mediaUrl: `${config.s3.endpoint}/${config.s3.bucket}/${fileName}`,
|
||||
s3Key: fileName,
|
||||
mediaType,
|
||||
thumbnailUrl: mediaItem.thumbnail_url,
|
||||
tags: normalizedTags,
|
||||
author: body.author ? body.author : tweetData.tweet.author.name,
|
||||
uploadedBy: {
|
||||
|
|
@ -601,7 +606,7 @@ export default new Elysia({ prefix: "/post" })
|
|||
|
||||
if (!result.ok) {
|
||||
failedCount += 1;
|
||||
console.error(`[Upload failed] index=${index} url=${url} key=${fileName}`, result.error);
|
||||
console.error(`[Upload failed] index=${index} url=${mediaItem.url} key=${fileName}`, result.error);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue