Refine partId extraction logic to ensure valid animestore URLs and update error message for clarity

This commit is contained in:
Nik Afiq 2025-12-06 20:04:27 +09:00
parent 138e0d5eb7
commit aebd3048f6

View File

@ -43,11 +43,13 @@ function extractPartId(urlStr: string): string | null {
if (!trimmed) return null;
try {
const u = new URL(trimmed);
if (!u.hostname.endsWith("animestore.docomo.ne.jp")) return null;
const partId = u.searchParams.get("partId") || u.searchParams.get("partid");
if (partId) return partId;
} catch {
// fallback to regex
}
if (!trimmed.includes("animestore.docomo.ne.jp")) return null;
const m = trimmed.match(/partId=(\d+)/i);
return m ? m[1] : null;
}
@ -165,7 +167,7 @@ export default function ShowsPage() {
setDanimeResult(null);
const partId = extractPartId(danimeUrl);
if (!partId) {
setScrapeError("partId を含む dアニメのURLを入力してください。");
setScrapeError("animestore.docomo.ne.jp のエピソードURLpartId付きを入力してください。");
return;
}
try {