feat: add endpoint to retrieve random media URL from posts

This commit is contained in:
암냥 2026-06-25 17:25:38 +09:00
commit ddcfacb47d
No known key found for this signature in database

View file

@ -613,4 +613,15 @@ export default new Elysia({ prefix: "/post" })
if (!randomPost) return status(404, "포스트를 찾을 수 없습니다."); if (!randomPost) return status(404, "포스트를 찾을 수 없습니다.");
return fetch(randomPost.mediaUrl, { cache: "no-store" }); return fetch(randomPost.mediaUrl, { cache: "no-store" });
})
.get("/random/url", async ({ status }) => {
const count = await MediaUpload.countDocuments();
if (count === 0) return status(404, "포스트를 찾을 수 없습니다.");
const randomIndex = Math.floor(Math.random() * count);
const randomPost = await MediaUpload.findOne().skip(randomIndex);
if (!randomPost) return status(404, "포스트를 찾을 수 없습니다.");
return randomPost.mediaUrl;
}); });