Implement a timeout for downloads

This commit is contained in:
nexryai
2026-01-12 21:41:17 +09:00
committed by GitHub
parent 2fd38076a6
commit c3f75ccf13
+8
View File
@@ -304,10 +304,18 @@ async function streamDownloadFromDrive(accessToken: string, bucket: string, obje
throw new Error("File not found");
}
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();
}, 5000);
const downloadRes = await fetch(`https://www.googleapis.com/drive/v3/files/${file.id}?alt=media`, {
headers: { Authorization: `Bearer ${accessToken}` },
signal: controller.signal,
});
clearTimeout(timeout);
if (!downloadRes.ok) {
console.error(downloadRes.status);
console.error(await downloadRes.text());