feat: implement post existence check and detail page

This commit is contained in:
암냥 2026-04-18 06:48:21 +09:00
commit b18cff8b1a
No known key found for this signature in database
10 changed files with 646 additions and 43 deletions

View file

@ -1,3 +1,5 @@
import { MediaUpload } from "@/models/media";
function fetchPixivData(url: string): Promise<any> {
// https://www.pixiv.net/artworks/143552616
const match = url.match(/\/artworks\/(\d+)/);
@ -30,4 +32,27 @@ function fetchPixivData(url: string): Promise<any> {
});
}
export { fetchPixivData };
async function checkPixivData(url: string, selected: Array<boolean>) {
const match = url.match(/\/artworks\/(\d+)/);
if (!match) {
throw new Error("Invalid Pixiv URL");
}
const artworkId = match[1];
const selectedIndices = selected
.map((isSelected, index) => (isSelected ? index : -1))
.filter((index) => index >= 0);
if (selectedIndices.length === 0) {
return false;
}
const existing = await MediaUpload.findOne({
"tweet.id": artworkId,
mediaIndex: { $in: selectedIndices },
});
return existing !== null;
}
export { checkPixivData, fetchPixivData };