feat: add endpoint to retrieve random media URL from posts
This commit is contained in:
parent
2809436d89
commit
ddcfacb47d
1 changed files with 11 additions and 0 deletions
|
|
@ -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;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue