From f6f7d83a350d43f5ba1c5148bbe7240bb3cc5e7b Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Sat, 30 Apr 2022 19:07:12 +0800 Subject: [PATCH] correct way to skip cache for onedrive --- src/remoteForOnedrive.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/remoteForOnedrive.ts b/src/remoteForOnedrive.ts index 1ce3d3f..492ee33 100644 --- a/src/remoteForOnedrive.ts +++ b/src/remoteForOnedrive.ts @@ -444,6 +444,7 @@ export class WrappedOnedriveClient { contentType: "application/json", headers: { Authorization: `Bearer ${await this.authGetter.getAccessToken()}`, + "Cache-Control": "no-cache", }, }) ); @@ -460,6 +461,7 @@ export class WrappedOnedriveClient { body: JSON.stringify(payload), headers: { Authorization: `Bearer ${await this.authGetter.getAccessToken()}`, + "Cache-Control": "no-cache", }, }) ); @@ -476,6 +478,7 @@ export class WrappedOnedriveClient { body: JSON.stringify(payload), headers: { Authorization: `Bearer ${await this.authGetter.getAccessToken()}`, + "Cache-Control": "no-cache", }, }) ); @@ -490,6 +493,7 @@ export class WrappedOnedriveClient { method: "DELETE", headers: { Authorization: `Bearer ${await this.authGetter.getAccessToken()}`, + "Cache-Control": "no-cache", }, }); } else { @@ -497,6 +501,7 @@ export class WrappedOnedriveClient { method: "DELETE", headers: { Authorization: `Bearer ${await this.authGetter.getAccessToken()}`, + "Cache-Control": "no-cache", }, }); } @@ -517,6 +522,7 @@ export class WrappedOnedriveClient { headers: { "Content-Type": DEFAULT_CONTENT_TYPE, Authorization: `Bearer ${await this.authGetter.getAccessToken()}`, + "Cache-Control": "no-cache", }, }); } else { @@ -526,6 +532,7 @@ export class WrappedOnedriveClient { headers: { "Content-Type": DEFAULT_CONTENT_TYPE, Authorization: `Bearer ${await this.authGetter.getAccessToken()}`, + "Cache-Control": "no-cache", }, }); } @@ -565,6 +572,7 @@ export class WrappedOnedriveClient { headers: { // no "Content-Length" allowed here "Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`, + /* "Cache-Control": "no-cache", not allowed here!!! */ }, }); return res.json as DriveItem | UploadSession; @@ -576,6 +584,7 @@ export class WrappedOnedriveClient { "Content-Length": `${rangeEnd - rangeStart}`, "Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`, "Content-Type": DEFAULT_CONTENT_TYPE, + /* "Cache-Control": "no-cache", not allowed here!!! */ }, }); return (await res.json()) as DriveItem | UploadSession; @@ -809,10 +818,21 @@ const downloadFromRemoteRaw = async ( ); const downloadUrl: string = rsp["@microsoft.graph.downloadUrl"]; if (VALID_REQURL) { - const content = (await requestUrl({ url: downloadUrl })).arrayBuffer; + const content = ( + await requestUrl({ + url: downloadUrl, + headers: { "Cache-Control": "no-cache" }, + }) + ).arrayBuffer; return content; } else { - const content = await (await fetch(downloadUrl)).arrayBuffer(); + const content = await ( + await fetch(downloadUrl, { + headers: { + "Cache-Control": "no-cache", + }, + }) + ).arrayBuffer(); return content; } };