This commit is contained in:
암냥 2026-04-23 19:11:16 +09:00
commit 3c601295b1
No known key found for this signature in database
5 changed files with 82 additions and 13 deletions

View file

@ -11,6 +11,8 @@ const mediaUploadSchema = new mongoose.Schema({
mediaIndex: { type: Number, required: true },
mediaUrl: { type: String, required: true },
s3Key: { type: String, required: true },
mediaType: { type: String, enum: ["image", "video"], default: "image" },
thumbnailUrl: { type: String },
tags: { type: [String], default: [] },
author: { type: String, required: true },
uploadedBy: {

View file

@ -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;
}