From a2ce95441ac86d0d6182eb4a29131d4431d70464 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Sat, 29 Jun 2024 00:43:01 +0800 Subject: [PATCH] download at best effort --- src/fsOnedrive.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/fsOnedrive.ts b/src/fsOnedrive.ts index 6102a35..6e05c34 100644 --- a/src/fsOnedrive.ts +++ b/src/fsOnedrive.ts @@ -986,11 +986,24 @@ export class FakeFsOnedrive extends FakeFs { ).arrayBuffer; return content; } else { - // cannot set no-cache here, will have cors error - const content = await ( - await fetch(downloadUrl, { cache: "no-store" }) - ).arrayBuffer(); - return content; + // so strange, sometimes (!!!) + // we cannot download the file because of CORS + try { + // cannot set no-cache here, will have cors error + const content = await ( + await fetch(downloadUrl, { cache: "no-store" }) + ).arrayBuffer(); + return content; + } catch (e) { + // let's try again to bypass the CORS + const content = ( + await requestUrl({ + url: downloadUrl, + headers: { "Cache-Control": "no-cache" }, + }) + ).arrayBuffer; + return content; + } } }