fully bypass cors for onedrive!

This commit is contained in:
fyears 2022-03-11 09:09:41 +08:00
parent c04876e0c5
commit ecc46f2ea1

View File

@ -17,6 +17,7 @@ import {
} from "./baseTypes"; } from "./baseTypes";
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt"; import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
import { import {
bufferToArrayBuffer,
getRandomArrayBuffer, getRandomArrayBuffer,
getRandomIntInclusive, getRandomIntInclusive,
mkdirpInVault, mkdirpInVault,
@ -545,19 +546,31 @@ export class WrappedOnedriveClient {
rangeEnd - 1 rangeEnd - 1
}, len=${rangeEnd - rangeStart}, size=${size}` }, len=${rangeEnd - rangeStart}, size=${size}`
); );
// obsidian requestUrl doesn't support setting Content-Length // NO AUTH HEADER here!
// currently downgraded to fetch()! if (requireApiVersion(API_VER_REQURL)) {
// AND, NO AUTH HEADER here! const res = await requestUrl({
const res = await fetch(theUrl, { url: theUrl,
method: "PUT", method: "PUT",
body: payload.subarray(rangeStart, rangeEnd), body: bufferToArrayBuffer(payload.subarray(rangeStart, rangeEnd)),
headers: { headers: {
"Content-Length": `${rangeEnd - rangeStart}`, // no "Content-Length" allowed here
"Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`, "Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`,
"Content-Type": "application/octet-stream", "Content-Type": "application/octet-stream",
}, },
}); });
return (await res.json()) as DriveItem | UploadSession; return res.json as DriveItem | UploadSession;
} else {
const res = await fetch(theUrl, {
method: "PUT",
body: payload.subarray(rangeStart, rangeEnd),
headers: {
"Content-Length": `${rangeEnd - rangeStart}`,
"Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`,
"Content-Type": "application/octet-stream",
},
});
return (await res.json()) as DriveItem | UploadSession;
}
}; };
} }