This commit is contained in:
암냥 2026-06-26 07:58:24 +09:00
commit 3344d6d532
6 changed files with 150 additions and 35 deletions

View file

@ -31,7 +31,16 @@ async function uploadToS3(fileName: string, mediaUrl: string, maxRetry = 3) {
for (let attempt = 1; attempt <= maxRetry; attempt++) {
try {
const response = await fetch(mediaUrl);
const parsedUrl = new URL(mediaUrl);
const isPixivImage = parsedUrl.hostname === "i.pximg.net";
const response = await fetch(mediaUrl, {
headers: isPixivImage
? {
"Referer": "https://www.pixiv.net/",
"User-Agent": "Mozilla/5.0 (compatible; akiyama.mizuki.guru/1.0)",
}
: undefined,
});
if (!response.ok) {
throw new Error(`Fetch failed: ${response.status}`);
}
@ -74,4 +83,4 @@ async function writeToS3(fileName: string, data: ArrayBuffer | Blob, contentType
});
}
export { makeS3FileName, uploadToS3, writeToS3, client as s3Client };
export { makeS3FileName, uploadToS3, writeToS3, client as s3Client };