feat: implement post existence check and detail page
This commit is contained in:
parent
55af0549e7
commit
b18cff8b1a
10 changed files with 646 additions and 43 deletions
|
|
@ -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 };
|
||||
Loading…
Add table
Add a link
Reference in a new issue