function fetchPixivData(url: string): Promise { // https://www.pixiv.net/artworks/143552616 const match = url.match(/\/artworks\/(\d+)/); if (!match) { throw new Error("Invalid Pixiv URL"); } const artworkId = match[1]; return fetch(`https://www.phixiv.net/api/info?id=${artworkId}&language=ko`) .then((response) => { if (!response.ok) { throw new Error(`Failed to fetch Pixiv data: ${response.status} ${response.statusText}`); } return response.json(); }) .then((data) => { // if #R-18 in tags, throw error if (data.tags && data.tags.some((tag: string) => tag.includes("R-18"))) { throw new Error("Pixiv artwork is marked as R-18"); } return data; }) .then((data) => { if (data.error) { throw new Error(`Pixiv API error: ${data.message}`); } return data; }); } export { fetchPixivData };