A big commit Squashed commit of CORS:
commit 8cffa38ebae2a46b7c8e855c7b21a124e35adc89 Author: fyears <1142836+fyears@users.noreply.github.com> Date: Thu Mar 10 23:52:56 2022 +0800 bypass more cors for onedrive commit 1b59ac1e58032099068aab55d22ef96c6396f203 Author: fyears <1142836+fyears@users.noreply.github.com> Date: Wed Mar 9 23:58:28 2022 +0800 change wordings for webdav cors commit 73142eb18b59fff20839680e866f51cfcb0a6226 Author: fyears <1142836+fyears@users.noreply.github.com> Date: Wed Mar 9 23:38:58 2022 +0800 remove cors hint for webdav commit 7dbb0b49d50e529b2b72e55ea2c8503ba7fa9268 Author: fyears <1142836+fyears@users.noreply.github.com> Date: Wed Mar 9 23:31:54 2022 +0800 fix webdav commit c28c4e19720a56230d483acf306463d42e619fa4 Author: fyears <1142836+fyears@users.noreply.github.com> Date: Wed Mar 9 23:31:35 2022 +0800 remove more headers commit 4eeae7043fa68d669a5c23c5549c14c1260ce638 Author: fyears <1142836+fyears@users.noreply.github.com> Date: Wed Mar 9 23:18:32 2022 +0800 polish cors hints for s3 commit d9e55a91a1c413e9419cd6b30a3a6e3b403d483b Author: fyears <1142836+fyears@users.noreply.github.com> Date: Wed Mar 9 22:40:37 2022 +0800 fix format commit b780a3eb4e37b05b8e8b92d6a2f9283b3459d738 Author: fyears <1142836+fyears@users.noreply.github.com> Date: Wed Mar 9 22:37:02 2022 +0800 finally correctly inject requestUrl into s3 commit 6a55a1a43d7653d65579ab88aa816e5d54cd276a Author: fyears <1142836+fyears@users.noreply.github.com> Date: Wed Mar 9 22:33:18 2022 +0800 to arraybuffer from view commit 2f2607b4f0a3d9db5943528ced57cb2fdb419607 Author: fyears <1142836+fyears@users.noreply.github.com> Date: Wed Mar 9 13:31:22 2022 +0800 add split ranges commit ea24da24dea83fdb770e7e391cf8a2e4fea78d0d Author: fyears <1142836+fyears@users.noreply.github.com> Date: Sun Mar 6 22:57:50 2022 +0800 add settings of bypassing for s3 commit 2f099dc8ca1e66ea137b28dd329be50968734ba6 Author: fyears <1142836+fyears@users.noreply.github.com> Date: Sun Mar 6 22:38:07 2022 +0800 use api ver var commit 74c7ce2449a88cbe7c7f50cbb687b36ff3732c04 Author: fyears <1142836+fyears@users.noreply.github.com> Date: Sun Mar 6 22:37:25 2022 +0800 correct way to inject s3 commit f29945d73132d21b2c44472ec2cafc06b9d71e8f Author: fyears <1142836+fyears@users.noreply.github.com> Date: Tue Mar 1 00:09:57 2022 +0800 add new http handler commit d55104cb08e168cbcc243cf901cbd7f46f2e324b Author: fyears <1142836+fyears@users.noreply.github.com> Date: Mon Feb 28 22:59:55 2022 +0800 add types for patch commit 50b79ade7188ee7dfab9c1d03119585db358ba6f Author: fyears <1142836+fyears@users.noreply.github.com> Date: Mon Feb 28 08:25:19 2022 +0800 remove verbose commit 83f0e71aa15aa7586f6d4e105cd77c25c2e113ce Author: fyears <1142836+fyears@users.noreply.github.com> Date: Mon Feb 28 08:25:04 2022 +0800 patch webdav!
This commit is contained in:
+106
-7
@@ -1,18 +1,117 @@
|
||||
import { Buffer } from "buffer";
|
||||
import { Vault } from "obsidian";
|
||||
import type { FileStat, WebDAVClient } from "webdav/web";
|
||||
import { AuthType, BufferLike, createClient } from "webdav/web";
|
||||
import { Vault, request, requestUrl, requireApiVersion } from "obsidian";
|
||||
|
||||
import { Queue } from "@fyears/tsqueue";
|
||||
import chunk from "lodash/chunk";
|
||||
import flatten from "lodash/flatten";
|
||||
import type { RemoteItem, WebdavConfig } from "./baseTypes";
|
||||
import { getReasonPhrase } from "http-status-codes";
|
||||
import { API_VER_REQURL, RemoteItem, WebdavConfig } from "./baseTypes";
|
||||
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
|
||||
import { bufferToArrayBuffer, getPathFolder, mkdirpInVault } from "./misc";
|
||||
export type { WebDAVClient } from "webdav/web";
|
||||
|
||||
import * as origLog from "loglevel";
|
||||
const log = origLog.getLogger("rs-default");
|
||||
|
||||
import type {
|
||||
FileStat,
|
||||
WebDAVClient,
|
||||
RequestOptionsWithState,
|
||||
Response,
|
||||
ResponseDataDetailed,
|
||||
} from "webdav/web";
|
||||
import { getPatcher } from "webdav/web";
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
getPatcher().patch(
|
||||
"request",
|
||||
async (
|
||||
options: RequestOptionsWithState
|
||||
): Promise<Response | ResponseDataDetailed<any>> => {
|
||||
const transformedHeaders = { ...options.headers };
|
||||
delete transformedHeaders["host"];
|
||||
delete transformedHeaders["Host"];
|
||||
delete transformedHeaders["content-length"];
|
||||
delete transformedHeaders["Content-Length"];
|
||||
const r = await requestUrl({
|
||||
url: options.url,
|
||||
method: options.method,
|
||||
body: options.data as string | ArrayBuffer,
|
||||
headers: transformedHeaders,
|
||||
});
|
||||
|
||||
let r2: Response | ResponseDataDetailed<any> = undefined;
|
||||
if (options.responseType === undefined) {
|
||||
r2 = {
|
||||
data: undefined,
|
||||
status: r.status,
|
||||
statusText: getReasonPhrase(r.status),
|
||||
headers: r.headers,
|
||||
};
|
||||
} else if (options.responseType === "json") {
|
||||
r2 = {
|
||||
data: r.json,
|
||||
status: r.status,
|
||||
statusText: getReasonPhrase(r.status),
|
||||
headers: r.headers,
|
||||
};
|
||||
} else if (options.responseType === "text") {
|
||||
r2 = {
|
||||
data: r.text,
|
||||
status: r.status,
|
||||
statusText: getReasonPhrase(r.status),
|
||||
headers: r.headers,
|
||||
};
|
||||
} else if (options.responseType === "arraybuffer") {
|
||||
r2 = {
|
||||
data: r.arrayBuffer,
|
||||
status: r.status,
|
||||
statusText: getReasonPhrase(r.status),
|
||||
headers: r.headers,
|
||||
};
|
||||
} else {
|
||||
throw Error(
|
||||
`do not know how to deal with responseType = ${options.responseType}`
|
||||
);
|
||||
}
|
||||
return r2;
|
||||
}
|
||||
);
|
||||
}
|
||||
// getPatcher().patch("request", (options: any) => {
|
||||
// // console.log("using fetch");
|
||||
// const r = fetch(options.url, {
|
||||
// method: options.method,
|
||||
// body: options.data as any,
|
||||
// headers: options.headers,
|
||||
// signal: options.signal,
|
||||
// })
|
||||
// .then((rsp) => {
|
||||
// if (options.responseType === undefined) {
|
||||
// return Promise.all([undefined, rsp]);
|
||||
// }
|
||||
// if (options.responseType === "json") {
|
||||
// return Promise.all([rsp.json(), rsp]);
|
||||
// }
|
||||
// if (options.responseType === "text") {
|
||||
// return Promise.all([rsp.text(), rsp]);
|
||||
// }
|
||||
// if (options.responseType === "arraybuffer") {
|
||||
// return Promise.all([rsp.arrayBuffer(), rsp]);
|
||||
// }
|
||||
// })
|
||||
// .then(([d, r]) => {
|
||||
// return {
|
||||
// data: d,
|
||||
// status: r.status,
|
||||
// statusText: r.statusText,
|
||||
// headers: r.headers,
|
||||
// };
|
||||
// });
|
||||
// // console.log("using fetch");
|
||||
// return r;
|
||||
// });
|
||||
import { AuthType, BufferLike, createClient } from "webdav/web";
|
||||
export type { WebDAVClient } from "webdav/web";
|
||||
|
||||
export const DEFAULT_WEBDAV_CONFIG = {
|
||||
address: "",
|
||||
username: "",
|
||||
@@ -169,7 +268,7 @@ export const uploadToRemote = async (
|
||||
// if encrypted, upload a fake file with the encrypted file name
|
||||
await client.client.putFileContents(uploadFile, "", {
|
||||
overwrite: true,
|
||||
onUploadProgress: (progress) => {
|
||||
onUploadProgress: (progress: any) => {
|
||||
// log.info(`Uploaded ${progress.loaded} bytes of ${progress.total}`);
|
||||
},
|
||||
});
|
||||
@@ -200,7 +299,7 @@ export const uploadToRemote = async (
|
||||
}
|
||||
await client.client.putFileContents(uploadFile, remoteContent, {
|
||||
overwrite: true,
|
||||
onUploadProgress: (progress) => {
|
||||
onUploadProgress: (progress: any) => {
|
||||
log.info(`Uploaded ${progress.loaded} bytes of ${progress.total}`);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user