From ce8d8d1c6250a4994f9b25dc85e91cde6ca0cd35 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Sun, 31 Dec 2023 22:41:48 +0800 Subject: [PATCH 01/23] beta --- manifest-beta.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 manifest-beta.json diff --git a/manifest-beta.json b/manifest-beta.json new file mode 100644 index 0000000..06cdacc --- /dev/null +++ b/manifest-beta.json @@ -0,0 +1,10 @@ +{ + "id": "remotely-save", + "name": "Remotely Save", + "version": "0.3.26", + "minAppVersion": "0.13.21", + "description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.", + "author": "fyears", + "authorUrl": "https://github.com/fyears", + "isDesktopOnly": false +} From 6a009b93cbbde1388e17eb88fe603f952bfcd389 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 00:43:59 +0800 Subject: [PATCH 02/23] fix webdav for new er --- src/remoteForWebdav.ts | 111 ++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 62 deletions(-) diff --git a/src/remoteForWebdav.ts b/src/remoteForWebdav.ts index d305e11..e9f517c 100644 --- a/src/remoteForWebdav.ts +++ b/src/remoteForWebdav.ts @@ -15,16 +15,16 @@ import type { FileStat, WebDAVClient, RequestOptionsWithState, - Response, - ResponseDataDetailed, + // Response, + // ResponseDataDetailed, } from "webdav"; -import { getPatcher } from "webdav"; + +// @ts-ignore +import { getPatcher } from "webdav/dist/web/index.js"; if (VALID_REQURL) { getPatcher().patch( "request", - async ( - options: RequestOptionsWithState - ): Promise> => { + async (options: RequestOptionsWithState): Promise => { const transformedHeaders = { ...options.headers }; delete transformedHeaders["host"]; delete transformedHeaders["Host"]; @@ -37,80 +37,65 @@ if (VALID_REQURL) { headers: transformedHeaders, }); - let r2: Response | ResponseDataDetailed = undefined; - if ((options as any).responseType === undefined) { - r2 = { - data: undefined, + let contentType: string | undefined = + r.headers["Content-Type"] || + r.headers["content-type"] || + options.headers["Content-Type"] || + options.headers["content-type"] || + options.headers["Accept"] || + options.headers["accept"]; + if (contentType !== undefined) { + contentType = contentType.toLowerCase(); + } + // console.log(`contentType=${contentType}`) + + let r2: Response = undefined; + if (contentType.includes("xml")) { + r2 = new Response(r.text, { status: r.status, statusText: getReasonPhrase(r.status), headers: r.headers, - }; - } else if ((options as any).responseType === "json") { - r2 = { - data: r.json, + }); + } else if ( + contentType.includes("json") || + contentType.includes("javascript") + ) { + r2 = new Response(r.json, { status: r.status, statusText: getReasonPhrase(r.status), headers: r.headers, - }; - } else if ((options as any).responseType === "text") { - r2 = { - data: r.text, + }); + } else if (contentType.includes("text")) { + // avoid text/json, + // so we split this out from the above xml or json branch + r2 = new Response(r.text, { status: r.status, statusText: getReasonPhrase(r.status), headers: r.headers, - }; - } else if ((options as any).responseType === "arraybuffer") { - r2 = { - data: r.arrayBuffer, + }); + } else if ( + contentType.includes("octet-stream") || + contentType.includes("binary") || + contentType.includes("buffer") + ) { + // application/octet-stream + r2 = new Response(r.arrayBuffer, { status: r.status, statusText: getReasonPhrase(r.status), headers: r.headers, - }; + }); } else { throw Error( - `do not know how to deal with responseType = ${ - (options as any).responseType - }` + `do not know how to deal with requested content type = ${contentType}` ); } 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"; + +// @ts-ignore +import { AuthType, BufferLike, createClient } from "webdav/dist/web/index.js"; export type { WebDAVClient } from "webdav"; export const DEFAULT_WEBDAV_CONFIG = { @@ -234,8 +219,9 @@ export class WrappedWebdavClient { method: "PROPFIND", headers: { Depth: "infinity", + Accept: "text/plain,application/xml", }, - responseType: "text", + // responseType: "text", } as any); if (res.status === 403) { throw Error("not support Infinity, get 403"); @@ -255,8 +241,9 @@ export class WrappedWebdavClient { method: "PROPFIND", headers: { Depth: "1", + Accept: "text/plain,application/xml", }, - responseType: "text", + // responseType: "text", } as any ); testPassed = true; From 2d7c33fb1abb745f6bfa2313156b9136c2b827d5 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 00:45:22 +0800 Subject: [PATCH 03/23] add docs for webdav infinicloud --- .../webdav_infinicloud_teracloud/README.md | 15 +++++++++++++++ .../infinicloud_account.png | 3 +++ .../infinicloud_rs_setting.png | 3 +++ 3 files changed, 21 insertions(+) create mode 100644 docs/remote_services/webdav_infinicloud_teracloud/README.md create mode 100644 docs/remote_services/webdav_infinicloud_teracloud/infinicloud_account.png create mode 100644 docs/remote_services/webdav_infinicloud_teracloud/infinicloud_rs_setting.png diff --git a/docs/remote_services/webdav_infinicloud_teracloud/README.md b/docs/remote_services/webdav_infinicloud_teracloud/README.md new file mode 100644 index 0000000..231d945 --- /dev/null +++ b/docs/remote_services/webdav_infinicloud_teracloud/README.md @@ -0,0 +1,15 @@ +# InfiniCLOUD (formally TeraCLOUD) Webdav + +## Link + + + +## Steps + +1. Register an acount. +2. Go to , in section "Apps Connection", enable "Turn on Apps Connection". Here you get the address and account and webdav password (different from your account password): + ![](./infinicloud_account.png) +3. In remotely-save setting page, select webdav type, then input the address/account/**webdav password**(not your account password). + ![](./infinicloud_rs_setting.png) +4. In remotely-save setting page, click "Check Connectivity". +5. Sync! diff --git a/docs/remote_services/webdav_infinicloud_teracloud/infinicloud_account.png b/docs/remote_services/webdav_infinicloud_teracloud/infinicloud_account.png new file mode 100644 index 0000000..53c8b4d --- /dev/null +++ b/docs/remote_services/webdav_infinicloud_teracloud/infinicloud_account.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e16bc9d86b30ab907fc176087701474f4ca2b8d887f649302f2e184f69d0cbc +size 373845 diff --git a/docs/remote_services/webdav_infinicloud_teracloud/infinicloud_rs_setting.png b/docs/remote_services/webdav_infinicloud_teracloud/infinicloud_rs_setting.png new file mode 100644 index 0000000..b9da8f9 --- /dev/null +++ b/docs/remote_services/webdav_infinicloud_teracloud/infinicloud_rs_setting.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d707f6997df57b9c6b74d72bcfd567995d15062269761ee404e6596a266a241 +size 91012 From 95197938601ffe6172119343e6934b6dd9ddb759 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:15:51 +0800 Subject: [PATCH 04/23] finally a real working compat for webdav --- src/remoteForWebdav.ts | 102 +++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/src/remoteForWebdav.ts b/src/remoteForWebdav.ts index e9f517c..53d2997 100644 --- a/src/remoteForWebdav.ts +++ b/src/remoteForWebdav.ts @@ -30,6 +30,7 @@ if (VALID_REQURL) { delete transformedHeaders["Host"]; delete transformedHeaders["content-length"]; delete transformedHeaders["Content-Length"]; + const r = await requestUrl({ url: options.url, method: options.method, @@ -47,48 +48,60 @@ if (VALID_REQURL) { if (contentType !== undefined) { contentType = contentType.toLowerCase(); } - // console.log(`contentType=${contentType}`) + // console.log(`requesting url=${options.url}`); + // console.log(`contentType=${contentType}`); - let r2: Response = undefined; - if (contentType.includes("xml")) { - r2 = new Response(r.text, { - status: r.status, - statusText: getReasonPhrase(r.status), - headers: r.headers, - }); - } else if ( - contentType.includes("json") || - contentType.includes("javascript") - ) { - r2 = new Response(r.json, { - status: r.status, - statusText: getReasonPhrase(r.status), - headers: r.headers, - }); - } else if (contentType.includes("text")) { - // avoid text/json, - // so we split this out from the above xml or json branch - r2 = new Response(r.text, { - status: r.status, - statusText: getReasonPhrase(r.status), - headers: r.headers, - }); - } else if ( - contentType.includes("octet-stream") || - contentType.includes("binary") || - contentType.includes("buffer") - ) { - // application/octet-stream - r2 = new Response(r.arrayBuffer, { - status: r.status, - statusText: getReasonPhrase(r.status), - headers: r.headers, - }); - } else { - throw Error( - `do not know how to deal with requested content type = ${contentType}` - ); - } + // let r2: Response = undefined; + // if (contentType.includes("xml")) { + // r2 = new Response(r.text, { + // status: r.status, + // statusText: getReasonPhrase(r.status), + // headers: r.headers, + // }); + // } else if ( + // contentType.includes("json") || + // contentType.includes("javascript") + // ) { + // console.log('inside json branch'); + // // const j = r.json; + // // console.log(j); + // r2 = new Response( + // r.text, // yea, here is the text because Response constructor expects a text + // { + // status: r.status, + // statusText: getReasonPhrase(r.status), + // headers: r.headers, + // }); + // } else if (contentType.includes("text")) { + // // avoid text/json, + // // so we split this out from the above xml or json branch + // r2 = new Response(r.text, { + // status: r.status, + // statusText: getReasonPhrase(r.status), + // headers: r.headers, + // }); + // } else if ( + // contentType.includes("octet-stream") || + // contentType.includes("binary") || + // contentType.includes("buffer") + // ) { + // // application/octet-stream + // r2 = new Response(r.arrayBuffer, { + // status: r.status, + // statusText: getReasonPhrase(r.status), + // headers: r.headers, + // }); + // } else { + // throw Error( + // `do not know how to deal with requested content type = ${contentType}` + // ); + // } + + const r2 = new Response(r.arrayBuffer, { + status: r.status, + statusText: getReasonPhrase(r.status), + headers: r.headers, + }); return r2; } ); @@ -444,9 +457,9 @@ const downloadFromRemoteRaw = async ( fileOrFolderPath: string ) => { await client.init(); - const buff = (await client.client.getFileContents( - getWebdavPath(fileOrFolderPath, client.remoteBaseDir) - )) as BufferLike; + const p = getWebdavPath(fileOrFolderPath, client.remoteBaseDir); + // console.log(`getWebdavPath=${p}`); + const buff = (await client.client.getFileContents(p)) as BufferLike; if (buff instanceof ArrayBuffer) { return buff; } else if (buff instanceof Buffer) { @@ -485,6 +498,7 @@ export const downloadFromRemote = async ( downloadFile = remoteEncryptedKey; } downloadFile = getWebdavPath(downloadFile, client.remoteBaseDir); + // console.log(`downloadFile=${downloadFile}`); const remoteContent = await downloadFromRemoteRaw(client, downloadFile); let localContent = remoteContent; if (password !== "") { From 2deb3be8eb1cb625d738ccdcef129e8f8607983a Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:16:39 +0800 Subject: [PATCH 05/23] bump 0.3.27 --- manifest-beta.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest-beta.json b/manifest-beta.json index 06cdacc..4aa908b 100644 --- a/manifest-beta.json +++ b/manifest-beta.json @@ -1,7 +1,7 @@ { "id": "remotely-save", "name": "Remotely Save", - "version": "0.3.26", + "version": "0.3.27", "minAppVersion": "0.13.21", "description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.", "author": "fyears", From cd0a9a395f98ad8622637d34152fb071e5f8b2ad Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:25:25 +0800 Subject: [PATCH 06/23] fix null body webdav --- src/remoteForWebdav.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/remoteForWebdav.ts b/src/remoteForWebdav.ts index 53d2997..b8cd0d1 100644 --- a/src/remoteForWebdav.ts +++ b/src/remoteForWebdav.ts @@ -97,11 +97,23 @@ if (VALID_REQURL) { // ); // } - const r2 = new Response(r.arrayBuffer, { - status: r.status, - statusText: getReasonPhrase(r.status), - headers: r.headers, - }); + let r2: Response = undefined; + if ([101, 103, 204, 205, 304].includes(r.status)) { + // A null body status is a status that is 101, 103, 204, 205, or 304. + // fix this: Failed to construct 'Response': Response with null body status cannot have body + r2 = new Response(null, { + status: r.status, + statusText: getReasonPhrase(r.status), + headers: r.headers, + }); + } else { + r2 = new Response(r.arrayBuffer, { + status: r.status, + statusText: getReasonPhrase(r.status), + headers: r.headers, + }); + } + return r2; } ); From 200d25de7038818a68b70abeeedb98c41f6528e3 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:26:00 +0800 Subject: [PATCH 07/23] 0.3.28 --- manifest-beta.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest-beta.json b/manifest-beta.json index 4aa908b..a3d1a1a 100644 --- a/manifest-beta.json +++ b/manifest-beta.json @@ -1,7 +1,7 @@ { "id": "remotely-save", "name": "Remotely Save", - "version": "0.3.27", + "version": "0.3.28", "minAppVersion": "0.13.21", "description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.", "author": "fyears", From bbb909cda47ff43c9e43c47b8a31b5ee1f6c9166 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:32:22 +0800 Subject: [PATCH 08/23] add link for null body --- src/remoteForWebdav.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/remoteForWebdav.ts b/src/remoteForWebdav.ts index b8cd0d1..d52e262 100644 --- a/src/remoteForWebdav.ts +++ b/src/remoteForWebdav.ts @@ -100,6 +100,7 @@ if (VALID_REQURL) { let r2: Response = undefined; if ([101, 103, 204, 205, 304].includes(r.status)) { // A null body status is a status that is 101, 103, 204, 205, or 304. + // https://fetch.spec.whatwg.org/#statuses // fix this: Failed to construct 'Response': Response with null body status cannot have body r2 = new Response(null, { status: r.status, From d6c39615d7f4950faf26cfef177502d03dbb66f1 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 10:40:38 +0800 Subject: [PATCH 09/23] owncloud --- docs/remote_services/webdav_owncloud/README.md | 17 +++++++++++++++++ .../webdav_owncloud/owncloud_address.png | 3 +++ .../webdav_owncloud/owncloud_files.png | 3 +++ .../webdav_owncloud/owncloud_rs_settings.png | 3 +++ 4 files changed, 26 insertions(+) create mode 100644 docs/remote_services/webdav_owncloud/README.md create mode 100644 docs/remote_services/webdav_owncloud/owncloud_address.png create mode 100644 docs/remote_services/webdav_owncloud/owncloud_files.png create mode 100644 docs/remote_services/webdav_owncloud/owncloud_rs_settings.png diff --git a/docs/remote_services/webdav_owncloud/README.md b/docs/remote_services/webdav_owncloud/README.md new file mode 100644 index 0000000..004bf00 --- /dev/null +++ b/docs/remote_services/webdav_owncloud/README.md @@ -0,0 +1,17 @@ +# ownCloud Webdav + +## Link + + + +# Steps + +1. Create an account. +2. Login. +3. In the Settings position, enable the "Show hidden files" and find out the WebDAV address. + ![](./owncloud_address.png) +4. Input the WebDAV address, account, password, **Depth Header Sent To Servers="only supports depth='1'"** in remotely-save settings. + ![](./owncloud_rs_settings.png) +5. In remotely-save setting page, click "Check Connectivity". +6. Sync! + ![](./owncloud_files.png) diff --git a/docs/remote_services/webdav_owncloud/owncloud_address.png b/docs/remote_services/webdav_owncloud/owncloud_address.png new file mode 100644 index 0000000..456ab39 --- /dev/null +++ b/docs/remote_services/webdav_owncloud/owncloud_address.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0d025b4ccf1be7fa2cc74e914e9a1a89a8d8f12a1b917bd4b26b975bf208294 +size 27796 diff --git a/docs/remote_services/webdav_owncloud/owncloud_files.png b/docs/remote_services/webdav_owncloud/owncloud_files.png new file mode 100644 index 0000000..dc136f9 --- /dev/null +++ b/docs/remote_services/webdav_owncloud/owncloud_files.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3d24d416016b2676a86166fcc35fa89f8befb7a872503b8da2be4374ef360ce +size 53503 diff --git a/docs/remote_services/webdav_owncloud/owncloud_rs_settings.png b/docs/remote_services/webdav_owncloud/owncloud_rs_settings.png new file mode 100644 index 0000000..c745930 --- /dev/null +++ b/docs/remote_services/webdav_owncloud/owncloud_rs_settings.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e8bf9a51e5d5bed66fb45fe085f37943bd90a51b33ef752d898c5b2caa71c2d +size 448797 From bbc69715e8b09d4342e5f227f27412e628b95eb5 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 11:05:49 +0800 Subject: [PATCH 10/23] add webdav links --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ca50f9a..81db44e 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,9 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a ### webdav +- Tutorials / Examples: + - [ownCloud](./docs/remote_services/webdav_owncloud/README.md) + - [InfiniCloud](./docs/remote_services/webdav_infinicloud_teracloud/README.md) - About CORS: - If you are using Obsidian desktop >= 0.13.25 or iOS >= 1.1.1, you can skip this CORS part. - If you are using Obsidian desktop < 0.13.25 or iOS < 1.1.1 or any Android version: From f66a7031b294acbcaea8a9436fe87d35e2ccb105 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 11:06:04 +0800 Subject: [PATCH 11/23] format --- docs/remote_services/webdav_owncloud/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/remote_services/webdav_owncloud/README.md b/docs/remote_services/webdav_owncloud/README.md index 004bf00..009df0d 100644 --- a/docs/remote_services/webdav_owncloud/README.md +++ b/docs/remote_services/webdav_owncloud/README.md @@ -9,9 +9,9 @@ 1. Create an account. 2. Login. 3. In the Settings position, enable the "Show hidden files" and find out the WebDAV address. - ![](./owncloud_address.png) + ![](./owncloud_address.png) 4. Input the WebDAV address, account, password, **Depth Header Sent To Servers="only supports depth='1'"** in remotely-save settings. - ![](./owncloud_rs_settings.png) + ![](./owncloud_rs_settings.png) 5. In remotely-save setting page, click "Check Connectivity". 6. Sync! - ![](./owncloud_files.png) + ![](./owncloud_files.png) From c8016b5f3088d8a955833bcbcec3ae48d0b07b7d Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 11:12:08 +0800 Subject: [PATCH 12/23] finally jianguoyun doc --- README.md | 1 + .../webdav_jianguoyun/README.md | 22 +++++++++++++++++++ .../webdav_jianguoyun.cn.png | 3 +++ .../webdav_jianguoyun_rs_settting.cn.png | 3 +++ 4 files changed, 29 insertions(+) create mode 100644 docs/remote_services/webdav_jianguoyun/README.md create mode 100644 docs/remote_services/webdav_jianguoyun/webdav_jianguoyun.cn.png create mode 100644 docs/remote_services/webdav_jianguoyun/webdav_jianguoyun_rs_settting.cn.png diff --git a/README.md b/README.md index 81db44e..e124f33 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a - Tutorials / Examples: - [ownCloud](./docs/remote_services/webdav_owncloud/README.md) - [InfiniCloud](./docs/remote_services/webdav_infinicloud_teracloud/README.md) + - [坚果云 JianGuoYun/NutStore](./docs/remote_services/webdav_jianguoyun/README.md) - About CORS: - If you are using Obsidian desktop >= 0.13.25 or iOS >= 1.1.1, you can skip this CORS part. - If you are using Obsidian desktop < 0.13.25 or iOS < 1.1.1 or any Android version: diff --git a/docs/remote_services/webdav_jianguoyun/README.md b/docs/remote_services/webdav_jianguoyun/README.md new file mode 100644 index 0000000..a9f2979 --- /dev/null +++ b/docs/remote_services/webdav_jianguoyun/README.md @@ -0,0 +1,22 @@ +# 坚果云 JianGuoYun/NutStore + +## 链接 Link + + + +## 注意!!!Attentions!!! + +坚果云有限制 api 数量等设定。本插件会产生若干查询,如果文件较多很容易触发 api 上限,从而工作不正常。这不是插件 bug,也没有办法解决。 + +JianGuoYun/NutStore has api limits. The plugin may generate many queries, and it's possible to reach the api limits if there are many files, then do not work properly. It's not a bug and there's no way to fix this situation. + +## 步骤 Steps + +1. **知悉坚果云有 api 限制,本插件可能因此工作不正常。Be aware that JianGuoYun/NutStore has api limits, and the plugin may not work properly because of this.** +2. 注册账号,登录。Register an account. +3. 去“个人信息”->“安全”,“添加应用”,从而获取了 webDAV 账号(应该是 email)和 WebDAV 密码(一串特殊的字符,不等于网站密码)。Go to "settings"->"Security", click "Add Application", then obtain the WebDAV account (email), and WebDAV password (a string different from web site password). + ![](./webdav_jianguoyun.cn.png) +4. 在 remotely-save 设置,输入网址、账号、密码、**“发送到服务器的 Depth Header”设置为“只支持 depth='1'”**。Input the WebDAV address, account, password, **Depth Header Sent To Servers="only supports depth='1'"** in remotely-save settings. + ![](./webdav_jianguoyun_rs_settting.cn.png) +5. 在 remotely-save 设置,检查连接。In remotely-save setting page, click "Check Connectivity". +6. 同步文件!Sync! diff --git a/docs/remote_services/webdav_jianguoyun/webdav_jianguoyun.cn.png b/docs/remote_services/webdav_jianguoyun/webdav_jianguoyun.cn.png new file mode 100644 index 0000000..995a396 --- /dev/null +++ b/docs/remote_services/webdav_jianguoyun/webdav_jianguoyun.cn.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd5aaab1e1ac0ea8996517c819bf5ac0d2a828483037419ba289b538957f4752 +size 515913 diff --git a/docs/remote_services/webdav_jianguoyun/webdav_jianguoyun_rs_settting.cn.png b/docs/remote_services/webdav_jianguoyun/webdav_jianguoyun_rs_settting.cn.png new file mode 100644 index 0000000..2dcaaa1 --- /dev/null +++ b/docs/remote_services/webdav_jianguoyun/webdav_jianguoyun_rs_settting.cn.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:112778176af954e16c93c582d968e7c14e5b950d64facce8593855f5fb75fbcc +size 431527 From d8f613bbb674cb5a6a7d273a8254fbab5628bed7 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Mon, 1 Jan 2024 11:57:55 +0800 Subject: [PATCH 13/23] minio --- README.md | 2 ++ docs/remote_services/s3_minio/README.md | 19 +++++++++++++++++++ .../s3_minio/minio_access_key.png | 3 +++ .../s3_minio/minio_create_bucket.png | 3 +++ .../remote_services/s3_minio/minio_region.png | 3 +++ .../s3_minio/minio_rs_settings.png | 3 +++ .../s3_minio/minio_sync_success.png | 3 +++ 7 files changed, 36 insertions(+) create mode 100644 docs/remote_services/s3_minio/README.md create mode 100644 docs/remote_services/s3_minio/minio_access_key.png create mode 100644 docs/remote_services/s3_minio/minio_create_bucket.png create mode 100644 docs/remote_services/s3_minio/minio_region.png create mode 100644 docs/remote_services/s3_minio/minio_rs_settings.png create mode 100644 docs/remote_services/s3_minio/minio_sync_success.png diff --git a/README.md b/README.md index e124f33..d06e2f6 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a ### S3 +- Tutorials / Examples: + - [MinIO](./docs/remote_services/s3_minio/README.md) - Prepare your S3 (-compatible) service information: [endpoint, region](https://docs.aws.amazon.com/general/latest/gr/s3.html), [access key id, secret access key](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-your-credentials.html), bucket name. The bucket should be empty and solely for syncing a vault. - About CORS: - If you are using Obsidian desktop >= 0.13.25 or mobile >= 1.1.1, you can skip this CORS part. diff --git a/docs/remote_services/s3_minio/README.md b/docs/remote_services/s3_minio/README.md new file mode 100644 index 0000000..b188dc3 --- /dev/null +++ b/docs/remote_services/s3_minio/README.md @@ -0,0 +1,19 @@ +# MinIO + +## Links + + + +## Steps + +1. Configure your minio instance and get an account. +2. Create an Access Key (during the creation, you will also get the auto-generated secret key). + ![](./minio_access_key.png) +3. Check or set the region. + ![](./minio_region.png) +4. Create a bucket. + ![](./minio_create_bucket.png) +5. In remotely-save setting page, input the address / bucket / access key / secret key. **Usually minio instances may need "S3 URL style"="Path Style".** Enable "Bypass CORS", because usually that's what you want. + ![](./minio_rs_settings.png) +6. Sync! + ![](./minio_sync_success.png) diff --git a/docs/remote_services/s3_minio/minio_access_key.png b/docs/remote_services/s3_minio/minio_access_key.png new file mode 100644 index 0000000..5ecfdef --- /dev/null +++ b/docs/remote_services/s3_minio/minio_access_key.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c384ec32a43fcac1e63dbc81d4fbb7fbfaffcd67d0f5a66104482a39475ad639 +size 323050 diff --git a/docs/remote_services/s3_minio/minio_create_bucket.png b/docs/remote_services/s3_minio/minio_create_bucket.png new file mode 100644 index 0000000..461fae9 --- /dev/null +++ b/docs/remote_services/s3_minio/minio_create_bucket.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:894a6a10b7f41754936d77a935b4a5a4ae722796fa5680c9c6d0dd53c3cdc1a2 +size 269705 diff --git a/docs/remote_services/s3_minio/minio_region.png b/docs/remote_services/s3_minio/minio_region.png new file mode 100644 index 0000000..80575be --- /dev/null +++ b/docs/remote_services/s3_minio/minio_region.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bfcc526281d2c6a9f1261f489603f3dd768f8b94f099a1b26649fa37c9318575 +size 315030 diff --git a/docs/remote_services/s3_minio/minio_rs_settings.png b/docs/remote_services/s3_minio/minio_rs_settings.png new file mode 100644 index 0000000..2d9af46 --- /dev/null +++ b/docs/remote_services/s3_minio/minio_rs_settings.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83615a6c2fbf7ff74679b480d29d222db8835bc067aee33a646e4b8d500c3aca +size 467575 diff --git a/docs/remote_services/s3_minio/minio_sync_success.png b/docs/remote_services/s3_minio/minio_sync_success.png new file mode 100644 index 0000000..2bd664e --- /dev/null +++ b/docs/remote_services/s3_minio/minio_sync_success.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd1bb9a6e285a1e63b545d714ca269eb714e980a5177392b967556f1f1754afe +size 147218 From 15c163e73ded3aaff0beb0f620db180216a2f63c Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Tue, 2 Jan 2024 00:08:09 +0800 Subject: [PATCH 14/23] alist --- docs/remote_services/webdav_alist/README.md | 22 +++++++++++++++++++ .../webdav_alist/alist_mount_path.en.png | 3 +++ .../webdav_alist/alist_mount_path.zh.png | 3 +++ .../webdav_alist/alist_rs_settings.en.png | 3 +++ 4 files changed, 31 insertions(+) create mode 100644 docs/remote_services/webdav_alist/README.md create mode 100644 docs/remote_services/webdav_alist/alist_mount_path.en.png create mode 100644 docs/remote_services/webdav_alist/alist_mount_path.zh.png create mode 100644 docs/remote_services/webdav_alist/alist_rs_settings.en.png diff --git a/docs/remote_services/webdav_alist/README.md b/docs/remote_services/webdav_alist/README.md new file mode 100644 index 0000000..ab0b265 --- /dev/null +++ b/docs/remote_services/webdav_alist/README.md @@ -0,0 +1,22 @@ +# AList + +## 链接 Links + +- English official website: and +- 中文官网: + +## 步骤 Steps + +1. 安装和使用 AList。获取账号名和密码。在网页上登录。Install and run AList. Get the account and password. Login using the web page. +2. 新建挂载,检查挂载路径。如图所示是 `/alisttest davpath`。Add new storage. Pay attention to the mount path. The screenshot shows the mount path as `/alisttest davpath`. + ![](./alist_mount_path.zh.png) + ![](./alist_mount_path.en.png) +3. 从而构建 webdav 网址如下,**http(s)://域名** + **端口** + **`/dav`** + **挂载路径**,其中挂载路径中假如有空格,换成 `%20`:Construct the webdav address as: **http(s)://domain** + **port** + **`/dav`** + **mount path**, and the space inside the mount path should be replaced with `%20`: + ``` + http[s]://domain:port/dav/[mountpath url encoded] + http://127.0.0.1:5244/dav/alisttest%20davpath + ``` +4. 在 remotely-save 设置,输入**带域名端口`/dav`和挂载路径的网址**、账号、密码。In remotely-save setting page, select webdav type, then input the **full address with mount path**/account/password. + ![](./alist_rs_settings.en.png) +5. 在 remotely-save 设置,检查连接。In remotely-save setting page, click "Check Connectivity". +6. 同步文件!Sync! diff --git a/docs/remote_services/webdav_alist/alist_mount_path.en.png b/docs/remote_services/webdav_alist/alist_mount_path.en.png new file mode 100644 index 0000000..0f2b89f --- /dev/null +++ b/docs/remote_services/webdav_alist/alist_mount_path.en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea05f67782b8f84518f13cf5587df719bdaa15f9e35b79f2801f91e695de6480 +size 46798 diff --git a/docs/remote_services/webdav_alist/alist_mount_path.zh.png b/docs/remote_services/webdav_alist/alist_mount_path.zh.png new file mode 100644 index 0000000..afcb55c --- /dev/null +++ b/docs/remote_services/webdav_alist/alist_mount_path.zh.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dcaaa5e64e894f0e9c8b0242b64bf4dd364c16d7314b09bc004f7ed0a0f1e0e5 +size 60853 diff --git a/docs/remote_services/webdav_alist/alist_rs_settings.en.png b/docs/remote_services/webdav_alist/alist_rs_settings.en.png new file mode 100644 index 0000000..0e5c4f8 --- /dev/null +++ b/docs/remote_services/webdav_alist/alist_rs_settings.en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b792320e2a4aaa16a17d82e80225ab35da05fd1f407fe067de72651beca088e +size 426289 From f55fad0e29be771c14e7db1ea2300851b9b7a873 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Tue, 2 Jan 2024 00:26:03 +0800 Subject: [PATCH 15/23] fix compability issue --- src/remoteForWebdav.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/remoteForWebdav.ts b/src/remoteForWebdav.ts index d52e262..04bcae1 100644 --- a/src/remoteForWebdav.ts +++ b/src/remoteForWebdav.ts @@ -48,15 +48,24 @@ if (VALID_REQURL) { if (contentType !== undefined) { contentType = contentType.toLowerCase(); } + const rspHeaders = { ...r.headers }; + for (let key in rspHeaders) { + if (rspHeaders.hasOwnProperty(key)) { + if (key === "content-disposition" || key === "Content-Disposition") { + rspHeaders[key] = encodeURIComponent(rspHeaders[key]); + } + } + } // console.log(`requesting url=${options.url}`); // console.log(`contentType=${contentType}`); + // console.log(`rspHeaders=${JSON.stringify(rspHeaders)}`) // let r2: Response = undefined; // if (contentType.includes("xml")) { // r2 = new Response(r.text, { // status: r.status, // statusText: getReasonPhrase(r.status), - // headers: r.headers, + // headers: rspHeaders, // }); // } else if ( // contentType.includes("json") || @@ -70,7 +79,7 @@ if (VALID_REQURL) { // { // status: r.status, // statusText: getReasonPhrase(r.status), - // headers: r.headers, + // headers: rspHeaders, // }); // } else if (contentType.includes("text")) { // // avoid text/json, @@ -78,7 +87,7 @@ if (VALID_REQURL) { // r2 = new Response(r.text, { // status: r.status, // statusText: getReasonPhrase(r.status), - // headers: r.headers, + // headers: rspHeaders, // }); // } else if ( // contentType.includes("octet-stream") || @@ -89,7 +98,7 @@ if (VALID_REQURL) { // r2 = new Response(r.arrayBuffer, { // status: r.status, // statusText: getReasonPhrase(r.status), - // headers: r.headers, + // headers: rspHeaders, // }); // } else { // throw Error( @@ -105,13 +114,13 @@ if (VALID_REQURL) { r2 = new Response(null, { status: r.status, statusText: getReasonPhrase(r.status), - headers: r.headers, + headers: rspHeaders, }); } else { r2 = new Response(r.arrayBuffer, { status: r.status, statusText: getReasonPhrase(r.status), - headers: r.headers, + headers: rspHeaders, }); } From ee8a3df0be270a9cc8136656dbd344fe63a6f079 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Tue, 2 Jan 2024 23:52:36 +0800 Subject: [PATCH 16/23] change method of s3 check connect --- src/remoteForS3.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/remoteForS3.ts b/src/remoteForS3.ts index e028888..ddee612 100644 --- a/src/remoteForS3.ts +++ b/src/remoteForS3.ts @@ -509,6 +509,11 @@ export const deleteFromRemote = async ( /** * Check the config of S3 by heading bucket * https://stackoverflow.com/questions/50842835 + * + * Updated on 20240102: + * Users are not always have permission of heading bucket, + * so we need to use listing objects instead... + * * @param s3Client * @param s3Config * @returns @@ -519,9 +524,15 @@ export const checkConnectivity = async ( callbackFunc?: any ) => { try { - const results = await s3Client.send( - new HeadBucketCommand({ Bucket: s3Config.s3BucketName }) - ); + // const results = await s3Client.send( + // new HeadBucketCommand({ Bucket: s3Config.s3BucketName }) + // ); + // very simplified version of listing objects + const confCmd = { + Bucket: s3Config.s3BucketName, + } as ListObjectsV2CommandInput; + const results = await s3Client.send(new ListObjectsV2Command(confCmd)); + if ( results === undefined || results.$metadata === undefined || From af71758ef79206c77880794718a6c0382be0c02d Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Wed, 3 Jan 2024 00:08:51 +0800 Subject: [PATCH 17/23] add cloudflare r2 --- README.md | 1 + .../s3_cloudflare_r2/README.md | 27 +++++++++++++++++++ .../s3_cloudflare_r2_create_api_token.png | 3 +++ .../s3_cloudflare_r2_create_bucket.png | 3 +++ .../s3_cloudflare_r2_rs_settings.png | 3 +++ 5 files changed, 37 insertions(+) create mode 100644 docs/remote_services/s3_cloudflare_r2/README.md create mode 100644 docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_create_api_token.png create mode 100644 docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_create_bucket.png create mode 100644 docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_rs_settings.png diff --git a/README.md b/README.md index d06e2f6..1f16074 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a ### S3 - Tutorials / Examples: + - [Cloudflare R2](./docs/remote_services/s3_cloudflare_r2/README.md) - [MinIO](./docs/remote_services/s3_minio/README.md) - Prepare your S3 (-compatible) service information: [endpoint, region](https://docs.aws.amazon.com/general/latest/gr/s3.html), [access key id, secret access key](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-your-credentials.html), bucket name. The bucket should be empty and solely for syncing a vault. - About CORS: diff --git a/docs/remote_services/s3_cloudflare_r2/README.md b/docs/remote_services/s3_cloudflare_r2/README.md new file mode 100644 index 0000000..77343da --- /dev/null +++ b/docs/remote_services/s3_cloudflare_r2/README.md @@ -0,0 +1,27 @@ +# Cloudflare R2 + +## Links + + + +## Steps + +1. **Be aware that it may cost you money.** +2. Create a Cloudflare account and enable R2 feature. **Credit card info might be required by Cloudflare**, though Cloudflare provides generous free tier and zero egress fee. +3. Create a bucket. + ![](./s3_cloudflare_r2_create_bucket.png) +4. Create an Access Key with "Object Read & Write" permission, and add specify to your created bucket. During the creation, you will also get the auto-generated secret key, and the endpoint address. + ![](./s3_cloudflare_r2_create_api_token.png) +5. In remotely-save setting page, input the address / bucket / access key / secret key. **Region being set to `us-east-1` is sufficient.** Enable "Bypass CORS", because usually that's what you want. + + Click "check connectivity". (If you encounter an issue and sure the info are correct, please upgrade remotely-save to **version >= 0.3.29** and try again.) + + ![](./s3_cloudflare_r2_rs_settings.png) + +6. Sync! + +## And Issue Related To "Check Connectivity" + +If you encounter an issue and sure the info are correct, please upgrade remotely-save to **version >= 0.3.29** and try again. + +Cloudflare doesn't allow `HeadBucket` for access keys with "Object Read & Write". So it may be possible that checking connectivity is not ok but actual syncing is ok. New version >= 0.3.29 of the plugin fix this problem by using `ListObjects` instead of `HeadBucket`. diff --git a/docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_create_api_token.png b/docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_create_api_token.png new file mode 100644 index 0000000..1ebfa77 --- /dev/null +++ b/docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_create_api_token.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:49a5cd07e538205ba733dc3ccb30e4e7da1290a4a80aefe08afac19fd2db2232 +size 467448 diff --git a/docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_create_bucket.png b/docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_create_bucket.png new file mode 100644 index 0000000..6507403 --- /dev/null +++ b/docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_create_bucket.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:61fc0812fe96871eed507d2f6b7bbad790ab70e95ff5fe764f8f8b2ab8ce82c2 +size 153015 diff --git a/docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_rs_settings.png b/docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_rs_settings.png new file mode 100644 index 0000000..2452ad9 --- /dev/null +++ b/docs/remote_services/s3_cloudflare_r2/s3_cloudflare_r2_rs_settings.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:02f9c0fea36679e54c8c3fac979bc41d15ae4f7992b269bc2b67255059af1d2f +size 579889 From 81c79ab848f33f3ba3630f7fe783e4844f92478b Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Wed, 3 Jan 2024 23:25:08 +0800 Subject: [PATCH 18/23] minio custom port --- docs/remote_services/s3_minio/README.md | 8 ++++++++ docs/remote_services/s3_minio/minio_custom_port.png | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 docs/remote_services/s3_minio/minio_custom_port.png diff --git a/docs/remote_services/s3_minio/README.md b/docs/remote_services/s3_minio/README.md index b188dc3..cdc72d7 100644 --- a/docs/remote_services/s3_minio/README.md +++ b/docs/remote_services/s3_minio/README.md @@ -17,3 +17,11 @@ ![](./minio_rs_settings.png) 6. Sync! ![](./minio_sync_success.png) + +## Ports In Address + +Just type in the full address with `http(s)://` and `:port` in remotely-save settings, for example `http://192.168.31.198:9000`. + +It's verified that everything is ok. + +![](./minio_custom_port.png) diff --git a/docs/remote_services/s3_minio/minio_custom_port.png b/docs/remote_services/s3_minio/minio_custom_port.png new file mode 100644 index 0000000..37b616d --- /dev/null +++ b/docs/remote_services/s3_minio/minio_custom_port.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b25c1209875ad781a29d3ac1cde5bd9c2137622e3919987c4d4e5f77dc8e3ec7 +size 68997 From 79a0b9f44de20cb8e4a43e1f6e728e84f32d2e4e Mon Sep 17 00:00:00 2001 From: ras0q Date: Fri, 29 Dec 2023 21:47:24 +0900 Subject: [PATCH 19/23] add ignorePaths setting --- src/baseTypes.ts | 1 + src/langs | 2 +- src/main.ts | 2 ++ src/settings.ts | 12 ++++++++++++ src/sync.ts | 22 +++++++++++++++++----- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/baseTypes.ts b/src/baseTypes.ts index 7d540d1..318f750 100644 --- a/src/baseTypes.ts +++ b/src/baseTypes.ts @@ -86,6 +86,7 @@ export interface RemotelySavePluginSettings { lang?: LangTypeAndAuto; logToDB?: boolean; skipSizeLargerThan?: number; + ignorePaths?: string[]; /** * @deprecated diff --git a/src/langs b/src/langs index 42eab5d..0b961f4 160000 --- a/src/langs +++ b/src/langs @@ -1 +1 @@ -Subproject commit 42eab5d544961f4c7830c63ba9559375437340c0 +Subproject commit 0b961f4865d11e3c78d74776b8d0eb2d642aa505 diff --git a/src/main.ts b/src/main.ts index bc9de28..7b60f08 100644 --- a/src/main.ts +++ b/src/main.ts @@ -85,6 +85,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = { lang: "auto", logToDB: false, skipSizeLargerThan: -1, + ignorePaths: [".obsidian/workspace.json", ".obsidian/workspace-mobile.json", ".obsidian/community-plugins.json"], }; interface OAuth2Info { @@ -296,6 +297,7 @@ export default class RemotelySavePlugin extends Plugin { this.app.vault.configDir, this.settings.syncUnderscoreItems, this.settings.skipSizeLargerThan, + this.settings.ignorePaths, this.settings.password ); log.info(plan.mixedStates); // for debugging diff --git a/src/settings.ts b/src/settings.ts index e851c9e..8047eb4 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1596,6 +1596,18 @@ export class RemotelySaveSettingTab extends PluginSettingTab { }); }); + new Setting(basicDiv) + .setName(t("settings_ignorepaths")) + .setDesc(t("settings_ignorepaths_desc")) + .addTextArea((textArea) => { + textArea + .setValue(`${this.plugin.settings.ignorePaths.join("\n")}`) + .onChange(async (value) => { + this.plugin.settings.ignorePaths = value.split("\n"); + await this.plugin.saveSettings(); + }); + }); + ////////////////////////////////////////////////// // below for advanced settings ////////////////////////////////////////////////// diff --git a/src/sync.ts b/src/sync.ts index 61e6fca..f00b200 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -293,8 +293,12 @@ const isSkipItem = ( key: string, syncConfigDir: boolean, syncUnderscoreItems: boolean, - configDir: string + configDir: string, + ignorePaths: string[] ) => { + if (ignorePaths.includes(key)) { + return true; + } if (syncConfigDir && isInsideObsFolder(key, configDir)) { return false; } @@ -315,6 +319,7 @@ const ensembleMixedStates = async ( syncConfigDir: boolean, configDir: string, syncUnderscoreItems: boolean, + ignorePaths: string[], password: string ) => { const results = {} as Record; @@ -322,7 +327,7 @@ const ensembleMixedStates = async ( for (const r of remoteStates) { const key = r.key; - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) { + if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { continue; } results[key] = r; @@ -361,7 +366,7 @@ const ensembleMixedStates = async ( throw Error(`unexpected ${entry}`); } - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) { + if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { continue; } @@ -395,6 +400,10 @@ const ensembleMixedStates = async ( password === "" ? undefined : getSizeFromOrigToEnc(entry.size), }; + if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + continue; + } + if (results.hasOwnProperty(key)) { results[key].key = r.key; results[key].existLocal = r.existLocal; @@ -417,7 +426,7 @@ const ensembleMixedStates = async ( deltimeRemoteFmt: unixTimeToStr(entry.actionWhen), } as FileOrFolderMixedState; - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) { + if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { continue; } @@ -445,7 +454,7 @@ const ensembleMixedStates = async ( throw Error(`unexpected ${entry}`); } - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) { + if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { continue; } @@ -967,6 +976,7 @@ export const getSyncPlan = async ( configDir: string, syncUnderscoreItems: boolean, skipSizeLargerThan: number, + ignorePaths: string[], password: string = "" ) => { const mixedStates = await ensembleMixedStates( @@ -978,8 +988,10 @@ export const getSyncPlan = async ( syncConfigDir, configDir, syncUnderscoreItems, + ignorePaths, password ); + console.table(mixedStates) const sortedKeys = Object.keys(mixedStates).sort( (k1, k2) => k2.length - k1.length From d7e034f070fe34be037f37d25400a2dc2578c9a2 Mon Sep 17 00:00:00 2001 From: ras0q Date: Fri, 29 Dec 2023 22:55:59 +0900 Subject: [PATCH 20/23] remove debug console.table --- src/sync.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sync.ts b/src/sync.ts index f00b200..f35a9b0 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -991,7 +991,6 @@ export const getSyncPlan = async ( ignorePaths, password ); - console.table(mixedStates) const sortedKeys = Object.keys(mixedStates).sort( (k1, k2) => k2.length - k1.length From 9e4d3826fdfb6cb1ce57ba80c8608b4f3b2ca46a Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Wed, 3 Jan 2024 23:37:08 +0800 Subject: [PATCH 21/23] add langs for ignorepath --- src/langs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/langs b/src/langs index 0b961f4..c75336a 160000 --- a/src/langs +++ b/src/langs @@ -1 +1 @@ -Subproject commit 0b961f4865d11e3c78d74776b8d0eb2d642aa505 +Subproject commit c75336a2a52fcf00147eea01ca767872dff2d0b4 From 6a651b844f4ebaa09541d673260fc3a195f03bb9 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Thu, 4 Jan 2024 00:26:02 +0800 Subject: [PATCH 22/23] ignore paths by regexgit add . --- README.md | 1 + src/main.ts | 5 ++++- src/settings.ts | 7 +++++- src/sync.ts | 59 +++++++++++++++++++++++++++++++++++++++++++------ styles.css | 4 ++++ 5 files changed, 67 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1f16074..b1160d8 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ This is yet another unofficial sync plugin for Obsidian. If you like it or find - **[End-to-end encryption](./docs/encryption.md) supported.** Files would be encrypted using openssl format before being sent to the cloud **if** user specify a password. - **Scheduled auto sync supported.** You can also manually trigger the sync using sidebar ribbon, or using the command from the command palette (or even bind the hot key combination to the command then press the hot key combination). - **[Minimal Intrusive](./docs/minimal_intrusive_design.md).** +- **Skip Large files and skip paths by custom regex conditions! - **Fully open source under [Apache-2.0 License](./LICENSE).** - **[Sync Algorithm open](./docs/sync_algorithm_v2.md) for discussion.** diff --git a/src/main.ts b/src/main.ts index 7b60f08..b8ec457 100644 --- a/src/main.ts +++ b/src/main.ts @@ -85,7 +85,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = { lang: "auto", logToDB: false, skipSizeLargerThan: -1, - ignorePaths: [".obsidian/workspace.json", ".obsidian/workspace-mobile.json", ".obsidian/community-plugins.json"], + ignorePaths: [], }; interface OAuth2Info { @@ -795,6 +795,9 @@ export default class RemotelySavePlugin extends Plugin { if (this.settings.s3.forcePathStyle === undefined) { this.settings.s3.forcePathStyle = false; } + if (this.settings.ignorePaths === undefined) { + this.settings.ignorePaths = []; + } } async checkIfPresetRulesFollowed() { diff --git a/src/settings.ts b/src/settings.ts index 8047eb4..13c8ed4 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1599,13 +1599,18 @@ export class RemotelySaveSettingTab extends PluginSettingTab { new Setting(basicDiv) .setName(t("settings_ignorepaths")) .setDesc(t("settings_ignorepaths_desc")) + .setClass("ignorepaths-settings") + .addTextArea((textArea) => { textArea .setValue(`${this.plugin.settings.ignorePaths.join("\n")}`) .onChange(async (value) => { - this.plugin.settings.ignorePaths = value.split("\n"); + this.plugin.settings.ignorePaths = value.trim().split("\n"); await this.plugin.saveSettings(); }); + textArea.inputEl.rows = 10; + + textArea.inputEl.addClass("ignorepaths-textarea"); }); ////////////////////////////////////////////////// diff --git a/src/sync.ts b/src/sync.ts index f35a9b0..5fdd1d6 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -7,6 +7,7 @@ import { } from "obsidian"; import AggregateError from "aggregate-error"; import PQueue from "p-queue"; +import XRegExp from "xregexp"; import type { RemoteItem, SyncTriggerSourceType, @@ -296,8 +297,12 @@ const isSkipItem = ( configDir: string, ignorePaths: string[] ) => { - if (ignorePaths.includes(key)) { - return true; + if (ignorePaths !== undefined && ignorePaths.length > 0) { + for (const r of ignorePaths) { + if (XRegExp(r, "A").test(key)) { + return true; + } + } } if (syncConfigDir && isInsideObsFolder(key, configDir)) { return false; @@ -327,7 +332,15 @@ const ensembleMixedStates = async ( for (const r of remoteStates) { const key = r.key; - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + if ( + isSkipItem( + key, + syncConfigDir, + syncUnderscoreItems, + configDir, + ignorePaths + ) + ) { continue; } results[key] = r; @@ -366,7 +379,15 @@ const ensembleMixedStates = async ( throw Error(`unexpected ${entry}`); } - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + if ( + isSkipItem( + key, + syncConfigDir, + syncUnderscoreItems, + configDir, + ignorePaths + ) + ) { continue; } @@ -400,7 +421,15 @@ const ensembleMixedStates = async ( password === "" ? undefined : getSizeFromOrigToEnc(entry.size), }; - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + if ( + isSkipItem( + key, + syncConfigDir, + syncUnderscoreItems, + configDir, + ignorePaths + ) + ) { continue; } @@ -426,7 +455,15 @@ const ensembleMixedStates = async ( deltimeRemoteFmt: unixTimeToStr(entry.actionWhen), } as FileOrFolderMixedState; - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + if ( + isSkipItem( + key, + syncConfigDir, + syncUnderscoreItems, + configDir, + ignorePaths + ) + ) { continue; } @@ -454,7 +491,15 @@ const ensembleMixedStates = async ( throw Error(`unexpected ${entry}`); } - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + if ( + isSkipItem( + key, + syncConfigDir, + syncUnderscoreItems, + configDir, + ignorePaths + ) + ) { continue; } diff --git a/styles.css b/styles.css index 75f5978..940a670 100644 --- a/styles.css +++ b/styles.css @@ -61,3 +61,7 @@ width: 350px; height: 350px; } + +.ignorepaths-textarea { + font-family: monospace; +} From d38ac34362c2676ec5e307598eb87d2c327f0a5d Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Thu, 4 Jan 2024 00:26:37 +0800 Subject: [PATCH 23/23] 0.3.29 --- manifest-beta.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest-beta.json b/manifest-beta.json index a3d1a1a..7fd52ae 100644 --- a/manifest-beta.json +++ b/manifest-beta.json @@ -1,7 +1,7 @@ { "id": "remotely-save", "name": "Remotely Save", - "version": "0.3.28", + "version": "0.3.29", "minAppVersion": "0.13.21", "description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.", "author": "fyears",