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,9 +546,20 @@ 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({
url: theUrl,
method: "PUT",
body: bufferToArrayBuffer(payload.subarray(rangeStart, rangeEnd)),
headers: {
// no "Content-Length" allowed here
"Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`,
"Content-Type": "application/octet-stream",
},
});
return res.json as DriveItem | UploadSession;
} else {
const res = await fetch(theUrl, { const res = await fetch(theUrl, {
method: "PUT", method: "PUT",
body: payload.subarray(rangeStart, rangeEnd), body: payload.subarray(rangeStart, rangeEnd),
@ -558,6 +570,7 @@ export class WrappedOnedriveClient {
}, },
}); });
return (await res.json()) as DriveItem | UploadSession; return (await res.json()) as DriveItem | UploadSession;
}
}; };
} }