wow
This commit is contained in:
parent
a5c4a74a69
commit
3344d6d532
6 changed files with 150 additions and 35 deletions
|
|
@ -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 };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue