Compare commits

...
43 Commits
Author SHA1 Message Date
fyears ee224bf4f2 new delay function to avoid the import problem
Release A New Version / build (16.x) (push) Failing after 36s
2024-04-01 00:13:33 +08:00
fyears f1bd0b1ce6 bump to 0.4.13 2024-03-31 23:52:07 +08:00
fyears 300ed213af improvement of statusbar, finally fully working on iphone 2024-03-31 23:50:42 +08:00
fyears 4be67ce491 minor change to synconsave 2024-03-31 19:07:47 +08:00
Vijayasanthamandfyears 98107ba4ea Improvement of sync_on_save (#502)
* Improve sync_on_save

* fix typo

---------

Co-authored-by: fyears <1142836+fyears@users.noreply.github.com>
2024-03-31 00:07:07 +08:00
fyears b674dd0f10 bump to 0.4.12
Release A New Version / build (16.x) (push) Failing after 35s
2024-03-30 22:01:59 +08:00
fyears 7930509e2a fix sync records 2024-03-30 21:44:09 +08:00
fyears 1c918d82da allowing # in onedrive 2024-03-30 15:39:35 +08:00
fyears 593fd7471b fix s3 detect http 2024-03-30 15:18:14 +08:00
Hamza Megahed 222f386586 Update s3_user_policy.md (#570)
fix AWS S3 user's policy configuration issue https://github.com/remotely-save/remotely-save/issues/564
2024-03-30 14:55:06 +08:00
fyears dcd02457cb fix folder segments of dropbox 2024-03-30 14:53:23 +08:00
fyears 791c0e8df6 very basic synthesizedFolder 2024-03-30 03:30:18 +08:00
fyears c37bf6aedd bump to 0.4.11
Release A New Version / build (16.x) (push) Failing after 50s
2024-03-27 00:44:57 +08:00
fyears bed28d9f0b fix too large operation 2024-03-27 00:44:16 +08:00
fyears 02e03681f7 fix encrypt method 2024-03-27 00:33:27 +08:00
fyears 62452341a3 correctly remove empty folders 2024-03-26 23:57:00 +08:00
fyears bff2f6a642 clean protection for 100% 2024-03-26 23:39:53 +08:00
fyears 833fdee69e finnally we have a big version 0.4.10
Release A New Version / build (16.x) (push) Failing after 47s
2024-03-25 01:19:11 +08:00
fyears 936fce76a1 hack for status bar 2024-03-25 01:18:34 +08:00
fyears e2e8265d43 add https checking 2024-03-25 00:43:13 +08:00
fyears e228250613 round second to dropbox 2024-03-25 00:31:21 +08:00
fyears dde4327249 bump to beta 0.4.9
Release A New Version / build (16.x) (push) Failing after 44s
2024-03-25 00:22:30 +08:00
fyears e283efc8f7 new encryption 2024-03-25 00:21:56 +08:00
fyears 6825241071 half way of encryption refactor 2024-03-23 16:38:58 +08:00
fyears 98380b6c92 remove loglevel and webdav-fs 2024-03-23 11:37:39 +08:00
fyears d3eb2166aa bump to 0.4.8
Release A New Version / build (16.x) (push) Failing after 36s
2024-03-21 00:08:07 +08:00
fyears 7ecce29940 fix webdav encodeURI 2024-03-21 00:07:32 +08:00
fyears 581c6237cc bump to 0.4.7
Release A New Version / build (16.x) (push) Failing after 32s
2024-03-20 03:44:34 +08:00
fyears 257c995090 fix a mysterious bug for webdav 2024-03-20 03:10:57 +08:00
fyears fd095a9093 more debug for webdav and bump to 0.4.6
Release A New Version / build (16.x) (push) Failing after 39s
2024-03-20 02:01:51 +08:00
fyears acc9233611 bump to beta 0.4.5
Release A New Version / build (16.x) (push) Failing after 41s
2024-03-20 01:42:33 +08:00
fyears 4456db11cf try to make webdav header happy 2024-03-20 01:42:02 +08:00
fyears 54449dd207 add doc for onedrive 2024-03-19 01:29:10 +08:00
fyears 822941f1c3 fix statusbar 2024-03-18 23:59:52 +08:00
fyears 62b176d709 bump to beta 0.4.4
Release A New Version / build (16.x) (push) Failing after 41s
2024-03-18 02:21:25 +08:00
fyears 9553bff44a mobile status bar 2024-03-18 02:20:56 +08:00
fyears ede1f4e1bc obfuscateSettingFile 2024-03-18 01:45:33 +08:00
fyears 97f4c0c427 fix grammar 2024-03-18 01:30:47 +08:00
fyears 94a56dabdd add debug log 2024-03-18 01:30:29 +08:00
fyears 4947eb91a2 bump to beta 0.4.3
Release A New Version / build (16.x) (push) Failing after 44s
2024-03-18 00:49:15 +08:00
fyears 2d12c9977d fix param 2024-03-18 00:48:53 +08:00
fyears f2794ac539 bump to beta 0.4.2
Release A New Version / build (16.x) (push) Failing after 40s
2024-03-18 00:46:02 +08:00
fyears 519fd27dd5 fix s3 time 2024-03-18 00:45:28 +08:00
35 changed files with 1815 additions and 420 deletions
+2 -1
View File
@@ -23,7 +23,7 @@ This is yet another unofficial sync plugin for Obsidian. If you like it or find
- Webdav - Webdav
- [Here](./docs/services_connectable_or_not.md) shows more connectable (or not-connectable) services in details. - [Here](./docs/services_connectable_or_not.md) shows more connectable (or not-connectable) services in details.
- **Obsidian Mobile supported.** Vaults can be synced across mobile and desktop devices with the cloud service as the "broker". - **Obsidian Mobile supported.** Vaults can be synced across mobile and desktop devices with the cloud service as the "broker".
- **[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. - **[End-to-end encryption](./docs/encryption/README.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). - **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).** - **[Minimal Intrusive](./docs/minimal_intrusive_design.md).**
- **Skip Large files** and **skip paths** by custom regex conditions! - **Skip Large files** and **skip paths** by custom regex conditions!
@@ -92,6 +92,7 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a
- If you decide to authorize this plugin to connect to OneDrive, please go to plugin's settings, and choose OneDrive then follow the instructions. - If you decide to authorize this plugin to connect to OneDrive, please go to plugin's settings, and choose OneDrive then follow the instructions.
- Password-based end-to-end encryption is also supported. But please be aware that **the vault name itself is not encrypted**. - Password-based end-to-end encryption is also supported. But please be aware that **the vault name itself is not encrypted**.
- If you want to sync the files across multiple devices, **your vault name should be the same** while using default settings. - If you want to sync the files across multiple devices, **your vault name should be the same** while using default settings.
- You might also want to checkout [faq for OneDrive](./docs/remote_services/onedrive/README.md).
### webdav ### webdav
+8
View File
@@ -0,0 +1,8 @@
# Encryption
Currently (March 2024), Remotely Save supports two end to end encryption format:
1. [RClone Crypt](./rclone.md) format, which is the recommend way now.
2. [OpenSSL enc](./openssl.md) format
Here is also the [comparation](./comparation.md).
+23
View File
@@ -0,0 +1,23 @@
# Comparation Between Encryption Formats
## Warning
**ALWAYS BACKUP YOUR VAULT MANUALLY!!!**
If you switch between RClone Crypt format and OpenSSL enc format, you have to delete the cloud vault files **manually** and **fully**, so that the plugin can re-sync (i.e. re-upload) the newly encrypted versions to the cloud.
## The feature table
| | RClone Crypt | OpenSSL enc | comments |
| ------------------------ | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| key generation | scrypt with fixed salt | PBKDF2 with dynamic salt | scrypt is better than PBKDF2 from the algorithm aspect. But RClone uses fixed salt by default. Also the parameters might affect the result. |
| content encryption | XSalsa20Poly1305 on chunks | AES-256-CBC | XSalsa20Poly1305 is way better than AES-256-CBC. And encryption by chunks should require less resources. |
| file name encryption | EME on each segment of the path | AES-256-CBC on the whole path | RClone has the benefit as well as pitfall that the path structure is preserved. Maybe it's more of a design decision difference? No comment on EME and AES-256-CBC. |
| viewing decrypted result | RClone has command that can mount the encrypted vault as if the encryption is transparent. | No convenient way except writing some scripts we are aware of. | RClone is way more convenient. |
## Some notes
1. Anyway, security is a hard problem. The author of Remotely Save doesn't have sufficient knowledge to "judge" which one is the better format. **Use them at your own risk.**
2. Currently the RClone Crypt format is recommended by default in Remotely Save. Just because of the taste from the Remotely Save author, who likes RClone.
3. **Always use a long password.**
4. Both algorithms are selected deliberately to **be compatible with some well-known third-party tools** (instead of some home-made methods) and **have many tests to ensure the correctness**.
@@ -1,10 +1,22 @@
# Encryption # OpenSSL enc format
If a password is set, the files are encrypted before being sent to the cloud. If a password is set, the files are encrypted before being sent to the cloud.
The encryption algorithm is delibrately designed to be aligned with openssl format. ## Warning
1. The encryption algorithm is implemented using web-crypto. **ALWAYS BACKUP YOUR VAULT MANUALLY!!!**
If you switch between RClone Crypt format and OpenSSL enc format, you have to delete the cloud vault files **manually** and **fully**, so that the plugin can re-sync (i.e. re-upload) the newly encrypted versions to the cloud.
## Comparation between encryption formats
See the doc [Comparation](./comparation.md).
## Interoperability with official OpenSSL
This encryption algorithm is delibrately designed to be aligned with openssl format.
1. The encryption algorithm is implemented using web-crypto. Using AES-256-CBC.
2. The file content is encrypted using openssl format. Assuming a file named `sometext.txt`, a password `somepassword`, then the encryption is equivalent to the following command: 2. The file content is encrypted using openssl format. Assuming a file named `sometext.txt`, a password `somepassword`, then the encryption is equivalent to the following command:
```bash ```bash
+46
View File
@@ -0,0 +1,46 @@
# RClone Crypt format
The encryption is compatible with RClone Crypt with **base64** name encryption format.
It's developed based on another js project by the same author of Remotely Save: [`@fyears/rclone-crypt`](https://github.com/fyears/rclone-crypt), which is NOT an official library from RClone, and is NOT affiliated with RClone.
Reasonable tests are also ported from official RClone code, to ensure the compatibility and correctness of the encryption.
## Warning
**ALWAYS BACKUP YOUR VAULT MANUALLY!!!**
If you switch between RClone Crypt format and OpenSSL enc format, you have to delete the cloud vault files **manually** and **fully**, so that the plugin can re-sync (i.e. re-upload) the newly encrypted versions to the cloud.
## Comparation between encryption formats
See the doc [Comparation](./comparation.md).
## Interoperability with official RClone
Please pay attention that the plugin uses **base64** of encrypted file names, while official RClone by default uses **base32** file names. The intention is purely for potentially support longer file names.
You could set up the RClone profile by calling `rclone config`. You need to create two profiles, one for your original connection and the other for RClone Crypt.
Finally, a working config file should like this:
```ini
[webdav1]
type = webdav
url = https://example.com/sharefolder1/subfolder1 # the same as the web address in Remotely Save settings.
vendor = other
user = <some webdav username>
pass = <some webdav password, obfuscated>
[webdav1crypt]
type = crypt
remote = nas1test:vaultname # the same as your "Remote Base Directory" (usually the vault name) in Remotely Save settings
password = <some encryption password, obfuscated>
filename_encoding = base64 # don't forget this!!!
```
You can use the `mount` command to view and see the files in file explorer! On Windows, the command should like this (the remote vault is mounted to drive `X:`):
```bash
rclone mount webdav1crypt: X: --network-mode
```
+23
View File
@@ -0,0 +1,23 @@
# OneDrive
- **This plugin is NOT an official Microsoft / OneDrive product.** The plugin just uses Microsoft's [OneDrive's public API](https://docs.microsoft.com/en-us/onedrive/developer/rest-api).
- After the authorization, the plugin can read your name and email, and read and write files in your OneDrive's `/Apps/remotely-save` folder.
- If you decide to authorize this plugin to connect to OneDrive, please go to plugin's settings, and choose OneDrive then follow the instructions.
- Password-based end-to-end encryption is also supported. But please be aware that **the vault name itself is not encrypted**.
- If you want to sync the files across multiple devices, **your vault name should be the same** while using default settings.
## FAQ
### How about OneDrive for Business?
This plugin only works for "OneDrive for personal", and not works for "OneDrive for Business" (yet). See [#11](https://github.com/fyears/remotely-save/issues/11) to further details.
### I cannot find `/Apps/remotely-save` folder
Mystically some users report that their OneDrive generate `/Application/Graph` instead of `/Apps/remotely-save`. See [#517](https://github.com/remotely-save/remotely-save/issues/517).
The solution is simple:
1. Backup your vault manually.
2. Go to onedrive website (<https://onedrive.live.com/>), and rename `/Application/Graph` to `/Application/remotely-save` (right click on the folder and you will see rename option)
3. Come back to Obsidian and try to sync!
@@ -33,6 +33,7 @@ Using the principle of least privilege is crucial for security when allowing a t
"Effect": "Allow", "Effect": "Allow",
"Action": [ "Action": [
"s3:HeadObject", "s3:HeadObject",
"s3:ListBucket",
"s3:PutObject", "s3:PutObject",
"s3:CopyObject", "s3:CopyObject",
"s3:UploadPart", "s3:UploadPart",
@@ -48,7 +49,10 @@ Using the principle of least privilege is crucial for security when allowing a t
"s3:DeleteObject", "s3:DeleteObject",
"s3:DeleteObjects" "s3:DeleteObjects"
], ],
"Resource": "arn:aws:s3:::my-bucket/*" "Resource": [
"arn:aws:s3:::my-bucket",
"arn:aws:s3:::my-bucket/*"
]
} }
] ]
} }
+1
View File
@@ -11,3 +11,4 @@
- [x] sync direction: incremental pull only - [x] sync direction: incremental pull only
- [x] sync protection: warning based on the threshold - [x] sync protection: warning based on the threshold
- [ ] partial sync: better sync on save - [ ] partial sync: better sync on save
- [x] encrpytion: new encryption method, see [this](../../encryption/)
+2
View File
@@ -1,6 +1,7 @@
import dotenv from "dotenv/config"; import dotenv from "dotenv/config";
import esbuild from "esbuild"; import esbuild from "esbuild";
import process from "process"; import process from "process";
import inlineWorkerPlugin from "esbuild-plugin-inline-worker";
// import builtins from 'builtin-modules' // import builtins from 'builtin-modules'
const banner = `/* const banner = `/*
@@ -54,6 +55,7 @@ esbuild
"process.env.NODE_DEBUG": `undefined`, // ugly fix "process.env.NODE_DEBUG": `undefined`, // ugly fix
"process.env.DEBUG": `undefined`, // ugly fix "process.env.DEBUG": `undefined`, // ugly fix
}, },
plugins: [inlineWorkerPlugin()],
}) })
.then((context) => { .then((context) => {
if (process.argv.includes("--watch")) { if (process.argv.includes("--watch")) {
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"id": "remotely-save", "id": "remotely-save",
"name": "Remotely Save", "name": "Remotely Save",
"version": "0.4.1", "version": "0.4.13",
"minAppVersion": "0.13.21", "minAppVersion": "0.13.21",
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.", "description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
"author": "fyears", "author": "fyears",
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"id": "remotely-save", "id": "remotely-save",
"name": "Remotely Save", "name": "Remotely Save",
"version": "0.3.40", "version": "0.4.13",
"minAppVersion": "0.13.21", "minAppVersion": "0.13.21",
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.", "description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
"author": "fyears", "author": "fyears",
+8 -7
View File
@@ -1,6 +1,6 @@
{ {
"name": "remotely-save", "name": "remotely-save",
"version": "0.4.1", "version": "0.4.13",
"description": "This is yet another sync plugin for Obsidian app.", "description": "This is yet another sync plugin for Obsidian app.",
"scripts": { "scripts": {
"dev2": "node esbuild.config.mjs --watch", "dev2": "node esbuild.config.mjs --watch",
@@ -24,7 +24,7 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"devDependencies": { "devDependencies": {
"@microsoft/microsoft-graph-types": "^2.40.0", "@microsoft/microsoft-graph-types": "^2.40.0",
"@types/chai": "^4.3.11", "@types/chai": "^4.3.14",
"@types/chai-as-promised": "^7.1.8", "@types/chai-as-promised": "^7.1.8",
"@types/jsdom": "^21.1.6", "@types/jsdom": "^21.1.6",
"@types/lodash": "^4.14.202", "@types/lodash": "^4.14.202",
@@ -34,13 +34,14 @@
"@types/node": "^20.10.4", "@types/node": "^20.10.4",
"@types/qrcode": "^1.5.5", "@types/qrcode": "^1.5.5",
"builtin-modules": "^3.3.0", "builtin-modules": "^3.3.0",
"chai": "^4.3.10", "chai": "^4.4.1",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"dotenv": "^16.3.1", "dotenv": "^16.3.1",
"esbuild": "^0.19.9", "esbuild": "^0.19.9",
"esbuild-plugin-inline-worker": "^0.1.1",
"jsdom": "^23.0.1", "jsdom": "^23.0.1",
"mocha": "^10.2.0", "mocha": "^10.4.0",
"npm-check-updates": "^16.14.12", "npm-check-updates": "^16.14.12",
"obsidian": "^1.4.11", "obsidian": "^1.4.11",
"prettier": "^3.1.1", "prettier": "^3.1.1",
@@ -50,7 +51,8 @@
"typescript": "^5.3.3", "typescript": "^5.3.3",
"webdav-server": "^2.6.2", "webdav-server": "^2.6.2",
"webpack": "^5.89.0", "webpack": "^5.89.0",
"webpack-cli": "^5.1.4" "webpack-cli": "^5.1.4",
"worker-loader": "^3.0.8"
}, },
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.474.0", "@aws-sdk/client-s3": "^3.474.0",
@@ -58,6 +60,7 @@
"@aws-sdk/signature-v4-crt": "^3.474.0", "@aws-sdk/signature-v4-crt": "^3.474.0",
"@aws-sdk/types": "^3.468.0", "@aws-sdk/types": "^3.468.0",
"@azure/msal-node": "^2.6.0", "@azure/msal-node": "^2.6.0",
"@fyears/rclone-crypt": "^0.0.7",
"@fyears/tsqueue": "^1.0.1", "@fyears/tsqueue": "^1.0.1",
"@microsoft/microsoft-graph-client": "^3.0.7", "@microsoft/microsoft-graph-client": "^3.0.7",
"@smithy/fetch-http-handler": "^2.3.1", "@smithy/fetch-http-handler": "^2.3.1",
@@ -75,7 +78,6 @@
"http-status-codes": "^2.3.0", "http-status-codes": "^2.3.0",
"localforage": "^1.10.0", "localforage": "^1.10.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"loglevel": "^1.8.1",
"lucide": "^0.298.0", "lucide": "^0.298.0",
"mime-types": "^2.1.35", "mime-types": "^2.1.35",
"mustache": "^4.2.0", "mustache": "^4.2.0",
@@ -90,7 +92,6 @@
"url": "^0.11.3", "url": "^0.11.3",
"util": "^0.12.5", "util": "^0.12.5",
"webdav": "^5.3.1", "webdav": "^5.3.1",
"webdav-fs": "^4.0.1",
"xregexp": "^5.1.1" "xregexp": "^5.1.1"
} }
} }
+18 -3
View File
@@ -88,6 +88,8 @@ export type SyncDirectionType =
| "incremental_pull_only" | "incremental_pull_only"
| "incremental_push_only"; | "incremental_push_only";
export type CipherMethodType = "rclone-base64" | "openssl-base64" | "unknown";
export interface RemotelySavePluginSettings { export interface RemotelySavePluginSettings {
s3: S3Config; s3: S3Config;
webdav: WebdavConfig; webdav: WebdavConfig;
@@ -115,6 +117,12 @@ export interface RemotelySavePluginSettings {
protectModifyPercentage?: number; protectModifyPercentage?: number;
syncDirection?: SyncDirectionType; syncDirection?: SyncDirectionType;
obfuscateSettingFile?: boolean;
enableMobileStatusBar?: boolean;
encryptionMethod?: CipherMethodType;
/** /**
* @deprecated * @deprecated
*/ */
@@ -157,6 +165,8 @@ export type DecisionTypeForMixedEntity =
| "remote_is_modified_then_pull" | "remote_is_modified_then_pull"
| "local_is_created_then_push" | "local_is_created_then_push"
| "remote_is_created_then_pull" | "remote_is_created_then_pull"
| "local_is_created_too_large_then_do_nothing"
| "remote_is_created_too_large_then_do_nothing"
| "local_is_deleted_thus_also_delete_remote" | "local_is_deleted_thus_also_delete_remote"
| "remote_is_deleted_thus_also_delete_local" | "remote_is_deleted_thus_also_delete_local"
| "conflict_created_then_keep_local" | "conflict_created_then_keep_local"
@@ -171,7 +181,9 @@ export type DecisionTypeForMixedEntity =
| "folder_existed_remote_then_also_create_local" | "folder_existed_remote_then_also_create_local"
| "folder_to_be_created" | "folder_to_be_created"
| "folder_to_skip" | "folder_to_skip"
| "folder_to_be_deleted"; | "folder_to_be_deleted_on_both"
| "folder_to_be_deleted_on_remote"
| "folder_to_be_deleted_on_local";
/** /**
* uniform representation * uniform representation
@@ -192,6 +204,7 @@ export interface Entity {
sizeRaw: number; sizeRaw: number;
hash?: string; hash?: string;
etag?: string; etag?: string;
synthesizedFolder?: boolean;
} }
export interface UploadedType { export interface UploadedType {
@@ -211,6 +224,8 @@ export interface MixedEntity {
decisionBranch?: number; decisionBranch?: number;
decision?: DecisionTypeForMixedEntity; decision?: DecisionTypeForMixedEntity;
conflictAction?: ConflictActionType; conflictAction?: ConflictActionType;
sideNotes?: any;
} }
/** /**
@@ -257,9 +272,9 @@ export const DEFAULT_LOG_HISTORY_FILE_PREFIX = "log_hist_exported_on_";
export type SyncTriggerSourceType = export type SyncTriggerSourceType =
| "manual" | "manual"
| "auto"
| "dry" | "dry"
| "autoOnceInit" | "auto"
| "auto_once_init"
| "auto_sync_on_save"; | "auto_sync_on_save";
export const REMOTELY_SAVE_VERSION_2022 = "0.3.25"; export const REMOTELY_SAVE_VERSION_2022 = "0.3.25";
+251
View File
@@ -0,0 +1,251 @@
import {
Cipher as CipherRCloneCryptPack,
encryptedSize,
} from "@fyears/rclone-crypt";
// @ts-ignore
import EncryptWorker from "./encryptRClone.worker";
interface RecvMsg {
status: "ok" | "error";
outputName?: string;
outputContent?: ArrayBuffer;
error?: any;
}
export const getSizeFromOrigToEnc = encryptedSize;
export class CipherRclone {
readonly password: string;
readonly cipher: CipherRCloneCryptPack;
readonly workers: Worker[];
init: boolean;
workerIdx: number;
constructor(password: string, workerNum: number) {
this.password = password;
this.init = false;
this.workerIdx = 0;
// console.debug("begin creating CipherRCloneCryptPack");
this.cipher = new CipherRCloneCryptPack("base64");
// console.debug("finish creating CipherRCloneCryptPack");
// console.debug("begin creating EncryptWorker");
this.workers = [];
for (let i = 0; i < workerNum; ++i) {
this.workers.push(new (EncryptWorker as any)() as Worker);
}
// console.debug("finish creating EncryptWorker");
}
closeResources() {
for (let i = 0; i < this.workers.length; ++i) {
this.workers[i].terminate();
}
}
async prepareByCallingWorker(): Promise<void> {
if (this.init) {
return;
}
// console.debug("begin prepareByCallingWorker");
await this.cipher.key(this.password, "");
// console.debug("finish getting key");
const res: Promise<void>[] = [];
for (let i = 0; i < this.workers.length; ++i) {
res.push(
new Promise((resolve, reject) => {
const channel = new MessageChannel();
channel.port2.onmessage = (event) => {
// console.debug("main: receiving msg in prepare");
const { status } = event.data as RecvMsg;
if (status === "ok") {
// console.debug("main: receiving init ok in prepare");
this.init = true;
resolve(); // return the class object itself
} else {
reject("error after prepareByCallingWorker");
}
};
channel.port2.onmessageerror = (event) => {
// console.debug("main: receiving error in prepare");
reject(event);
};
// console.debug("main: before postMessage in prepare");
this.workers[i].postMessage(
{
action: "prepare",
dataKeyBuf: this.cipher.dataKey.buffer,
nameKeyBuf: this.cipher.nameKey.buffer,
nameTweakBuf: this.cipher.nameTweak.buffer,
},
[channel.port1 /* buffer no transfered because we need to copy */]
);
})
);
}
await Promise.all(res);
}
async encryptNameByCallingWorker(inputName: string): Promise<string> {
// console.debug("main: start encryptNameByCallingWorker");
await this.prepareByCallingWorker();
// console.debug(
// "main: really start generate promise in encryptNameByCallingWorker"
// );
++this.workerIdx;
const whichWorker = this.workerIdx % this.workers.length;
return await new Promise((resolve, reject) => {
const channel = new MessageChannel();
channel.port2.onmessage = (event) => {
// console.debug("main: receiving msg in encryptNameByCallingWorker");
const { outputName } = event.data as RecvMsg;
if (outputName === undefined) {
reject("unknown outputName after encryptNameByCallingWorker");
} else {
resolve(outputName);
}
};
channel.port2.onmessageerror = (event) => {
// console.debug("main: receiving error in encryptNameByCallingWorker");
reject(event);
};
// console.debug("main: before postMessage in encryptNameByCallingWorker");
this.workers[whichWorker].postMessage(
{
action: "encryptName",
inputName: inputName,
},
[channel.port1]
);
});
}
async decryptNameByCallingWorker(inputName: string): Promise<string> {
await this.prepareByCallingWorker();
++this.workerIdx;
const whichWorker = this.workerIdx % this.workers.length;
return await new Promise((resolve, reject) => {
const channel = new MessageChannel();
channel.port2.onmessage = (event) => {
// console.debug("main: receiving msg in decryptNameByCallingWorker");
const { outputName, status } = event.data as RecvMsg;
if (status === "error") {
reject("error");
} else {
if (outputName === undefined) {
reject("unknown outputName after decryptNameByCallingWorker");
} else {
resolve(outputName);
}
}
};
channel.port2.onmessageerror = (event) => {
// console.debug("main: receiving error in decryptNameByCallingWorker");
reject(event);
channel;
};
// console.debug("main: before postMessage in decryptNameByCallingWorker");
this.workers[whichWorker].postMessage(
{
action: "decryptName",
inputName: inputName,
},
[channel.port1]
);
});
}
async encryptContentByCallingWorker(
input: ArrayBuffer
): Promise<ArrayBuffer> {
await this.prepareByCallingWorker();
++this.workerIdx;
const whichWorker = this.workerIdx % this.workers.length;
return await new Promise((resolve, reject) => {
const channel = new MessageChannel();
channel.port2.onmessage = (event) => {
// console.debug("main: receiving msg in encryptContentByCallingWorker");
const { outputContent } = event.data as RecvMsg;
if (outputContent === undefined) {
reject("unknown outputContent after encryptContentByCallingWorker");
} else {
resolve(outputContent);
}
};
channel.port2.onmessageerror = (event) => {
// console.debug("main: receiving error in encryptContentByCallingWorker");
reject(event);
};
// console.debug(
// "main: before postMessage in encryptContentByCallingWorker"
// );
this.workers[whichWorker].postMessage(
{
action: "encryptContent",
inputContent: input,
},
[channel.port1, input]
);
});
}
async decryptContentByCallingWorker(
input: ArrayBuffer
): Promise<ArrayBuffer> {
await this.prepareByCallingWorker();
++this.workerIdx;
const whichWorker = this.workerIdx % this.workers.length;
return await new Promise((resolve, reject) => {
const channel = new MessageChannel();
channel.port2.onmessage = (event) => {
// console.debug("main: receiving msg in decryptContentByCallingWorker");
const { outputContent, status } = event.data as RecvMsg;
if (status === "error") {
reject("error");
} else {
if (outputContent === undefined) {
reject("unknown outputContent after decryptContentByCallingWorker");
} else {
resolve(outputContent);
}
}
};
channel.port2.onmessageerror = (event) => {
// console.debug(
// "main: receiving onmessageerror in decryptContentByCallingWorker"
// );
reject(event);
};
// console.debug(
// "main: before postMessage in decryptContentByCallingWorker"
// );
this.workers[whichWorker].postMessage(
{
action: "decryptContent",
inputContent: input,
},
[channel.port1, input]
);
});
}
}
+184
View File
@@ -0,0 +1,184 @@
import { nanoid } from "nanoid";
import { Cipher as CipherRCloneCryptPack } from "@fyears/rclone-crypt";
const ctx: WorkerGlobalScope = self as any;
const workerNanoID = nanoid();
const cipher = new CipherRCloneCryptPack("base64");
// console.debug(`worker [${workerNanoID}]: cipher created`);
async function encryptNameStr(input: string) {
const res = await cipher.encryptFileName(input);
return res;
}
async function decryptNameStr(input: string) {
return await cipher.decryptFileName(input);
}
async function encryptContentBuf(input: ArrayBuffer) {
return (await cipher.encryptData(new Uint8Array(input), undefined)).buffer;
}
async function decryptContentBuf(input: ArrayBuffer) {
return (await cipher.decryptData(new Uint8Array(input))).buffer;
}
ctx.addEventListener("message", async (event: any) => {
const port: MessagePort = event.ports[0];
const {
action,
dataKeyBuf,
nameKeyBuf,
nameTweakBuf,
inputName,
inputContent,
} = event.data as {
action:
| "prepare"
| "encryptContent"
| "decryptContent"
| "encryptName"
| "decryptName";
dataKeyBuf?: ArrayBuffer;
nameKeyBuf?: ArrayBuffer;
nameTweakBuf?: ArrayBuffer;
inputName?: string;
inputContent?: ArrayBuffer;
};
// console.debug(`worker [${workerNanoID}]: receiving action=${action}`);
if (action === "prepare") {
// console.debug(`worker [${workerNanoID}]: prepare: start`);
try {
if (
dataKeyBuf === undefined ||
nameKeyBuf === undefined ||
nameTweakBuf === undefined
) {
// console.debug(`worker [${workerNanoID}]: prepare: no buffer??`);
throw Error(
`worker [${workerNanoID}]: prepare: internal keys not transferred to worker properly`
);
}
// console.debug(`worker [${workerNanoID}]: prepare: so we update`);
cipher.updateInternalKey(
new Uint8Array(dataKeyBuf),
new Uint8Array(nameKeyBuf),
new Uint8Array(nameTweakBuf)
);
port.postMessage({
status: "ok",
});
} catch (error) {
console.error(error);
port.postMessage({
status: "error",
error: error,
});
}
} else if (action === "encryptName") {
try {
if (inputName === undefined) {
throw Error(
`worker [${workerNanoID}]: encryptName: internal inputName not transferred to worker properly`
);
}
const outputName = await encryptNameStr(inputName);
// console.debug(
// `worker [${workerNanoID}]: after encryptNameStr, before postMessage`
// );
port.postMessage({
status: "ok",
outputName: outputName,
});
} catch (error) {
console.error(`worker [${workerNanoID}]: encryptName=${inputName}`);
console.error(error);
port.postMessage({
status: "error",
error: error,
});
}
} else if (action === "decryptName") {
try {
if (inputName === undefined) {
throw Error(
`worker [${workerNanoID}]: decryptName: internal inputName not transferred to worker properly`
);
}
const outputName = await decryptNameStr(inputName);
// console.debug(
// `worker [${workerNanoID}]: after decryptNameStr, before postMessage`
// );
port.postMessage({
status: "ok",
outputName: outputName,
});
} catch (error) {
console.error(`worker [${workerNanoID}]: decryptName=${inputName}`);
console.error(error);
port.postMessage({
status: "error",
error: error,
});
}
} else if (action === "encryptContent") {
try {
if (inputContent === undefined) {
throw Error(
`worker [${workerNanoID}]: encryptContent: internal inputContent not transferred to worker properly`
);
}
const outputContent = await encryptContentBuf(inputContent);
// console.debug(
// `worker [${workerNanoID}]: after encryptContentBuf, before postMessage`
// );
port.postMessage(
{
status: "ok",
outputContent: outputContent,
},
[outputContent]
);
} catch (error) {
console.error(error);
port.postMessage({
status: "error",
error: error,
});
}
} else if (action === "decryptContent") {
try {
if (inputContent === undefined) {
throw Error(
`worker [${workerNanoID}]: decryptContent: internal inputContent not transferred to worker properly`
);
}
const outputContent = await decryptContentBuf(inputContent);
// console.debug(
// `worker [${workerNanoID}]: after decryptContentBuf, before postMessage`
// );
port.postMessage(
{
status: "ok",
outputContent: outputContent,
},
[outputContent]
);
} catch (error) {
console.error(error);
port.postMessage({
status: "error",
error: error,
});
}
} else {
port.postMessage({
status: "error",
error: `worker [${workerNanoID}]: unknown action=${action}`,
});
}
});
+215
View File
@@ -0,0 +1,215 @@
import { CipherMethodType } from "./baseTypes";
import * as openssl from "./encryptOpenSSL";
import * as rclone from "./encryptRClone";
import { isVaildText } from "./misc";
export class Cipher {
readonly password: string;
readonly method: CipherMethodType;
cipherRClone?: rclone.CipherRclone;
constructor(password: string, method: CipherMethodType) {
this.password = password ?? "";
this.method = method;
if (method === "rclone-base64") {
this.cipherRClone = new rclone.CipherRclone(password, 5);
}
}
closeResources() {
if (this.method === "rclone-base64" && this.cipherRClone !== undefined) {
this.cipherRClone.closeResources();
}
}
isPasswordEmpty() {
return this.password === "";
}
isFolderAware() {
if (this.method === "openssl-base64") {
return false;
}
if (this.method === "rclone-base64") {
return true;
}
throw Error(`no idea about isFolderAware for method=${this.method}`);
}
async encryptContent(content: ArrayBuffer) {
// console.debug("start encryptContent");
if (this.password === "") {
return content;
}
if (this.method === "openssl-base64") {
const res = await openssl.encryptArrayBuffer(content, this.password);
if (res === undefined) {
throw Error(`cannot encrypt content`);
}
return res;
} else if (this.method === "rclone-base64") {
const res =
await this.cipherRClone!.encryptContentByCallingWorker(content);
if (res === undefined) {
throw Error(`cannot encrypt content`);
}
return res;
} else {
throw Error(`not supported encrypt method=${this.method}`);
}
}
async decryptContent(content: ArrayBuffer) {
// console.debug("start decryptContent");
if (this.password === "") {
return content;
}
if (this.method === "openssl-base64") {
const res = await openssl.decryptArrayBuffer(content, this.password);
if (res === undefined) {
throw Error(`cannot decrypt content`);
}
return res;
} else if (this.method === "rclone-base64") {
const res =
await this.cipherRClone!.decryptContentByCallingWorker(content);
if (res === undefined) {
throw Error(`cannot decrypt content`);
}
return res;
} else {
throw Error(`not supported decrypt method=${this.method}`);
}
}
async encryptName(name: string) {
// console.debug("start encryptName");
if (this.password === "") {
return name;
}
if (this.method === "openssl-base64") {
const res = await openssl.encryptStringToBase64url(name, this.password);
if (res === undefined) {
throw Error(`cannot encrypt name=${name}`);
}
return res;
} else if (this.method === "rclone-base64") {
const res = await this.cipherRClone!.encryptNameByCallingWorker(name);
if (res === undefined) {
throw Error(`cannot encrypt name=${name}`);
}
return res;
} else {
throw Error(`not supported encrypt method=${this.method}`);
}
}
async decryptName(name: string): Promise<string> {
// console.debug("start decryptName");
if (this.password === "") {
return name;
}
if (this.method === "openssl-base64") {
if (name.startsWith(openssl.MAGIC_ENCRYPTED_PREFIX_BASE32)) {
// backward compitable with the openssl-base32
try {
const res = await openssl.decryptBase32ToString(name, this.password);
if (res !== undefined && isVaildText(res)) {
return res;
} else {
throw Error(`cannot decrypt name=${name}`);
}
} catch (error) {
throw Error(`cannot decrypt name=${name}`);
}
} else if (name.startsWith(openssl.MAGIC_ENCRYPTED_PREFIX_BASE64URL)) {
try {
const res = await openssl.decryptBase64urlToString(
name,
this.password
);
if (res !== undefined && isVaildText(res)) {
return res;
} else {
throw Error(`cannot decrypt name=${name}`);
}
} catch (error) {
throw Error(`cannot decrypt name=${name}`);
}
} else {
throw Error(
`method=${this.method} but the name=${name}, likely mismatch`
);
}
} else if (this.method === "rclone-base64") {
const res = await this.cipherRClone!.decryptNameByCallingWorker(name);
if (res === undefined) {
throw Error(`cannot decrypt name=${name}`);
}
return res;
} else {
throw Error(`not supported decrypt method=${this.method}`);
}
}
getSizeFromOrigToEnc(x: number) {
if (this.password === "") {
return x;
}
if (this.method === "openssl-base64") {
return openssl.getSizeFromOrigToEnc(x);
} else if (this.method === "rclone-base64") {
return rclone.getSizeFromOrigToEnc(x);
} else {
throw Error(`not supported encrypt method=${this.method}`);
}
}
/**
* quick guess, no actual decryption here
* @param name
* @returns
*/
static isLikelyOpenSSLEncryptedName(name: string): boolean {
if (
name.startsWith(openssl.MAGIC_ENCRYPTED_PREFIX_BASE32) ||
name.startsWith(openssl.MAGIC_ENCRYPTED_PREFIX_BASE64URL)
) {
return true;
}
return false;
}
/**
* quick guess, no actual decryption here
* @param name
* @returns
*/
static isLikelyEncryptedName(name: string): boolean {
return Cipher.isLikelyOpenSSLEncryptedName(name);
}
/**
* quick guess, no actual decryption here, only openssl can be guessed here
* @param name
* @returns
*/
static isLikelyEncryptedNameNotMatchMethod(
name: string,
method: CipherMethodType
): boolean {
if (
Cipher.isLikelyOpenSSLEncryptedName(name) &&
method !== "openssl-base64"
) {
return true;
}
if (
!Cipher.isLikelyOpenSSLEncryptedName(name) &&
method === "openssl-base64"
) {
return true;
}
return false;
}
}
+24 -13
View File
@@ -5,27 +5,27 @@
"goback": "Go Back", "goback": "Go Back",
"submit": "Submit", "submit": "Submit",
"sometext": "Here are some texts.", "sometext": "Here are some texts.",
"syncrun_alreadyrunning": "{{pluginName}} already running in stage {{syncStatus}}!", "syncrun_alreadyrunning": "New command {{newTriggerSource}} stops because {{pluginName}} is already running in stage {{syncStatus}}!",
"syncrun_syncingribbon": "{{pluginName}}: syncing from {{triggerSource}}", "syncrun_syncingribbon": "{{pluginName}}: syncing from {{triggerSource}}",
"syncrun_step0": "0/8 Remotely Save running in dry mode, not actual file changes would happen.", "syncrun_step0": "0/8 Remotely Save is running in dry mode, thus not actual file changes would happen.",
"syncrun_step1": "1/8 Remotely Save Sync Preparing ({{serviceType}})", "syncrun_step1": "1/8 Remotely Save is preparing ({{serviceType}})",
"syncrun_step2": "2/8 Starting to fetch remote meta data.", "syncrun_step2": "2/8 Starting to fetch remote meta data.",
"syncrun_step3": "3/8 Checking password correct or not.", "syncrun_step3": "3/8 Checking password correct or not.",
"syncrun_passworderr": "Something goes wrong while checking password.", "syncrun_passworderr": "Something goes wrong while checking password.",
"syncrun_step4": "4/8 Starting to fetch local meta data.", "syncrun_step4": "4/8 Starting to fetch local meta data.",
"syncrun_step5": "5/8 Starting to fetch local prev sync data.", "syncrun_step5": "5/8 Starting to fetch local prev sync data.",
"syncrun_step6": "6/8 Starting to generate sync plan.", "syncrun_step6": "6/8 Starting to generate sync plan.",
"syncrun_step7": "7/8 Remotely Save Sync data exchanging!", "syncrun_step7": "7/8 Remotely Save Sync data is exchanging!",
"syncrun_step7skip": "7/8 Remotely Save real sync is skipped in dry run mode.", "syncrun_step7skip": "7/8 Remotely Save real sync is skipped in dry run mode.",
"syncrun_step8": "8/8 Remotely Save finish!", "syncrun_step8": "8/8 Remotely Save finished!",
"syncrun_shortstep0": "0/2 Remotely Save running in dry mode, not actual file changes would happen.", "syncrun_shortstep0": "0/2 Remotely Save is running in dry mode, not actual file changes would happen.",
"syncrun_shortstep1": "1/2 Remotely Save Sync Start Running ({{serviceType}})", "syncrun_shortstep1": "1/2 Remotely Save starts running ({{serviceType}})",
"syncrun_shortstep2skip": "2/2 Remotely Save real sync is skipped in dry run mode.", "syncrun_shortstep2skip": "2/2 Remotely Save real sync is skipped in dry run mode.",
"syncrun_shortstep2": "2/2 Remotely Save finish!", "syncrun_shortstep2": "2/2 Remotely Save finished!",
"syncrun_abort": "{{manifestID}}-{{theDate}}: abort sync, triggerSource={{triggerSource}}, error while {{syncStatus}}", "syncrun_abort": "{{manifestID}}-{{theDate}}: abort sync, triggerSource={{triggerSource}}, error while {{syncStatus}}",
"syncrun_abort_protectmodifypercentage": "Abort! you set changing files >= {{protectModifyPercentage}}% is not allowed but {{realModifyDeleteCount}}/{{allFilesCount}}={{percent}}% is going to be modified or deleted! If you are sure you want this sync, please adjust the allowed ratio in the settings.", "syncrun_abort_protectmodifypercentage": "Abort! you set changing files >= {{protectModifyPercentage}}% is not allowed but {{realModifyDeleteCount}}/{{allFilesCount}}={{percent}}% is going to be modified or deleted! If you are sure you want this sync, please adjust the allowed ratio in the settings.",
"protocol_saveqr": "New not-oauth2 settings for {{manifestName}} saved. Reopen the plugin Settings to the effect.", "protocol_saveqr": "New not-oauth2 settings for {{manifestName}} is saved. Reopen the plugin settings to make it effective.",
"protocol_callbacknotsupported": "Your uri call a callback that's not supported yet: {{params}}", "protocol_callbacknotsupported": "Your uri calls a callback that's not supported yet: {{params}}",
"protocol_dropbox_connecting": "Connecting to Dropbox...\nPlease DO NOT close this modal.", "protocol_dropbox_connecting": "Connecting to Dropbox...\nPlease DO NOT close this modal.",
"protocol_dropbox_connect_succ": "Good! We've connected to Dropbox as user {{username}}!", "protocol_dropbox_connect_succ": "Good! We've connected to Dropbox as user {{username}}!",
"protocol_dropbox_connect_succ_revoke": "You've connected as user {{username}}. If you want to disconnect, click this button.", "protocol_dropbox_connect_succ_revoke": "You've connected as user {{username}}. If you want to disconnect, click this button.",
@@ -64,6 +64,8 @@
"modal_password_attn5": "Attention 5/5: The longer the password, the better.", "modal_password_attn5": "Attention 5/5: The longer the password, the better.",
"modal_password_secondconfirm": "The Second Confirm to change password.", "modal_password_secondconfirm": "The Second Confirm to change password.",
"modal_password_notice": "New password saved!", "modal_password_notice": "New password saved!",
"modal_encryptionmethod_title": "Hold on and PLEASE READ ON...",
"modal_encryptionmethod_shortdesc": "You are changing the encrpytion method but you have set the password before.\nAfter switching the method, you need to <b>manually</b> and <b>fully</b> delete every encrypted vault files in the remote and re-sync (so that re-upload) the newly encrypted files again.",
"modal_remotebasedir_title": "You are changing the remote base directory config", "modal_remotebasedir_title": "You are changing the remote base directory config",
"modal_remotebasedir_shortdesc": "1. The plugin would NOT automatically move the content from the old directory to the new one directly on the remote. Everything syncs from the beginning again.\n2. If you set the string to the empty, the config would be reset to use the vault folder name (the default config).\n3. The remote directory name itself would not be encrypted even you've set an E2E password.\n4. Some special char like '?', '/', '\\' are not allowed. Spaces in the beginning or in the end are also trimmed.", "modal_remotebasedir_shortdesc": "1. The plugin would NOT automatically move the content from the old directory to the new one directly on the remote. Everything syncs from the beginning again.\n2. If you set the string to the empty, the config would be reset to use the vault folder name (the default config).\n3. The remote directory name itself would not be encrypted even you've set an E2E password.\n4. Some special char like '?', '/', '\\' are not allowed. Spaces in the beginning or in the end are also trimmed.",
"modal_remotebasedir_invaliddirhint": "Your input contains special characters like '?', '/', '\\' which are not allowed.", "modal_remotebasedir_invaliddirhint": "Your input contains special characters like '?', '/', '\\' which are not allowed.",
@@ -109,7 +111,12 @@
"modal_sizesconflict_copynotice": "All the sizes conflicts info have been copied to the clipboard!", "modal_sizesconflict_copynotice": "All the sizes conflicts info have been copied to the clipboard!",
"settings_basic": "Basic Settings", "settings_basic": "Basic Settings",
"settings_password": "Encryption Password", "settings_password": "Encryption Password",
"settings_password_desc": "Password for E2E encryption. Empty for no password. You need to click \"Confirm\". Attention: the password and other info are saved locally.", "settings_password_desc": "Password for E2E encryption. Empty for no password. You need to click \"Confirm\". Attention: The password and other info are saved locally. After changing the password, you need to manually delete every original files in the remote, and re-sync (so that upload) the encrypted files again.",
"settings_encryptionmethod": "Encryption Method",
"settings_encryptionmethod_desc": "Encryption method for E2E encryption. RClone Crypt format is recommended but it doesn't encrypt path structure. OpenSSL enc is the legacy format of this plugin. <b>Both are not affliated with official RClone and OpenSSL product or community.</b> Attention: After switching the method, you need to manually delete every original files in the remote and re-sync (so that upload) the encrypted files again. More info in the <a href='https://github.com/remotely-save/remotely-save/tree/master/docs/encryption'>online doc</a>.",
"settings_encryptionmethod_rclone": "RClone Crypt (recommended)",
"settings_encryptionmethod_openssl": "OpenSSL enc (legacy)",
"settings_autorun": "Schedule For Auto Run", "settings_autorun": "Schedule For Auto Run",
"settings_autorun_desc": "The plugin tries to schedule the running after every interval. Battery may be impacted.", "settings_autorun_desc": "The plugin tries to schedule the running after every interval. Battery may be impacted.",
"settings_autorun_notset": "(not set)", "settings_autorun_notset": "(not set)",
@@ -264,6 +271,8 @@
"setting_syncdirection_bidirectional_desc": "Bidirectional (default)", "setting_syncdirection_bidirectional_desc": "Bidirectional (default)",
"setting_syncdirection_incremental_push_only_desc": "Incremental Push Only (aka backup mode)", "setting_syncdirection_incremental_push_only_desc": "Incremental Push Only (aka backup mode)",
"setting_syncdirection_incremental_pull_only_desc": "Incremental Pull Only", "setting_syncdirection_incremental_pull_only_desc": "Incremental Pull Only",
"settings_enablemobilestatusbar": "Mobile Status Bar (experimental)",
"settings_enablemobilestatusbar_desc": "By default Obsidian mobile hides status bar. But some users want to show it up. So here is a hack.",
"settings_importexport": "Import and Export Partial Settings", "settings_importexport": "Import and Export Partial Settings",
"settings_export": "Export", "settings_export": "Export",
"settings_export_desc": "Export not-oauth2 settings by generating a qrcode.", "settings_export_desc": "Export not-oauth2 settings by generating a qrcode.",
@@ -277,6 +286,8 @@
"settings_outputsettingsconsole_desc": "The settings save on disk in encoded. Click this to see the decoded settings in console.", "settings_outputsettingsconsole_desc": "The settings save on disk in encoded. Click this to see the decoded settings in console.",
"settings_outputsettingsconsole_button": "Output", "settings_outputsettingsconsole_button": "Output",
"settings_outputsettingsconsole_notice": "Finished outputing in console.", "settings_outputsettingsconsole_notice": "Finished outputing in console.",
"settings_obfuscatesettingfile": "Obfuscate The Setting File Or Not",
"settings_obfuscatesettingfile_desc": "The setting file (data.json) has some sensitive information. It's strongly recommended to obfuscate it to avoid unexpected read and modification. If you are sure to view and edit it manually, you can disable the obfuscation.",
"settings_viewconsolelog": "View Console Log", "settings_viewconsolelog": "View Console Log",
"settings_viewconsolelog_desc": "On desktop, please press \"ctrl+shift+i\" or \"cmd+shift+i\" to view the log. On mobile, please install the third-party plugin <a href='https://obsidian.md/plugins?search=Logstravaganza'>Logstravaganza</a> to export the console log to a note.", "settings_viewconsolelog_desc": "On desktop, please press \"ctrl+shift+i\" or \"cmd+shift+i\" to view the log. On mobile, please install the third-party plugin <a href='https://obsidian.md/plugins?search=Logstravaganza'>Logstravaganza</a> to export the console log to a note.",
"settings_syncplans": "Export Sync Plans", "settings_syncplans": "Export Sync Plans",
@@ -299,7 +310,7 @@
"settings_resetcache_button": "Reset", "settings_resetcache_button": "Reset",
"settings_resetcache_notice": "Local internal cache/databases deleted. Please manually reload the plugin.", "settings_resetcache_notice": "Local internal cache/databases deleted. Please manually reload the plugin.",
"syncalgov3_title": "Remotely Save has HUGE updates on the sync algorithm", "syncalgov3_title": "Remotely Save has HUGE updates on the sync algorithm",
"syncalgov3_texts": "Welcome to use Remotely Save!\nFrom this version, a new algorithm has been developed:\n<ul><li>More robust deletion sync,</li><li>minimal conflict handling,</li><li>no meta data uploaded any more,</li><li>deletion / modification protection,</li><li>backup mode</li><li>...</li></ul>\nStay tune for more! A full introduction is in the <a href='https://github.com/remotely-save/remotely-save/tree/master/docs/sync_algorithm/v3/intro.md'>doc website</a>.\nIf you agree to use this, please read and check two checkboxes then click the \"Agree\" button, and enjoy the plugin!\nIf you do not agree, please click the \"Do Not Agree\" button, the plugin will unload itself.\nAlso, please consider <a href='https://github.com/remotely-save/remotely-save'>visit the GitHub repo and star ⭐ it</a>! Or even <a href='https://github.com/remotely-save/donation'>buy me a coffee</a>. Your support is very important to me! Thanks!", "syncalgov3_texts": "Welcome to use Remotely Save!\nFrom this version, a new algorithm has been developed:\n<ul><li>More robust deletion sync,</li><li>minimal conflict handling,</li><li>no meta data uploaded any more,</li><li>deletion / modification protection,</li><li>backup mode</li><li>new encryption method</li><li>...</li></ul>\nStay tune for more! A full introduction is in the <a href='https://github.com/remotely-save/remotely-save/tree/master/docs/sync_algorithm/v3/intro.md'>doc website</a>.\nIf you agree to use this, please read and check two checkboxes then click the \"Agree\" button, and enjoy the plugin!\nIf you do not agree, please click the \"Do Not Agree\" button, the plugin will unload itself.\nAlso, please consider <a href='https://github.com/remotely-save/remotely-save'>visit the GitHub repo and star ⭐ it</a>! Or even <a href='https://github.com/remotely-save/donation'>buy me a coffee</a>. Your support is very important to me! Thanks!",
"syncalgov3_checkbox_manual_backup": "I will backup my vault manually firstly.", "syncalgov3_checkbox_manual_backup": "I will backup my vault manually firstly.",
"syncalgov3_checkbox_requiremultidevupdate": "I understand I need to update the plugin ACROSS ALL DEVICES to make them work properly.", "syncalgov3_checkbox_requiremultidevupdate": "I understand I need to update the plugin ACROSS ALL DEVICES to make them work properly.",
"syncalgov3_button_agree": "Agree", "syncalgov3_button_agree": "Agree",
+13 -3
View File
@@ -5,7 +5,7 @@
"goback": "返回", "goback": "返回",
"submit": "提交", "submit": "提交",
"sometext": "这里有一段文字。", "sometext": "这里有一段文字。",
"syncrun_alreadyrunning": "{{pluginName}} 正处于此阶段:{{syncStatus}}!", "syncrun_alreadyrunning": "{{pluginName}} 正处于此阶段:{{syncStatus}}!中断触发 {{newTriggerSource}}。",
"syncrun_syncingribbon": "{{pluginName}}:正在由 {{triggerSource}} 触发运行", "syncrun_syncingribbon": "{{pluginName}}:正在由 {{triggerSource}} 触发运行",
"syncrun_step0": "0/8 Remotely Save 在空跑(dry run)模式,不会发生实际的文件交换。", "syncrun_step0": "0/8 Remotely Save 在空跑(dry run)模式,不会发生实际的文件交换。",
"syncrun_step1": "1/8 Remotely Save 准备同步({{serviceType}}", "syncrun_step1": "1/8 Remotely Save 准备同步({{serviceType}}",
@@ -64,6 +64,8 @@
"modal_password_attn5": "注意 5/5:密码越长越好。", "modal_password_attn5": "注意 5/5:密码越长越好。",
"modal_password_secondconfirm": "再次确认保存新密码", "modal_password_secondconfirm": "再次确认保存新密码",
"modal_password_notice": "新密码已保存!", "modal_password_notice": "新密码已保存!",
"modal_encryptionmethod_title": "稍等一下,请阅读下文:",
"modal_encryptionmethod_shortdesc": "您正在修改加密方式,但是您已经设置了密码。\n修改加密方式之后,您需要<b>手动</b>和<b>完全</b>删除在远端的之前加密过的库文件,然后重新同步(从而重新上传)新的加密文件。",
"modal_remotebasedir_title": "您正在修改远端基文件夹设置", "modal_remotebasedir_title": "您正在修改远端基文件夹设置",
"modal_remotebasedir_shortdesc": "1. 本插件并不会自动在远端把内容从旧文件夹移动到新文件夹。所有内容都会重新同步。\n2. 如果你使得文本输入框为空,那么本设置会被重设回库的文件夹名(默认设置)。\n3. 即使您设置了端对端加密的密码,远端文件夹名称本身也不会被加密。\n4. 某些特殊字符,如“?”、“/”、“\\”是不允许的。文本前后的空格也会被自动删去。", "modal_remotebasedir_shortdesc": "1. 本插件并不会自动在远端把内容从旧文件夹移动到新文件夹。所有内容都会重新同步。\n2. 如果你使得文本输入框为空,那么本设置会被重设回库的文件夹名(默认设置)。\n3. 即使您设置了端对端加密的密码,远端文件夹名称本身也不会被加密。\n4. 某些特殊字符,如“?”、“/”、“\\”是不允许的。文本前后的空格也会被自动删去。",
"modal_remotebasedir_invaliddirhint": "您所输入的内容含有某些特殊字符,如“?”、“/”、“\\”,它们是不允许的。", "modal_remotebasedir_invaliddirhint": "您所输入的内容含有某些特殊字符,如“?”、“/”、“\\”,它们是不允许的。",
@@ -109,7 +111,11 @@
"modal_sizesconflict_copynotice": "所有的文件大小冲突信息,已被复制到剪贴板!", "modal_sizesconflict_copynotice": "所有的文件大小冲突信息,已被复制到剪贴板!",
"settings_basic": "基本设置", "settings_basic": "基本设置",
"settings_password": "密码", "settings_password": "密码",
"settings_password_desc": "端到端加密的密码。不填写则代表没密码。您需要点击“确认”来修改。注意:密码和其它信息都会在本地保存。", "settings_password_desc": "端到端加密的密码。不填写则代表没密码。您需要点击“确认”来修改。注意:密码和其它信息都会在本地保存。如果您修改了密码,您需要手动删除远端的所有文件,重新同步(从而上传)加密文件。",
"settings_encryptionmethod": "加密方法",
"settings_encryptionmethod_desc": "端到端加密的方法。推荐选用 RClone Crypt 方法,但是它没有加密文件路径结构。OpenSSL enc 是本插件一开始就支持的方式。<b>两种方法都和 RClone、OpenSSL 官方产品和社区无利益相关。</b>如果您修改了加密方法,您需要手动删除远端的所有文件,重新同步(从而上传)加密文件。更多详细说明见<a href='https://github.com/remotely-save/remotely-save/tree/master/docs/encryption'>在线文档</a>。",
"settings_encryptionmethod_rclone": "RClone Crypt(推荐)",
"settings_encryptionmethod_openssl": "OpenSSL enc(旧方法)",
"settings_autorun": "自动运行", "settings_autorun": "自动运行",
"settings_autorun_desc": "每隔一段时间,此插件尝试自动同步。会影响到电池用量。", "settings_autorun_desc": "每隔一段时间,此插件尝试自动同步。会影响到电池用量。",
"settings_autorun_notset": "(不设置)", "settings_autorun_notset": "(不设置)",
@@ -264,6 +270,8 @@
"setting_syncdirection_bidirectional_desc": "双向同步(默认)", "setting_syncdirection_bidirectional_desc": "双向同步(默认)",
"setting_syncdirection_incremental_push_only_desc": "只增量推送(也即:备份模式)", "setting_syncdirection_incremental_push_only_desc": "只增量推送(也即:备份模式)",
"setting_syncdirection_incremental_pull_only_desc": "只增量拉取", "setting_syncdirection_incremental_pull_only_desc": "只增量拉取",
"settings_enablemobilestatusbar": "手机的状态栏(实验性质)",
"settings_enablemobilestatusbar_desc": "Obsidian 手机版默认隐藏了状态栏。有些用户希望展示它。这里提供了设置选项。",
"settings_importexport": "导入导出部分设置", "settings_importexport": "导入导出部分设置",
"settings_export": "导出", "settings_export": "导出",
"settings_export_desc": "用 QR 码导出非 oauth2 的设置信息。", "settings_export_desc": "用 QR 码导出非 oauth2 的设置信息。",
@@ -277,6 +285,8 @@
"settings_outputsettingsconsole_desc": "硬盘上的设置文件是编码过的,点击这里从而解码并输出到终端。", "settings_outputsettingsconsole_desc": "硬盘上的设置文件是编码过的,点击这里从而解码并输出到终端。",
"settings_outputsettingsconsole_button": "输出", "settings_outputsettingsconsole_button": "输出",
"settings_outputsettingsconsole_notice": "已输出到终端", "settings_outputsettingsconsole_notice": "已输出到终端",
"settings_obfuscatesettingfile": "是否混淆保存设置文件",
"settings_obfuscatesettingfile_desc": "设置文件(data.json)含有敏感信息。强烈建议混淆后保存它,从而避免出乎意料的读取和修改。如果您确认要手动查看和修改它,可以关闭混淆保存。",
"settings_viewconsolelog": "查看终端输出", "settings_viewconsolelog": "查看终端输出",
"settings_viewconsolelog_desc": "电脑上,输入“ctrl+shift+i”或“cmd+shift+i”来查看终端输出。手机上,安装第三方插件 <a href='https://obsidian.md/plugins?search=Logstravaganza'>Logstravaganza</a> 来导出终端输出到一篇笔记上。", "settings_viewconsolelog_desc": "电脑上,输入“ctrl+shift+i”或“cmd+shift+i”来查看终端输出。手机上,安装第三方插件 <a href='https://obsidian.md/plugins?search=Logstravaganza'>Logstravaganza</a> 来导出终端输出到一篇笔记上。",
"settings_syncplans": "导出同步计划", "settings_syncplans": "导出同步计划",
@@ -299,7 +309,7 @@
"settings_resetcache_button": "重设", "settings_resetcache_button": "重设",
"settings_resetcache_notice": "本地同步缓存和数据库已被删除。请手动重新载入此插件。", "settings_resetcache_notice": "本地同步缓存和数据库已被删除。请手动重新载入此插件。",
"syncalgov3_title": "Remotely Save 的同步算法有重大更新", "syncalgov3_title": "Remotely Save 的同步算法有重大更新",
"syncalgov3_texts": "欢迎使用 Remotely Save!\n从这个版本开始,插件更新了同步算法:\n<ul><li>更稳健的删除同步</li><li>引入冲突处理</li><li>避免上传元数据</li><li>修改删除保护</li><li>备份模式</li><li>……</li></ul>\n敬请期待更多更新!详细介绍请参阅<a href='https://github.com/remotely-save/remotely-save/tree/master/docs/sync_algorithm/v3/intro.md'>文档网站</a>。\n如果您同意使用新版本,请阅读和勾选两个勾选框,然后点击“同意”按钮,开始使用插件吧!\n如果您不同意,请点击“不同意”按钮,插件将自动停止运行(unload)。\n此外,请考虑<a href='https://github.com/remotely-save/remotely-save'>访问 GitHub 页面然后点赞 ⭐</a>!您的支持对我十分重要!谢谢!", "syncalgov3_texts": "欢迎使用 Remotely Save!\n从这个版本开始,插件更新了同步算法:\n<ul><li>更稳健的删除同步</li><li>引入冲突处理</li><li>避免上传元数据</li><li>修改删除保护</li><li>备份模式</li><li>新的加密方式</li><li>……</li></ul>\n敬请期待更多更新!详细介绍请参阅<a href='https://github.com/remotely-save/remotely-save/tree/master/docs/sync_algorithm/v3/intro.md'>文档网站</a>。\n如果您同意使用新版本,请阅读和勾选两个勾选框,然后点击“同意”按钮,开始使用插件吧!\n如果您不同意,请点击“不同意”按钮,插件将自动停止运行(unload)。\n此外,请考虑<a href='https://github.com/remotely-save/remotely-save'>访问 GitHub 页面然后点赞 ⭐</a>!您的支持对我十分重要!谢谢!",
"syncalgov3_checkbox_manual_backup": "我将会首先手动备份我的库(Vault)。", "syncalgov3_checkbox_manual_backup": "我将会首先手动备份我的库(Vault)。",
"syncalgov3_checkbox_requiremultidevupdate": "我理解,我需要在所有设备上都更新此插件使之正常运行。", "syncalgov3_checkbox_requiremultidevupdate": "我理解,我需要在所有设备上都更新此插件使之正常运行。",
"syncalgov3_button_agree": "同意", "syncalgov3_button_agree": "同意",
+13 -3
View File
@@ -5,7 +5,7 @@
"goback": "返回", "goback": "返回",
"submit": "提交", "submit": "提交",
"sometext": "這裡有一段文字。", "sometext": "這裡有一段文字。",
"syncrun_alreadyrunning": "{{pluginName}} 正處於此階段:{{syncStatus}}!", "syncrun_alreadyrunning": "{{pluginName}} 正處於此階段:{{syncStatus}}! 中斷觸發 {{newTriggerSource}}。",
"syncrun_syncingribbon": "{{pluginName}}:正在由 {{triggerSource}} 觸發執行", "syncrun_syncingribbon": "{{pluginName}}:正在由 {{triggerSource}} 觸發執行",
"syncrun_step0": "0/8 Remotely Save 在空跑(dry run)模式,不會發生實際的檔案交換。", "syncrun_step0": "0/8 Remotely Save 在空跑(dry run)模式,不會發生實際的檔案交換。",
"syncrun_step1": "1/8 Remotely Save 準備同步({{serviceType}}", "syncrun_step1": "1/8 Remotely Save 準備同步({{serviceType}}",
@@ -64,6 +64,8 @@
"modal_password_attn5": "注意 5/5:密碼越長越好。", "modal_password_attn5": "注意 5/5:密碼越長越好。",
"modal_password_secondconfirm": "再次確認儲存新密碼", "modal_password_secondconfirm": "再次確認儲存新密碼",
"modal_password_notice": "新密碼已儲存!", "modal_password_notice": "新密碼已儲存!",
"modal_encryptionmethod_title": "稍等一下,請閱讀下文:",
"modal_encryptionmethod_shortdesc": "您正在修改加密方式,但是您已經設定了密碼。\n修改加密方式之後,您需要<b>手動</b>和<b>完全</b>刪除在遠端的之前加密過的庫檔案,然後重新同步(從而重新上傳)新的加密檔案。",
"modal_remotebasedir_title": "您正在修改遠端基資料夾設定", "modal_remotebasedir_title": "您正在修改遠端基資料夾設定",
"modal_remotebasedir_shortdesc": "1. 本外掛並不會自動在遠端把內容從舊資料夾移動到新資料夾。所有內容都會重新同步。\n2. 如果你使得文字輸入框為空,那麼本設定會被重設回庫的資料夾名(預設設定)。\n3. 即使您設定了端對端加密的密碼,遠端資料夾名稱本身也不會被加密。\n4. 某些特殊字元,如“?”、“/”、“\\”是不允許的。文字前後的空格也會被自動刪去。", "modal_remotebasedir_shortdesc": "1. 本外掛並不會自動在遠端把內容從舊資料夾移動到新資料夾。所有內容都會重新同步。\n2. 如果你使得文字輸入框為空,那麼本設定會被重設回庫的資料夾名(預設設定)。\n3. 即使您設定了端對端加密的密碼,遠端資料夾名稱本身也不會被加密。\n4. 某些特殊字元,如“?”、“/”、“\\”是不允許的。文字前後的空格也會被自動刪去。",
"modal_remotebasedir_invaliddirhint": "您所輸入的內容含有某些特殊字元,如“?”、“/”、“\\”,它們是不允許的。", "modal_remotebasedir_invaliddirhint": "您所輸入的內容含有某些特殊字元,如“?”、“/”、“\\”,它們是不允許的。",
@@ -109,7 +111,11 @@
"modal_sizesconflict_copynotice": "所有的檔案大小衝突資訊,已被複制到剪貼簿!", "modal_sizesconflict_copynotice": "所有的檔案大小衝突資訊,已被複制到剪貼簿!",
"settings_basic": "基本設定", "settings_basic": "基本設定",
"settings_password": "密碼", "settings_password": "密碼",
"settings_password_desc": "端到端加密的密碼。不填寫則代表沒密碼。您需要點選“確認”來修改。注意:密碼和其它資訊都會在本地儲存。", "settings_password_desc": "端到端加密的密碼。不填寫則代表沒密碼。您需要點選“確認”來修改。注意:密碼和其它資訊都會在本地儲存。如果您修改了密碼,您需要手動刪除遠端的所有檔案,重新同步(從而上傳)加密檔案。",
"settings_encryptionmethod": "加密方法",
"settings_encryptionmethod_desc": "端到端加密的方法。推薦選用 RClone Crypt 方法,但是它沒有加密檔案路徑結構。OpenSSL enc 是本外掛一開始就支援的方式。<b>兩種方法都和 RClone、OpenSSL 官方產品和社群無利益相關。</b>如果您修改了加密方法,您需要手動刪除遠端的所有檔案,重新同步(從而上傳)加密檔案。更多詳細說明見<a href='https://github.com/remotely-save/remotely-save/tree/master/docs/encryption'>線上文件</a>。",
"settings_encryptionmethod_rclone": "RClone Crypt(推薦)",
"settings_encryptionmethod_openssl": "OpenSSL enc(舊方法)",
"settings_autorun": "自動執行", "settings_autorun": "自動執行",
"settings_autorun_desc": "每隔一段時間,此外掛嘗試自動同步。會影響到電池用量。", "settings_autorun_desc": "每隔一段時間,此外掛嘗試自動同步。會影響到電池用量。",
"settings_autorun_notset": "(不設定)", "settings_autorun_notset": "(不設定)",
@@ -264,6 +270,8 @@
"setting_syncdirection_bidirectional_desc": "雙向同步(預設)", "setting_syncdirection_bidirectional_desc": "雙向同步(預設)",
"setting_syncdirection_incremental_push_only_desc": "只增量推送(也即:備份模式)", "setting_syncdirection_incremental_push_only_desc": "只增量推送(也即:備份模式)",
"setting_syncdirection_incremental_pull_only_desc": "只增量拉取", "setting_syncdirection_incremental_pull_only_desc": "只增量拉取",
"settings_enablemobilestatusbar": "手機的狀態列(實驗性質)",
"settings_enablemobilestatusbar_desc": "Obsidian 手機版預設隱藏了狀態列。有些使用者希望展示它。這裡提供了設定選項。",
"settings_importexport": "匯入匯出部分設定", "settings_importexport": "匯入匯出部分設定",
"settings_export": "匯出", "settings_export": "匯出",
"settings_export_desc": "用 QR 碼匯出非 oauth2 的設定資訊。", "settings_export_desc": "用 QR 碼匯出非 oauth2 的設定資訊。",
@@ -277,6 +285,8 @@
"settings_outputsettingsconsole_desc": "硬碟上的設定檔案是編碼過的,點選這裡從而解碼並輸出到終端。", "settings_outputsettingsconsole_desc": "硬碟上的設定檔案是編碼過的,點選這裡從而解碼並輸出到終端。",
"settings_outputsettingsconsole_button": "輸出", "settings_outputsettingsconsole_button": "輸出",
"settings_outputsettingsconsole_notice": "已輸出到終端", "settings_outputsettingsconsole_notice": "已輸出到終端",
"settings_obfuscatesettingfile": "是否混淆儲存設定檔案",
"settings_obfuscatesettingfile_desc": "設定檔案(data.json)含有敏感資訊。強烈建議混淆後儲存它,從而避免出乎意料的讀取和修改。如果您確認要手動檢視和修改它,可以關閉混淆儲存。",
"settings_viewconsolelog": "檢視終端輸出", "settings_viewconsolelog": "檢視終端輸出",
"settings_viewconsolelog_desc": "電腦上,輸入“ctrl+shift+i”或“cmd+shift+i”來檢視終端輸出。手機上,安裝第三方外掛 <a href='https://obsidian.md/plugins?search=Logstravaganza'>Logstravaganza</a> 來匯出終端輸出到一篇筆記上。", "settings_viewconsolelog_desc": "電腦上,輸入“ctrl+shift+i”或“cmd+shift+i”來檢視終端輸出。手機上,安裝第三方外掛 <a href='https://obsidian.md/plugins?search=Logstravaganza'>Logstravaganza</a> 來匯出終端輸出到一篇筆記上。",
"settings_syncplans": "匯出同步計劃", "settings_syncplans": "匯出同步計劃",
@@ -299,7 +309,7 @@
"settings_resetcache_button": "重設", "settings_resetcache_button": "重設",
"settings_resetcache_notice": "本地同步快取和資料庫已被刪除。請手動重新載入此外掛。", "settings_resetcache_notice": "本地同步快取和資料庫已被刪除。請手動重新載入此外掛。",
"syncalgov3_title": "Remotely Save 的同步演算法有重大更新", "syncalgov3_title": "Remotely Save 的同步演算法有重大更新",
"syncalgov3_texts": "歡迎使用 Remotely Save!\n從這個版本開始,外掛更新了同步演算法:\n<ul><li>更穩健的刪除同步</li><li>引入衝突處理</li><li>避免上傳元資料</li><li>修改刪除保護</li><li>備份模式</li><li>……</li></ul>\n敬請期待更多更新!詳細介紹請參閱<a href='https://github.com/remotely-save/remotely-save/tree/master/docs/sync_algorithm/v3/intro.md'>文件網站</a>。\n如果您同意使用新版本,請閱讀和勾選兩個勾選框,然後點選“同意”按鈕,開始使用外掛吧!\n如果您不同意,請點選“不同意”按鈕,外掛將自動停止執行(unload)。\n此外,請考慮<a href='https://github.com/remotely-save/remotely-save'>訪問 GitHub 頁面然後點贊 ⭐</a>!您的支援對我十分重要!謝謝!", "syncalgov3_texts": "歡迎使用 Remotely Save!\n從這個版本開始,外掛更新了同步演算法:\n<ul><li>更穩健的刪除同步</li><li>引入衝突處理</li><li>避免上傳元資料</li><li>修改刪除保護</li><li>備份模式</li><li>新的加密方式</li><li>……</li></ul>\n敬請期待更多更新!詳細介紹請參閱<a href='https://github.com/remotely-save/remotely-save/tree/master/docs/sync_algorithm/v3/intro.md'>文件網站</a>。\n如果您同意使用新版本,請閱讀和勾選兩個勾選框,然後點選“同意”按鈕,開始使用外掛吧!\n如果您不同意,請點選“不同意”按鈕,外掛將自動停止執行(unload)。\n此外,請考慮<a href='https://github.com/remotely-save/remotely-save'>訪問 GitHub 頁面然後點贊 ⭐</a>!您的支援對我十分重要!謝謝!",
"syncalgov3_checkbox_manual_backup": "我將會首先手動備份我的庫(Vault)。", "syncalgov3_checkbox_manual_backup": "我將會首先手動備份我的庫(Vault)。",
"syncalgov3_checkbox_requiremultidevupdate": "我理解,我需要在所有裝置上都更新此外掛使之正常執行。", "syncalgov3_checkbox_requiremultidevupdate": "我理解,我需要在所有裝置上都更新此外掛使之正常執行。",
"syncalgov3_button_agree": "同意", "syncalgov3_button_agree": "同意",
+126 -51
View File
@@ -9,6 +9,7 @@ import {
Platform, Platform,
requestUrl, requestUrl,
requireApiVersion, requireApiVersion,
Events,
} from "obsidian"; } from "obsidian";
import cloneDeep from "lodash/cloneDeep"; import cloneDeep from "lodash/cloneDeep";
import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide"; import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide";
@@ -66,7 +67,8 @@ import { SyncAlgoV3Modal } from "./syncAlgoV3Notice";
import AggregateError from "aggregate-error"; import AggregateError from "aggregate-error";
import { exportVaultSyncPlansToFiles } from "./debugMode"; import { exportVaultSyncPlansToFiles } from "./debugMode";
import { compareVersion } from "./misc"; import { changeMobileStatusBar, compareVersion } from "./misc";
import { Cipher } from "./encryptUnified";
const DEFAULT_SETTINGS: RemotelySavePluginSettings = { const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
s3: DEFAULT_S3_CONFIG, s3: DEFAULT_S3_CONFIG,
@@ -95,6 +97,9 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
howToCleanEmptyFolder: "skip", howToCleanEmptyFolder: "skip",
protectModifyPercentage: 50, protectModifyPercentage: 50,
syncDirection: "bidirectional", syncDirection: "bidirectional",
obfuscateSettingFile: true,
enableMobileStatusBar: false,
encryptionMethod: "unknown",
}; };
interface OAuth2Info { interface OAuth2Info {
@@ -145,6 +150,8 @@ export default class RemotelySavePlugin extends Plugin {
i18n!: I18n; i18n!: I18n;
vaultRandomID!: string; vaultRandomID!: string;
debugServerTemp?: string; debugServerTemp?: string;
syncEvent?: Events;
appContainerObserver?: MutationObserver;
async syncRun(triggerSource: SyncTriggerSourceType = "manual") { async syncRun(triggerSource: SyncTriggerSourceType = "manual") {
const t = (x: TransItemType, vars?: any) => { const t = (x: TransItemType, vars?: any) => {
@@ -161,15 +168,17 @@ export default class RemotelySavePlugin extends Plugin {
} }
}; };
if (this.syncStatus !== "idle") { if (this.syncStatus !== "idle") {
// here the notice is shown regardless of triggerSource // really, users don't want to see this in auto mode
new Notice( // so we use getNotice to avoid unnecessary show up
getNotice(
t("syncrun_alreadyrunning", { t("syncrun_alreadyrunning", {
pluginName: this.manifest.name, pluginName: this.manifest.name,
syncStatus: this.syncStatus, syncStatus: this.syncStatus,
newTriggerSource: triggerSource,
}) })
); );
if (this.currSyncMsg !== undefined && this.currSyncMsg !== "") { if (this.currSyncMsg !== undefined && this.currSyncMsg !== "") {
new Notice(this.currSyncMsg); getNotice(this.currSyncMsg);
} }
return; return;
} }
@@ -252,10 +261,12 @@ export default class RemotelySavePlugin extends Plugin {
getNotice(t("syncrun_step3")); getNotice(t("syncrun_step3"));
} }
this.syncStatus = "checking_password"; this.syncStatus = "checking_password";
const passwordCheckResult = await isPasswordOk(
remoteEntityList, const cipher = new Cipher(
this.settings.password this.settings.password,
this.settings.encryptionMethod ?? "unknown"
); );
const passwordCheckResult = await isPasswordOk(remoteEntityList, cipher);
if (!passwordCheckResult.ok) { if (!passwordCheckResult.ok) {
getNotice(t("syncrun_passworderr")); getNotice(t("syncrun_passworderr"));
throw Error(passwordCheckResult.reason); throw Error(passwordCheckResult.reason);
@@ -304,7 +315,8 @@ export default class RemotelySavePlugin extends Plugin {
this.app.vault.configDir, this.app.vault.configDir,
this.settings.syncUnderscoreItems ?? false, this.settings.syncUnderscoreItems ?? false,
this.settings.ignorePaths ?? [], this.settings.ignorePaths ?? [],
this.settings.password cipher,
this.settings.serviceType
); );
mixedEntityMappings = await getSyncPlanInplace( mixedEntityMappings = await getSyncPlanInplace(
mixedEntityMappings, mixedEntityMappings,
@@ -338,7 +350,7 @@ export default class RemotelySavePlugin extends Plugin {
this.vaultRandomID, this.vaultRandomID,
profileID, profileID,
this.app.vault, this.app.vault,
this.settings.password, cipher,
this.settings.concurrency ?? 5, this.settings.concurrency ?? 5,
(key: string) => self.trash(key), (key: string) => self.trash(key),
this.settings.protectModifyPercentage ?? 50, this.settings.protectModifyPercentage ?? 50,
@@ -369,7 +381,8 @@ export default class RemotelySavePlugin extends Plugin {
realCounter, realCounter,
realTotalCount, realTotalCount,
pathName, pathName,
decision decision,
triggerSource
), ),
this.db this.db
); );
@@ -382,6 +395,8 @@ export default class RemotelySavePlugin extends Plugin {
} }
} }
cipher.closeResources();
if (this.settings.currLogLevel === "info") { if (this.settings.currLogLevel === "info") {
getNotice(t("syncrun_shortstep2")); getNotice(t("syncrun_shortstep2"));
} else { } else {
@@ -407,6 +422,7 @@ export default class RemotelySavePlugin extends Plugin {
this.updateLastSuccessSyncMsg(lastSuccessSyncMillis); this.updateLastSuccessSyncMsg(lastSuccessSyncMillis);
} }
this.syncEvent?.trigger("SYNC_DONE");
console.info( console.info(
`${ `${
this.manifest.id this.manifest.id
@@ -456,6 +472,8 @@ export default class RemotelySavePlugin extends Plugin {
this.currSyncMsg = ""; this.currSyncMsg = "";
this.syncEvent = new Events();
await this.loadSettings(); await this.loadSettings();
// MUST after loadSettings and before prepareDB // MUST after loadSettings and before prepareDB
@@ -720,8 +738,14 @@ export default class RemotelySavePlugin extends Plugin {
async () => this.syncRun("manual") async () => this.syncRun("manual")
); );
// Create Status Bar Item (not supported on mobile) this.enableMobileStatusBarIfSet();
if (!Platform.isMobileApp && this.settings.enableStatusBarInfo === true) {
// Create Status Bar Item
if (
(!Platform.isMobile ||
(Platform.isMobile && this.settings.enableMobileStatusBar)) &&
this.settings.enableStatusBarInfo === true
) {
const statusBarItem = this.addStatusBarItem(); const statusBarItem = this.addStatusBarItem();
this.statusBarElement = statusBarItem.createEl("span"); this.statusBarElement = statusBarItem.createEl("span");
this.statusBarElement.setAttribute("data-tooltip-position", "top"); this.statusBarElement.setAttribute("data-tooltip-position", "top");
@@ -797,6 +821,10 @@ export default class RemotelySavePlugin extends Plugin {
async onunload() { async onunload() {
console.info(`unloading plugin ${this.manifest.id}`); console.info(`unloading plugin ${this.manifest.id}`);
this.syncRibbon = undefined; this.syncRibbon = undefined;
if (this.appContainerObserver !== undefined) {
this.appContainerObserver.disconnect();
this.appContainerObserver = undefined;
}
if (this.oauth2Info !== undefined) { if (this.oauth2Info !== undefined) {
this.oauth2Info.helperModal = undefined; this.oauth2Info.helperModal = undefined;
this.oauth2Info = { this.oauth2Info = {
@@ -894,11 +922,39 @@ export default class RemotelySavePlugin extends Plugin {
this.settings.syncDirection = "bidirectional"; this.settings.syncDirection = "bidirectional";
} }
if (this.settings.obfuscateSettingFile === undefined) {
this.settings.obfuscateSettingFile = true;
}
if (this.settings.enableMobileStatusBar === undefined) {
this.settings.enableMobileStatusBar = false;
}
if (
this.settings.encryptionMethod === undefined ||
this.settings.encryptionMethod === "unknown"
) {
if (
this.settings.password === undefined ||
this.settings.password === ""
) {
// we have a preferred way
this.settings.encryptionMethod = "rclone-base64";
} else {
// likely to be inherited from the old version
this.settings.encryptionMethod = "openssl-base64";
}
}
await this.saveSettings(); await this.saveSettings();
} }
async saveSettings() { async saveSettings() {
await this.saveData(normalConfigToMessy(this.settings)); if (this.settings.obfuscateSettingFile) {
await this.saveData(normalConfigToMessy(this.settings));
} else {
await this.saveData(this.settings);
}
} }
/** /**
@@ -1057,7 +1113,7 @@ export default class RemotelySavePlugin extends Plugin {
) { ) {
this.app.workspace.onLayoutReady(() => { this.app.workspace.onLayoutReady(() => {
window.setTimeout(() => { window.setTimeout(() => {
this.syncRun("autoOnceInit"); this.syncRun("auto_once_init");
}, this.settings.initRunAfterMilliseconds); }, this.settings.initRunAfterMilliseconds);
}); });
} }
@@ -1083,48 +1139,66 @@ export default class RemotelySavePlugin extends Plugin {
}, scheduleTimeFromNow); }, scheduleTimeFromNow);
}; };
this.app.workspace.onLayoutReady(() => { const checkCurrFileModified = async (caller: "SYNC" | "FILE_CHANGES") => {
const intervalID = window.setInterval(() => { const currentFile = this.app.workspace.getActiveFile();
const currentFile = this.app.workspace.getActiveFile();
if (currentFile) { if (currentFile) {
// get the last modified time of the current file // get the last modified time of the current file
// if it has been modified within the last syncOnSaveAfterMilliseconds // if it has modified after lastSuccessSync
// then schedule a run for syncOnSaveAfterMilliseconds after it was modified // then schedule a run for syncOnSaveAfterMilliseconds after it was modified
const lastModified = currentFile.stat.mtime; const lastModified = currentFile.stat.mtime;
const currentTime = Date.now(); const lastSuccessSyncMillis = await getLastSuccessSyncTimeByVault(
if ( this.db,
currentTime - lastModified < this.vaultRandomID
this.settings!.syncOnSaveAfterMilliseconds! );
) { if (
if ( this.syncStatus === "idle" &&
!needToRunAgain && lastModified > lastSuccessSyncMillis &&
!runScheduled && !runScheduled
this.syncStatus === "idle" ) {
) { scheduleSyncOnSave(this.settings!.syncOnSaveAfterMilliseconds!);
const scheduleTimeFromNow = } else if (
this.settings!.syncOnSaveAfterMilliseconds! - this.syncStatus === "idle" &&
(currentTime - lastModified); needToRunAgain &&
scheduleSyncOnSave(scheduleTimeFromNow); !runScheduled
} else if ( ) {
needToRunAgain && scheduleSyncOnSave(this.settings!.syncOnSaveAfterMilliseconds!);
!runScheduled && needToRunAgain = false;
this.syncStatus === "idle" } else {
) { if (caller === "FILE_CHANGES") {
scheduleSyncOnSave(this.settings!.syncOnSaveAfterMilliseconds!); needToRunAgain = true;
needToRunAgain = false;
} else {
needToRunAgain = true;
}
} }
} }
}, this.settings.syncOnSaveAfterMilliseconds); }
this.syncOnSaveIntervalID = intervalID; };
this.registerInterval(intervalID);
this.app.workspace.onLayoutReady(() => {
// listen to sync done
this.registerEvent(
this.syncEvent?.on("SYNC_DONE", () => {
checkCurrFileModified("SYNC");
})!
);
// listen to current file save changes
this.registerEvent(
this.app.vault.on("modify", (x) => {
// console.debug(`event=modify! file=${x}`);
checkCurrFileModified("FILE_CHANGES");
})
);
}); });
} }
} }
enableMobileStatusBarIfSet() {
this.app.workspace.onLayoutReady(() => {
if (Platform.isMobile && this.settings.enableMobileStatusBar) {
this.appContainerObserver = changeMobileStatusBar("enable");
}
});
}
async saveAgreeToUseNewSyncAlgorithm() { async saveAgreeToUseNewSyncAlgorithm() {
this.settings.agreeToUseSyncV3 = true; this.settings.agreeToUseSyncV3 = true;
await this.saveSettings(); await this.saveSettings();
@@ -1134,9 +1208,10 @@ export default class RemotelySavePlugin extends Plugin {
i: number, i: number,
totalCount: number, totalCount: number,
pathName: string, pathName: string,
decision: string decision: string,
triggerSource: SyncTriggerSourceType
) { ) {
const msg = `syncing progress=${i}/${totalCount},decision=${decision},path=${pathName}`; const msg = `syncing progress=${i}/${totalCount},decision=${decision},path=${pathName},source=${triggerSource}`;
this.currSyncMsg = msg; this.currSyncMsg = msg;
} }
+141 -1
View File
@@ -1,4 +1,4 @@
import { Vault } from "obsidian"; import { Platform, Vault } from "obsidian";
import * as path from "path"; import * as path from "path";
import { base32, base64url } from "rfc4648"; import { base32, base64url } from "rfc4648";
@@ -118,6 +118,12 @@ export const base64ToArrayBuffer = (b64text: string) => {
return bufferToArrayBuffer(Buffer.from(b64text, "base64")); return bufferToArrayBuffer(Buffer.from(b64text, "base64"));
}; };
export const copyArrayBuffer = (src: ArrayBuffer) => {
var dst = new ArrayBuffer(src.byteLength);
new Uint8Array(dst).set(new Uint8Array(src));
return dst;
};
/** /**
* https://stackoverflow.com/questions/43131242 * https://stackoverflow.com/questions/43131242
* @param hex * @param hex
@@ -159,6 +165,9 @@ export const base64ToBase64url = (a: string, pad: boolean = false) => {
* @param a * @param a
*/ */
export const isVaildText = (a: string) => { export const isVaildText = (a: string) => {
if (a === undefined) {
return false;
}
// If the regex matches, the string is invalid. // If the regex matches, the string is invalid.
return !XRegExp("\\p{Cc}|\\p{Cf}|\\p{Co}|\\p{Cn}|\\p{Zl}|\\p{Zp}", "A").test( return !XRegExp("\\p{Cc}|\\p{Cf}|\\p{Co}|\\p{Cn}|\\p{Zl}|\\p{Zp}", "A").test(
a a
@@ -503,3 +512,134 @@ export const stringToFragment = (string: string) => {
wrapper.innerHTML = string; wrapper.innerHTML = string;
return wrapper.content; return wrapper.content;
}; };
/**
* https://forum.obsidian.md/t/css-to-show-status-bar-on-mobile-devices/77185
* @param op
*/
export const changeMobileStatusBar = (
op: "enable" | "disable",
oldAppContainerObserver?: MutationObserver
) => {
const appContainer = document.getElementsByClassName("app-container")[0] as
| HTMLElement
| undefined;
const statusbar = document.querySelector(
".is-mobile .app-container .status-bar"
) as HTMLElement | undefined;
if (appContainer === undefined || statusbar === undefined) {
// give up, exit
console.warn(`give up watching appContainer for statusbar`);
console.warn(`appContainer=${appContainer}, statusbar=${statusbar}`);
return undefined;
}
if (op === "enable") {
const callback = async (
mutationList: MutationRecord[],
observer: MutationObserver
) => {
for (const mutation of mutationList) {
// console.debug(mutation);
if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
const k = mutation.addedNodes[0] as Element;
if (
k.className.contains("mobile-navbar") ||
k.className.contains("mobile-toolbar")
) {
// have to wait, otherwise the height is not correct??
await new Promise((resolve) => setTimeout(resolve, 300));
const height = window
.getComputedStyle(k as Element)
.getPropertyValue("height");
statusbar.style.setProperty("display", "flex");
statusbar.style.setProperty("margin-bottom", height);
}
}
}
};
const observer = new MutationObserver(callback);
observer.observe(appContainer, {
attributes: false,
childList: true,
characterData: false,
subtree: false,
});
try {
// init, manual call
const navBar = document.getElementsByClassName(
"mobile-navbar"
)[0] as HTMLElement;
// thanks to community's solution
const height = window.getComputedStyle(navBar).getPropertyValue("height");
statusbar.style.setProperty("display", "flex");
statusbar.style.setProperty("margin-bottom", height);
} catch (e) {
// skip
}
return observer;
} else {
if (oldAppContainerObserver !== undefined) {
console.debug(`disconnect oldAppContainerObserver`);
oldAppContainerObserver.disconnect();
oldAppContainerObserver = undefined;
}
statusbar.style.removeProperty("display");
statusbar.style.removeProperty("margin-bottom");
return undefined;
}
};
/**
* https://github.com/remotely-save/remotely-save/issues/567
* https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Case-Sensitivity-in-API-2/td-p/191279
* @param entities
*/
export const fixEntityListCasesInplace = (entities: { keyRaw: string }[]) => {
entities.sort((a, b) => a.keyRaw.length - b.keyRaw.length);
// console.log(JSON.stringify(entities,null,2));
const caseMapping: Record<string, string> = { "": "" };
for (const e of entities) {
// console.log(`looking for: ${JSON.stringify(e, null, 2)}`);
let parentFolder = getParentFolder(e.keyRaw);
if (parentFolder === "/") {
parentFolder = "";
}
const parentFolderLower = parentFolder.toLocaleLowerCase();
const segs = e.keyRaw.split("/");
if (e.keyRaw.endsWith("/")) {
// folder
if (caseMapping.hasOwnProperty(parentFolderLower)) {
const newKeyRaw = `${caseMapping[parentFolderLower]}${segs
.slice(-2)
.join("/")}`;
caseMapping[newKeyRaw.toLocaleLowerCase()] = newKeyRaw;
e.keyRaw = newKeyRaw;
// console.log(JSON.stringify(caseMapping,null,2));
continue;
} else {
throw Error(`${parentFolder} doesn't have cases record??`);
}
} else {
// file
if (caseMapping.hasOwnProperty(parentFolderLower)) {
const newKeyRaw = `${caseMapping[parentFolderLower]}${segs
.slice(-1)
.join("/")}`;
e.keyRaw = newKeyRaw;
continue;
} else {
throw Error(`${parentFolder} doesn't have cases record??`);
}
}
}
return entities;
};
+21 -18
View File
@@ -12,6 +12,7 @@ import * as dropbox from "./remoteForDropbox";
import * as onedrive from "./remoteForOnedrive"; import * as onedrive from "./remoteForOnedrive";
import * as s3 from "./remoteForS3"; import * as s3 from "./remoteForS3";
import * as webdav from "./remoteForWebdav"; import * as webdav from "./remoteForWebdav";
import { Cipher } from "./encryptUnified";
export class RemoteClient { export class RemoteClient {
readonly serviceType: SUPPORTED_SERVICES_TYPE; readonly serviceType: SUPPORTED_SERVICES_TYPE;
@@ -105,8 +106,8 @@ export class RemoteClient {
uploadToRemote = async ( uploadToRemote = async (
fileOrFolderPath: string, fileOrFolderPath: string,
vault: Vault | undefined, vault: Vault | undefined,
isRecursively: boolean = false, isRecursively: boolean,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "", remoteEncryptedKey: string = "",
foldersCreatedBefore: Set<string> | undefined = undefined, foldersCreatedBefore: Set<string> | undefined = undefined,
uploadRaw: boolean = false, uploadRaw: boolean = false,
@@ -119,7 +120,7 @@ export class RemoteClient {
fileOrFolderPath, fileOrFolderPath,
vault, vault,
isRecursively, isRecursively,
password, cipher,
remoteEncryptedKey, remoteEncryptedKey,
uploadRaw, uploadRaw,
rawContent rawContent
@@ -130,7 +131,7 @@ export class RemoteClient {
fileOrFolderPath, fileOrFolderPath,
vault, vault,
isRecursively, isRecursively,
password, cipher,
remoteEncryptedKey, remoteEncryptedKey,
uploadRaw, uploadRaw,
rawContent rawContent
@@ -141,7 +142,7 @@ export class RemoteClient {
fileOrFolderPath, fileOrFolderPath,
vault, vault,
isRecursively, isRecursively,
password, cipher,
remoteEncryptedKey, remoteEncryptedKey,
foldersCreatedBefore, foldersCreatedBefore,
uploadRaw, uploadRaw,
@@ -153,7 +154,7 @@ export class RemoteClient {
fileOrFolderPath, fileOrFolderPath,
vault, vault,
isRecursively, isRecursively,
password, cipher,
remoteEncryptedKey, remoteEncryptedKey,
foldersCreatedBefore, foldersCreatedBefore,
uploadRaw, uploadRaw,
@@ -185,7 +186,7 @@ export class RemoteClient {
fileOrFolderPath: string, fileOrFolderPath: string,
vault: Vault, vault: Vault,
mtime: number, mtime: number,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "", remoteEncryptedKey: string = "",
skipSaving: boolean = false skipSaving: boolean = false
) => { ) => {
@@ -196,7 +197,7 @@ export class RemoteClient {
fileOrFolderPath, fileOrFolderPath,
vault, vault,
mtime, mtime,
password, cipher,
remoteEncryptedKey, remoteEncryptedKey,
skipSaving skipSaving
); );
@@ -206,7 +207,7 @@ export class RemoteClient {
fileOrFolderPath, fileOrFolderPath,
vault, vault,
mtime, mtime,
password, cipher,
remoteEncryptedKey, remoteEncryptedKey,
skipSaving skipSaving
); );
@@ -216,7 +217,7 @@ export class RemoteClient {
fileOrFolderPath, fileOrFolderPath,
vault, vault,
mtime, mtime,
password, cipher,
remoteEncryptedKey, remoteEncryptedKey,
skipSaving skipSaving
); );
@@ -226,7 +227,7 @@ export class RemoteClient {
fileOrFolderPath, fileOrFolderPath,
vault, vault,
mtime, mtime,
password, cipher,
remoteEncryptedKey, remoteEncryptedKey,
skipSaving skipSaving
); );
@@ -237,36 +238,38 @@ export class RemoteClient {
deleteFromRemote = async ( deleteFromRemote = async (
fileOrFolderPath: string, fileOrFolderPath: string,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "" remoteEncryptedKey: string = "",
synthesizedFolder: boolean = false
) => { ) => {
if (this.serviceType === "s3") { if (this.serviceType === "s3") {
return await s3.deleteFromRemote( return await s3.deleteFromRemote(
s3.getS3Client(this.s3Config!), s3.getS3Client(this.s3Config!),
this.s3Config!, this.s3Config!,
fileOrFolderPath, fileOrFolderPath,
password, cipher,
remoteEncryptedKey remoteEncryptedKey,
synthesizedFolder
); );
} else if (this.serviceType === "webdav") { } else if (this.serviceType === "webdav") {
return await webdav.deleteFromRemote( return await webdav.deleteFromRemote(
this.webdavClient!, this.webdavClient!,
fileOrFolderPath, fileOrFolderPath,
password, cipher,
remoteEncryptedKey remoteEncryptedKey
); );
} else if (this.serviceType === "dropbox") { } else if (this.serviceType === "dropbox") {
return await dropbox.deleteFromRemote( return await dropbox.deleteFromRemote(
this.dropboxClient!, this.dropboxClient!,
fileOrFolderPath, fileOrFolderPath,
password, cipher,
remoteEncryptedKey remoteEncryptedKey
); );
} else if (this.serviceType === "onedrive") { } else if (this.serviceType === "onedrive") {
return await onedrive.deleteFromRemote( return await onedrive.deleteFromRemote(
this.onedriveClient!, this.onedriveClient!,
fileOrFolderPath, fileOrFolderPath,
password, cipher,
remoteEncryptedKey remoteEncryptedKey
); );
} else { } else {
+21 -17
View File
@@ -10,14 +10,15 @@ import {
OAUTH2_FORCE_EXPIRE_MILLISECONDS, OAUTH2_FORCE_EXPIRE_MILLISECONDS,
UploadedType, UploadedType,
} from "./baseTypes"; } from "./baseTypes";
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
import { import {
bufferToArrayBuffer, bufferToArrayBuffer,
fixEntityListCasesInplace,
getFolderLevels, getFolderLevels,
hasEmojiInText, hasEmojiInText,
headersToRecord, headersToRecord,
mkdirpInVault, mkdirpInVault,
} from "./misc"; } from "./misc";
import { Cipher } from "./encryptUnified";
export { Dropbox } from "dropbox"; export { Dropbox } from "dropbox";
@@ -451,8 +452,8 @@ export const uploadToRemote = async (
client: WrappedDropboxClient, client: WrappedDropboxClient,
fileOrFolderPath: string, fileOrFolderPath: string,
vault: Vault | undefined, vault: Vault | undefined,
isRecursively: boolean = false, isRecursively: boolean,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "", remoteEncryptedKey: string = "",
foldersCreatedBefore: Set<string> | undefined = undefined, foldersCreatedBefore: Set<string> | undefined = undefined,
uploadRaw: boolean = false, uploadRaw: boolean = false,
@@ -463,7 +464,7 @@ export const uploadToRemote = async (
await client.init(); await client.init();
let uploadFile = fileOrFolderPath; let uploadFile = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
if (remoteEncryptedKey === undefined || remoteEncryptedKey === "") { if (remoteEncryptedKey === undefined || remoteEncryptedKey === "") {
throw Error( throw Error(
`uploadToRemote(dropbox) you have password but remoteEncryptedKey is empty!` `uploadToRemote(dropbox) you have password but remoteEncryptedKey is empty!`
@@ -483,8 +484,8 @@ export const uploadToRemote = async (
let ctime = 0; let ctime = 0;
const s = await vault?.adapter?.stat(fileOrFolderPath); const s = await vault?.adapter?.stat(fileOrFolderPath);
if (s !== undefined && s !== null) { if (s !== undefined && s !== null) {
mtime = Math.round(s.mtime / 1000.0) * 1000; mtime = Math.floor(s.mtime / 1000.0) * 1000;
ctime = Math.round(s.ctime / 1000.0) * 1000; ctime = Math.floor(s.ctime / 1000.0) * 1000;
} }
const mtimeStr = new Date(mtime).toISOString().replace(/\.\d{3}Z$/, "Z"); const mtimeStr = new Date(mtime).toISOString().replace(/\.\d{3}Z$/, "Z");
@@ -497,8 +498,8 @@ export const uploadToRemote = async (
throw Error(`you specify uploadRaw, but you also provide a folder key!`); throw Error(`you specify uploadRaw, but you also provide a folder key!`);
} }
// folder // folder
if (password === "") { if (cipher.isPasswordEmpty() || cipher.isFolderAware()) {
// if not encrypted, mkdir a remote folder // if not encrypted, || encrypted isFolderAware, mkdir a remote folder
if (foldersCreatedBefore?.has(uploadFile)) { if (foldersCreatedBefore?.has(uploadFile)) {
// created, pass // created, pass
} else { } else {
@@ -530,7 +531,8 @@ export const uploadToRemote = async (
mtimeCli: mtime, mtimeCli: mtime,
}; };
} else { } else {
// if encrypted, upload a fake file with the encrypted file name // if encrypted && !isFolderAware(),
// upload a fake file with the encrypted file name
await retryReq( await retryReq(
() => () =>
client.dropbox.filesUpload({ client.dropbox.filesUpload({
@@ -564,8 +566,8 @@ export const uploadToRemote = async (
localContent = await vault.adapter.readBinary(fileOrFolderPath); localContent = await vault.adapter.readBinary(fileOrFolderPath);
} }
let remoteContent = localContent; let remoteContent = localContent;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
remoteContent = await encryptArrayBuffer(localContent, password); remoteContent = await cipher.encryptContent(localContent);
} }
// in dropbox, we don't need to create folders before uploading! cool! // in dropbox, we don't need to create folders before uploading! cool!
// TODO: filesUploadSession for larger files (>=150 MB) // TODO: filesUploadSession for larger files (>=150 MB)
@@ -634,6 +636,8 @@ export const listAllFromRemote = async (client: WrappedDropboxClient) => {
unifiedContents.push(...unifiedContents2); unifiedContents.push(...unifiedContents2);
} }
fixEntityListCasesInplace(unifiedContents);
return unifiedContents; return unifiedContents;
}; };
@@ -670,7 +674,7 @@ export const downloadFromRemote = async (
fileOrFolderPath: string, fileOrFolderPath: string,
vault: Vault, vault: Vault,
mtime: number, mtime: number,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "", remoteEncryptedKey: string = "",
skipSaving: boolean = false skipSaving: boolean = false
) => { ) => {
@@ -691,14 +695,14 @@ export const downloadFromRemote = async (
return new ArrayBuffer(0); return new ArrayBuffer(0);
} else { } else {
let downloadFile = fileOrFolderPath; let downloadFile = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
downloadFile = remoteEncryptedKey; downloadFile = remoteEncryptedKey;
} }
downloadFile = getDropboxPath(downloadFile, client.remoteBaseDir); downloadFile = getDropboxPath(downloadFile, client.remoteBaseDir);
const remoteContent = await downloadFromRemoteRaw(client, downloadFile); const remoteContent = await downloadFromRemoteRaw(client, downloadFile);
let localContent = remoteContent; let localContent = remoteContent;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
localContent = await decryptArrayBuffer(remoteContent, password); localContent = await cipher.decryptContent(remoteContent);
} }
if (!skipSaving) { if (!skipSaving) {
await vault.adapter.writeBinary(fileOrFolderPath, localContent, { await vault.adapter.writeBinary(fileOrFolderPath, localContent, {
@@ -712,14 +716,14 @@ export const downloadFromRemote = async (
export const deleteFromRemote = async ( export const deleteFromRemote = async (
client: WrappedDropboxClient, client: WrappedDropboxClient,
fileOrFolderPath: string, fileOrFolderPath: string,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "" remoteEncryptedKey: string = ""
) => { ) => {
if (fileOrFolderPath === "/") { if (fileOrFolderPath === "/") {
return; return;
} }
let remoteFileName = fileOrFolderPath; let remoteFileName = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
remoteFileName = remoteEncryptedKey; remoteFileName = remoteEncryptedKey;
} }
remoteFileName = getDropboxPath(remoteFileName, client.remoteBaseDir); remoteFileName = getDropboxPath(remoteFileName, client.remoteBaseDir);
+26 -20
View File
@@ -17,13 +17,13 @@ import {
Entity, Entity,
UploadedType, UploadedType,
} from "./baseTypes"; } from "./baseTypes";
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
import { import {
bufferToArrayBuffer, bufferToArrayBuffer,
getRandomArrayBuffer, getRandomArrayBuffer,
getRandomIntInclusive, getRandomIntInclusive,
mkdirpInVault, mkdirpInVault,
} from "./misc"; } from "./misc";
import { Cipher } from "./encryptUnified";
const SCOPES = ["User.Read", "Files.ReadWrite.AppFolder", "offline_access"]; const SCOPES = ["User.Read", "Files.ReadWrite.AppFolder", "offline_access"];
const REDIRECT_URI = `obsidian://${COMMAND_CALLBACK_ONEDRIVE}`; const REDIRECT_URI = `obsidian://${COMMAND_CALLBACK_ONEDRIVE}`;
@@ -471,6 +471,11 @@ export class WrappedOnedriveClient {
const pathFrag = encodeURI(pathFragOrig); const pathFrag = encodeURI(pathFragOrig);
theUrl = `${API_PREFIX}${pathFrag}`; theUrl = `${API_PREFIX}${pathFrag}`;
} }
// we want to support file name with hash #
// because every url we construct here do not contain the # symbol
// thus it should be safe to directly replace the character
theUrl = theUrl.replace(/#/g, "%23");
// console.debug(`building url: [${pathFragOrig}] => [${theUrl}]`)
return theUrl; return theUrl;
}; };
@@ -550,7 +555,7 @@ export class WrappedOnedriveClient {
// 20220401: On Android, requestUrl has issue that text becomes base64. // 20220401: On Android, requestUrl has issue that text becomes base64.
// Use fetch everywhere instead! // Use fetch everywhere instead!
if (false /*VALID_REQURL*/) { if (false /*VALID_REQURL*/) {
await requestUrl({ const res = await requestUrl({
url: theUrl, url: theUrl,
method: "PUT", method: "PUT",
body: payload, body: payload,
@@ -560,8 +565,9 @@ export class WrappedOnedriveClient {
Authorization: `Bearer ${await this.authGetter.getAccessToken()}`, Authorization: `Bearer ${await this.authGetter.getAccessToken()}`,
}, },
}); });
return res.json as DriveItem | UploadSession;
} else { } else {
await fetch(theUrl, { const res = await fetch(theUrl, {
method: "PUT", method: "PUT",
body: payload, body: payload,
headers: { headers: {
@@ -569,6 +575,7 @@ export class WrappedOnedriveClient {
Authorization: `Bearer ${await this.authGetter.getAccessToken()}`, Authorization: `Bearer ${await this.authGetter.getAccessToken()}`,
}, },
}); });
return (await res.json()) as DriveItem | UploadSession;
} }
}; };
@@ -694,8 +701,8 @@ export const uploadToRemote = async (
client: WrappedOnedriveClient, client: WrappedOnedriveClient,
fileOrFolderPath: string, fileOrFolderPath: string,
vault: Vault | undefined, vault: Vault | undefined,
isRecursively: boolean = false, isRecursively: boolean,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "", remoteEncryptedKey: string = "",
foldersCreatedBefore: Set<string> | undefined = undefined, foldersCreatedBefore: Set<string> | undefined = undefined,
uploadRaw: boolean = false, uploadRaw: boolean = false,
@@ -704,7 +711,7 @@ export const uploadToRemote = async (
await client.init(); await client.init();
let uploadFile = fileOrFolderPath; let uploadFile = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
if (remoteEncryptedKey === undefined || remoteEncryptedKey === "") { if (remoteEncryptedKey === undefined || remoteEncryptedKey === "") {
throw Error( throw Error(
`uploadToRemote(onedrive) you have password but remoteEncryptedKey is empty!` `uploadToRemote(onedrive) you have password but remoteEncryptedKey is empty!`
@@ -734,8 +741,8 @@ export const uploadToRemote = async (
throw Error(`you specify uploadRaw, but you also provide a folder key!`); throw Error(`you specify uploadRaw, but you also provide a folder key!`);
} }
// folder // folder
if (password === "") { if (cipher.isPasswordEmpty() || cipher.isFolderAware()) {
// if not encrypted, mkdir a remote folder // if not encrypted, || encrypted isFolderAware, mkdir a remote folder
if (foldersCreatedBefore?.has(uploadFile)) { if (foldersCreatedBefore?.has(uploadFile)) {
// created, pass // created, pass
} else { } else {
@@ -763,16 +770,15 @@ export const uploadToRemote = async (
mtimeCli: mtime, mtimeCli: mtime,
}; };
} else { } else {
// if encrypted, // if encrypted && !isFolderAware(),
// upload a fake, random-size file // upload a fake, random-size file
// with the encrypted file name // with the encrypted file name
const byteLengthRandom = getRandomIntInclusive( const byteLengthRandom = getRandomIntInclusive(
1, 1,
65536 /* max allowed */ 65536 /* max allowed */
); );
const arrBufRandom = await encryptArrayBuffer( const arrBufRandom = await cipher.encryptContent(
getRandomArrayBuffer(byteLengthRandom), getRandomArrayBuffer(byteLengthRandom)
password
); );
// an encrypted folder is always small, we just use put here // an encrypted folder is always small, we just use put here
@@ -816,8 +822,8 @@ export const uploadToRemote = async (
localContent = await vault.adapter.readBinary(fileOrFolderPath); localContent = await vault.adapter.readBinary(fileOrFolderPath);
} }
let remoteContent = localContent; let remoteContent = localContent;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
remoteContent = await encryptArrayBuffer(localContent, password); remoteContent = await cipher.encryptContent(localContent);
} }
// no need to create parent folders firstly, cool! // no need to create parent folders firstly, cool!
@@ -930,7 +936,7 @@ export const downloadFromRemote = async (
fileOrFolderPath: string, fileOrFolderPath: string,
vault: Vault, vault: Vault,
mtime: number, mtime: number,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "", remoteEncryptedKey: string = "",
skipSaving: boolean = false skipSaving: boolean = false
) => { ) => {
@@ -948,14 +954,14 @@ export const downloadFromRemote = async (
return new ArrayBuffer(0); return new ArrayBuffer(0);
} else { } else {
let downloadFile = fileOrFolderPath; let downloadFile = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
downloadFile = remoteEncryptedKey; downloadFile = remoteEncryptedKey;
} }
downloadFile = getOnedrivePath(downloadFile, client.remoteBaseDir); downloadFile = getOnedrivePath(downloadFile, client.remoteBaseDir);
const remoteContent = await downloadFromRemoteRaw(client, downloadFile); const remoteContent = await downloadFromRemoteRaw(client, downloadFile);
let localContent = remoteContent; let localContent = remoteContent;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
localContent = await decryptArrayBuffer(remoteContent, password); localContent = await cipher.decryptContent(remoteContent);
} }
if (!skipSaving) { if (!skipSaving) {
await vault.adapter.writeBinary(fileOrFolderPath, localContent, { await vault.adapter.writeBinary(fileOrFolderPath, localContent, {
@@ -969,14 +975,14 @@ export const downloadFromRemote = async (
export const deleteFromRemote = async ( export const deleteFromRemote = async (
client: WrappedOnedriveClient, client: WrappedOnedriveClient,
fileOrFolderPath: string, fileOrFolderPath: string,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "" remoteEncryptedKey: string = ""
) => { ) => {
if (fileOrFolderPath === "/") { if (fileOrFolderPath === "/") {
return; return;
} }
let remoteFileName = fileOrFolderPath; let remoteFileName = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
remoteFileName = remoteEncryptedKey; remoteFileName = remoteEncryptedKey;
} }
remoteFileName = getOnedrivePath(remoteFileName, client.remoteBaseDir); remoteFileName = getOnedrivePath(remoteFileName, client.remoteBaseDir);
+57 -28
View File
@@ -22,7 +22,7 @@ import { buildQueryString } from "@smithy/querystring-builder";
import { HeaderBag, HttpHandlerOptions, Provider } from "@aws-sdk/types"; import { HeaderBag, HttpHandlerOptions, Provider } from "@aws-sdk/types";
import { Buffer } from "buffer"; import { Buffer } from "buffer";
import * as mime from "mime-types"; import * as mime from "mime-types";
import { Vault, requestUrl, RequestUrlParam } from "obsidian"; import { Vault, requestUrl, RequestUrlParam, Platform } from "obsidian";
import { Readable } from "stream"; import { Readable } from "stream";
import * as path from "path"; import * as path from "path";
import AggregateError from "aggregate-error"; import AggregateError from "aggregate-error";
@@ -33,7 +33,6 @@ import {
UploadedType, UploadedType,
VALID_REQURL, VALID_REQURL,
} from "./baseTypes"; } from "./baseTypes";
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
import { import {
arrayBufferToBuffer, arrayBufferToBuffer,
bufferToArrayBuffer, bufferToArrayBuffer,
@@ -43,6 +42,7 @@ import {
export { S3Client } from "@aws-sdk/client-s3"; export { S3Client } from "@aws-sdk/client-s3";
import PQueue from "p-queue"; import PQueue from "p-queue";
import { Cipher } from "./encryptUnified";
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// special handler using Obsidian requestUrl // special handler using Obsidian requestUrl
@@ -233,7 +233,14 @@ const fromS3ObjectToEntity = (
if (x.Key! in mtimeRecords) { if (x.Key! in mtimeRecords) {
const m2 = mtimeRecords[x.Key!]; const m2 = mtimeRecords[x.Key!];
if (m2 !== 0) { if (m2 !== 0) {
mtimeCli = m2; // to be compatible with RClone, we read and store the time in seconds in new version!
if (m2 >= 1000000000000) {
// it's a millsecond, uploaded by old codes..
mtimeCli = m2;
} else {
// it's a second, uploaded by new codes of the plugin from March 24, 2024
mtimeCli = m2 * 1000;
}
} }
} }
const key = getLocalNoPrefixPath(x.Key!, remotePrefix); const key = getLocalNoPrefixPath(x.Key!, remotePrefix);
@@ -243,6 +250,7 @@ const fromS3ObjectToEntity = (
mtimeCli: mtimeCli, mtimeCli: mtimeCli,
sizeRaw: x.Size!, sizeRaw: x.Size!,
etag: x.ETag, etag: x.ETag,
synthesizedFolder: false,
}; };
return r; return r;
}; };
@@ -257,11 +265,18 @@ const fromS3HeadObjectToEntity = (
const mtimeSvr = Math.floor(x.LastModified!.valueOf() / 1000.0) * 1000; const mtimeSvr = Math.floor(x.LastModified!.valueOf() / 1000.0) * 1000;
let mtimeCli = mtimeSvr; let mtimeCli = mtimeSvr;
if (x.Metadata !== undefined) { if (x.Metadata !== undefined) {
const m2 = Math.round( const m2 = Math.floor(
parseFloat(x.Metadata.mtime || x.Metadata.MTime || "0") parseFloat(x.Metadata.mtime || x.Metadata.MTime || "0")
); );
if (m2 !== 0) { if (m2 !== 0) {
mtimeCli = m2; // to be compatible with RClone, we read and store the time in seconds in new version!
if (m2 >= 1000000000000) {
// it's a millsecond, uploaded by old codes..
mtimeCli = m2;
} else {
// it's a second, uploaded by new codes of the plugin from March 24, 2024
mtimeCli = m2 * 1000;
}
} }
} }
// console.debug( // console.debug(
@@ -358,8 +373,8 @@ export const uploadToRemote = async (
s3Config: S3Config, s3Config: S3Config,
fileOrFolderPath: string, fileOrFolderPath: string,
vault: Vault | undefined, vault: Vault | undefined,
isRecursively: boolean = false, isRecursively: boolean,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "", remoteEncryptedKey: string = "",
uploadRaw: boolean = false, uploadRaw: boolean = false,
rawContent: string | ArrayBuffer = "", rawContent: string | ArrayBuffer = "",
@@ -368,7 +383,7 @@ export const uploadToRemote = async (
): Promise<UploadedType> => { ): Promise<UploadedType> => {
console.debug(`uploading ${fileOrFolderPath}`); console.debug(`uploading ${fileOrFolderPath}`);
let uploadFile = fileOrFolderPath; let uploadFile = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
if (remoteEncryptedKey === undefined || remoteEncryptedKey === "") { if (remoteEncryptedKey === undefined || remoteEncryptedKey === "") {
throw Error( throw Error(
`uploadToRemote(s3) you have password but remoteEncryptedKey is empty!` `uploadToRemote(s3) you have password but remoteEncryptedKey is empty!`
@@ -402,8 +417,8 @@ export const uploadToRemote = async (
Body: "", Body: "",
ContentType: contentType, ContentType: contentType,
Metadata: { Metadata: {
MTime: `${mtime}`, MTime: `${mtime / 1000.0}`,
CTime: `${ctime}`, CTime: `${ctime / 1000.0}`,
}, },
}) })
); );
@@ -416,7 +431,7 @@ export const uploadToRemote = async (
// file // file
// we ignore isRecursively parameter here // we ignore isRecursively parameter here
let contentType = DEFAULT_CONTENT_TYPE; let contentType = DEFAULT_CONTENT_TYPE;
if (password === "") { if (cipher.isPasswordEmpty()) {
contentType = contentType =
mime.contentType( mime.contentType(
mime.lookup(fileOrFolderPath) || DEFAULT_CONTENT_TYPE mime.lookup(fileOrFolderPath) || DEFAULT_CONTENT_TYPE
@@ -447,8 +462,8 @@ export const uploadToRemote = async (
} }
} }
let remoteContent = localContent; let remoteContent = localContent;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
remoteContent = await encryptArrayBuffer(localContent, password); remoteContent = await cipher.encryptContent(localContent);
} }
const bytesIn5MB = 5242880; const bytesIn5MB = 5242880;
@@ -465,8 +480,8 @@ export const uploadToRemote = async (
Body: body, Body: body,
ContentType: contentType, ContentType: contentType,
Metadata: { Metadata: {
MTime: `${mtime}`, MTime: `${mtime / 1000.0}`,
CTime: `${ctime}`, CTime: `${ctime / 1000.0}`,
}, },
}, },
}); });
@@ -539,12 +554,12 @@ const listFromRemoteRaw = async (
if (rspHead.Metadata === undefined) { if (rspHead.Metadata === undefined) {
// pass // pass
} else { } else {
mtimeRecords[content.Key!] = Math.round( mtimeRecords[content.Key!] = Math.floor(
parseFloat( parseFloat(
rspHead.Metadata.mtime || rspHead.Metadata.MTime || "0" rspHead.Metadata.mtime || rspHead.Metadata.MTime || "0"
) )
); );
ctimeRecords[content.Key!] = Math.round( ctimeRecords[content.Key!] = Math.floor(
parseFloat( parseFloat(
rspHead.Metadata.ctime || rspHead.Metadata.CTime || "0" rspHead.Metadata.ctime || rspHead.Metadata.CTime || "0"
) )
@@ -585,7 +600,10 @@ export const listAllFromRemote = async (
s3Client: S3Client, s3Client: S3Client,
s3Config: S3Config s3Config: S3Config
) => { ) => {
return await listFromRemoteRaw(s3Client, s3Config, s3Config.remotePrefix); const res = (
await listFromRemoteRaw(s3Client, s3Config, s3Config.remotePrefix)
).filter((x) => x.keyRaw !== "" && x.keyRaw !== "/");
return res;
}; };
/** /**
@@ -645,8 +663,8 @@ export const downloadFromRemote = async (
fileOrFolderPath: string, fileOrFolderPath: string,
vault: Vault, vault: Vault,
mtime: number, mtime: number,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "", remoteEncryptedKey: string,
skipSaving: boolean = false skipSaving: boolean = false
) => { ) => {
const isFolder = fileOrFolderPath.endsWith("/"); const isFolder = fileOrFolderPath.endsWith("/");
@@ -664,7 +682,7 @@ export const downloadFromRemote = async (
return new ArrayBuffer(0); return new ArrayBuffer(0);
} else { } else {
let downloadFile = fileOrFolderPath; let downloadFile = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
downloadFile = remoteEncryptedKey; downloadFile = remoteEncryptedKey;
} }
downloadFile = getRemoteWithPrefixPath( downloadFile = getRemoteWithPrefixPath(
@@ -677,8 +695,8 @@ export const downloadFromRemote = async (
downloadFile downloadFile
); );
let localContent = remoteContent; let localContent = remoteContent;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
localContent = await decryptArrayBuffer(remoteContent, password); localContent = await cipher.decryptContent(remoteContent);
} }
if (!skipSaving) { if (!skipSaving) {
await vault.adapter.writeBinary(fileOrFolderPath, localContent, { await vault.adapter.writeBinary(fileOrFolderPath, localContent, {
@@ -700,14 +718,18 @@ export const deleteFromRemote = async (
s3Client: S3Client, s3Client: S3Client,
s3Config: S3Config, s3Config: S3Config,
fileOrFolderPath: string, fileOrFolderPath: string,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "" remoteEncryptedKey: string = "",
synthesizedFolder: boolean = false
) => { ) => {
if (fileOrFolderPath === "/") { if (fileOrFolderPath === "/") {
return; return;
} }
if (synthesizedFolder) {
return;
}
let remoteFileName = fileOrFolderPath; let remoteFileName = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
remoteFileName = remoteEncryptedKey; remoteFileName = remoteEncryptedKey;
} }
remoteFileName = getRemoteWithPrefixPath( remoteFileName = getRemoteWithPrefixPath(
@@ -721,7 +743,7 @@ export const deleteFromRemote = async (
}) })
); );
if (fileOrFolderPath.endsWith("/") && password === "") { if (fileOrFolderPath.endsWith("/") && cipher.isPasswordEmpty()) {
const x = await listFromRemoteRaw(s3Client, s3Config, remoteFileName); const x = await listFromRemoteRaw(s3Client, s3Config, remoteFileName);
x.forEach(async (element) => { x.forEach(async (element) => {
await s3Client.send( await s3Client.send(
@@ -731,7 +753,7 @@ export const deleteFromRemote = async (
}) })
); );
}); });
} else if (fileOrFolderPath.endsWith("/") && password !== "") { } else if (fileOrFolderPath.endsWith("/") && !cipher.isPasswordEmpty()) {
// TODO // TODO
} else { } else {
// pass // pass
@@ -756,6 +778,13 @@ export const checkConnectivity = async (
callbackFunc?: any callbackFunc?: any
) => { ) => {
try { try {
// TODO: no universal way now, just check this in connectivity
if (Platform.isIosApp && s3Config.s3Endpoint.startsWith("http://")) {
throw Error(
`Your s3 endpoint could only be https, not http, because of the iOS restriction.`
);
}
// const results = await s3Client.send( // const results = await s3Client.send(
// new HeadBucketCommand({ Bucket: s3Config.s3BucketName }) // new HeadBucketCommand({ Bucket: s3Config.s3BucketName })
// ); // );
+83 -87
View File
@@ -1,13 +1,14 @@
import { Buffer } from "buffer"; import { Buffer } from "buffer";
import { Vault, requestUrl } from "obsidian"; import { Platform, Vault, requestUrl } from "obsidian";
import { Queue } from "@fyears/tsqueue"; import { Queue } from "@fyears/tsqueue";
import chunk from "lodash/chunk"; import chunk from "lodash/chunk";
import flatten from "lodash/flatten"; import flatten from "lodash/flatten";
import cloneDeep from "lodash/cloneDeep";
import { getReasonPhrase } from "http-status-codes"; import { getReasonPhrase } from "http-status-codes";
import { Entity, UploadedType, VALID_REQURL, WebdavConfig } from "./baseTypes"; import { Entity, UploadedType, VALID_REQURL, WebdavConfig } from "./baseTypes";
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
import { bufferToArrayBuffer, getPathFolder, mkdirpInVault } from "./misc"; import { bufferToArrayBuffer, getPathFolder, mkdirpInVault } from "./misc";
import { Cipher } from "./encryptUnified";
import type { import type {
FileStat, FileStat,
@@ -26,43 +27,75 @@ function onlyAscii(str: string) {
return !/[^\u0000-\u00ff]/g.test(str); return !/[^\u0000-\u00ff]/g.test(str);
} }
/**
* https://stackoverflow.com/questions/12539574/
* @param obj
* @returns
*/
function objKeyToLower(obj: Record<string, string>) {
return Object.fromEntries(
Object.entries(obj).map(([k, v]) => [k.toLowerCase(), v])
);
}
// @ts-ignore // @ts-ignore
import { getPatcher } from "webdav/dist/web/index.js"; import { getPatcher } from "webdav/dist/web/index.js";
if (VALID_REQURL) { if (VALID_REQURL) {
getPatcher().patch( getPatcher().patch(
"request", "request",
async (options: RequestOptionsWithState): Promise<Response> => { async (options: RequestOptionsWithState): Promise<Response> => {
const transformedHeaders = { ...options.headers }; const transformedHeaders = objKeyToLower({ ...options.headers });
delete transformedHeaders["host"]; delete transformedHeaders["host"];
delete transformedHeaders["Host"];
delete transformedHeaders["content-length"]; delete transformedHeaders["content-length"];
delete transformedHeaders["Content-Length"];
const r = await requestUrl({ const reqContentType =
transformedHeaders["accept"] ?? transformedHeaders["content-type"];
const retractedHeaders = { ...transformedHeaders };
if (retractedHeaders.hasOwnProperty("authorization")) {
retractedHeaders["authorization"] = "<retracted>";
}
console.debug(`before request:`);
console.debug(`url: ${options.url}`);
console.debug(`method: ${options.method}`);
console.debug(`headers: ${JSON.stringify(retractedHeaders, null, 2)}`);
console.debug(`reqContentType: ${reqContentType}`);
let r = await requestUrl({
url: options.url, url: options.url,
method: options.method, method: options.method,
body: options.data as string | ArrayBuffer, body: options.data as string | ArrayBuffer,
headers: transformedHeaders, headers: transformedHeaders,
contentType: reqContentType,
throw: false, throw: false,
}); });
let contentType: string | undefined = if (
r.headers["Content-Type"] || r.headers["content-type"]; r.status === 401 &&
if (options.headers !== undefined) { Platform.isIosApp &&
contentType = !options.url.endsWith("/") &&
contentType || !options.url.endsWith(".md") &&
options.headers["Content-Type"] || options.method.toUpperCase() === "PROPFIND"
options.headers["content-type"] || ) {
options.headers["Accept"] || // don't ask me why,
options.headers["accept"]; // some webdav servers have some mysterious behaviours,
// if a folder doesn't exist without slash, the servers return 401 instead of 404
// here is a dirty hack that works
console.debug(`so we have 401, try appending request url with slash`);
r = await requestUrl({
url: `${options.url}/`,
method: options.method,
body: options.data as string | ArrayBuffer,
headers: transformedHeaders,
contentType: reqContentType,
throw: false,
});
} }
if (contentType !== undefined) { console.debug(`after request:`);
contentType = contentType.toLowerCase(); const rspHeaders = objKeyToLower({ ...r.headers });
} console.debug(`rspHeaders: ${JSON.stringify(rspHeaders, null, 2)}`);
const rspHeaders = { ...r.headers };
console.log("rspHeaders");
console.log(rspHeaders);
for (let key in rspHeaders) { for (let key in rspHeaders) {
if (rspHeaders.hasOwnProperty(key)) { if (rspHeaders.hasOwnProperty(key)) {
// avoid the error: // avoid the error:
@@ -79,74 +112,28 @@ if (VALID_REQURL) {
// } // }
// } // }
if (!onlyAscii(rspHeaders[key])) { if (!onlyAscii(rspHeaders[key])) {
console.debug(`rspHeaders[key] needs encode: ${key}`);
rspHeaders[key] = encodeURIComponent(rspHeaders[key]); rspHeaders[key] = encodeURIComponent(rspHeaders[key]);
} }
} }
} }
// console.info(`requesting url=${options.url}`);
// console.info(`contentType=${contentType}`);
// console.info(`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: rspHeaders,
// });
// } else if (
// contentType.includes("json") ||
// contentType.includes("javascript")
// ) {
// console.info('inside json branch');
// // const j = r.json;
// // console.info(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: rspHeaders,
// });
// } 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: rspHeaders,
// });
// } 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: rspHeaders,
// });
// } else {
// throw Error(
// `do not know how to deal with requested content type = ${contentType}`
// );
// }
let r2: Response | undefined = undefined; let r2: Response | undefined = undefined;
const statusText = getReasonPhrase(r.status);
console.debug(`statusText: ${statusText}`);
if ([101, 103, 204, 205, 304].includes(r.status)) { if ([101, 103, 204, 205, 304].includes(r.status)) {
// A null body status is a status that is 101, 103, 204, 205, or 304. // A null body status is a status that is 101, 103, 204, 205, or 304.
// https://fetch.spec.whatwg.org/#statuses // https://fetch.spec.whatwg.org/#statuses
// fix this: Failed to construct 'Response': Response with null body status cannot have body // fix this: Failed to construct 'Response': Response with null body status cannot have body
r2 = new Response(null, { r2 = new Response(null, {
status: r.status, status: r.status,
statusText: getReasonPhrase(r.status), statusText: statusText,
headers: rspHeaders, headers: rspHeaders,
}); });
} else { } else {
r2 = new Response(r.arrayBuffer, { r2 = new Response(r.arrayBuffer, {
status: r.status, status: r.status,
statusText: getReasonPhrase(r.status), statusText: statusText,
headers: rspHeaders, headers: rspHeaders,
}); });
} }
@@ -229,7 +216,8 @@ export class WrappedWebdavClient {
remoteBaseDir: string, remoteBaseDir: string,
saveUpdatedConfigFunc: () => Promise<any> saveUpdatedConfigFunc: () => Promise<any>
) { ) {
this.webdavConfig = webdavConfig; this.webdavConfig = cloneDeep(webdavConfig);
this.webdavConfig.address = encodeURI(this.webdavConfig.address);
this.remoteBaseDir = remoteBaseDir; this.remoteBaseDir = remoteBaseDir;
this.vaultFolderExists = false; this.vaultFolderExists = false;
this.saveUpdatedConfigFunc = saveUpdatedConfigFunc; this.saveUpdatedConfigFunc = saveUpdatedConfigFunc;
@@ -240,6 +228,13 @@ export class WrappedWebdavClient {
if (this.client !== undefined) { if (this.client !== undefined) {
return; return;
} }
if (Platform.isIosApp && !this.webdavConfig.address.startsWith("https")) {
throw Error(
`Your webdav address could only be https, not http, because of the iOS restriction.`
);
}
const headers = { const headers = {
"Cache-Control": "no-cache", "Cache-Control": "no-cache",
}; };
@@ -333,15 +328,15 @@ export const uploadToRemote = async (
client: WrappedWebdavClient, client: WrappedWebdavClient,
fileOrFolderPath: string, fileOrFolderPath: string,
vault: Vault | undefined, vault: Vault | undefined,
isRecursively: boolean = false, isRecursively: boolean,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "", remoteEncryptedKey: string = "",
uploadRaw: boolean = false, uploadRaw: boolean = false,
rawContent: string | ArrayBuffer = "" rawContent: string | ArrayBuffer = ""
): Promise<UploadedType> => { ): Promise<UploadedType> => {
await client.init(); await client.init();
let uploadFile = fileOrFolderPath; let uploadFile = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
if (remoteEncryptedKey === undefined || remoteEncryptedKey === "") { if (remoteEncryptedKey === undefined || remoteEncryptedKey === "") {
throw Error( throw Error(
`uploadToRemote(webdav) you have password but remoteEncryptedKey is empty!` `uploadToRemote(webdav) you have password but remoteEncryptedKey is empty!`
@@ -360,8 +355,8 @@ export const uploadToRemote = async (
throw Error(`you specify uploadRaw, but you also provide a folder key!`); throw Error(`you specify uploadRaw, but you also provide a folder key!`);
} }
// folder // folder
if (password === "") { if (cipher.isPasswordEmpty() || cipher.isFolderAware()) {
// if not encrypted, mkdir a remote folder // if not encrypted, || encrypted isFolderAware, mkdir a remote folder
await client.client.createDirectory(uploadFile, { await client.client.createDirectory(uploadFile, {
recursive: true, recursive: true,
}); });
@@ -370,7 +365,8 @@ export const uploadToRemote = async (
entity: res, entity: res,
}; };
} else { } else {
// if encrypted, upload a fake file with the encrypted file name // if encrypted && !isFolderAware(),
// upload a fake file with the encrypted file name
await client.client.putFileContents(uploadFile, "", { await client.client.putFileContents(uploadFile, "", {
overwrite: true, overwrite: true,
onUploadProgress: (progress: any) => { onUploadProgress: (progress: any) => {
@@ -403,8 +399,8 @@ export const uploadToRemote = async (
mtimeCli = (await vault.adapter.stat(fileOrFolderPath))?.mtime; mtimeCli = (await vault.adapter.stat(fileOrFolderPath))?.mtime;
} }
let remoteContent = localContent; let remoteContent = localContent;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
remoteContent = await encryptArrayBuffer(localContent, password); remoteContent = await cipher.encryptContent(localContent);
} }
// updated 20220326: the algorithm guarantee this // updated 20220326: the algorithm guarantee this
// // we need to create folders before uploading // // we need to create folders before uploading
@@ -508,7 +504,7 @@ export const downloadFromRemote = async (
fileOrFolderPath: string, fileOrFolderPath: string,
vault: Vault, vault: Vault,
mtime: number, mtime: number,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "", remoteEncryptedKey: string = "",
skipSaving: boolean = false skipSaving: boolean = false
) => { ) => {
@@ -529,15 +525,15 @@ export const downloadFromRemote = async (
return new ArrayBuffer(0); return new ArrayBuffer(0);
} else { } else {
let downloadFile = fileOrFolderPath; let downloadFile = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
downloadFile = remoteEncryptedKey; downloadFile = remoteEncryptedKey;
} }
downloadFile = getWebdavPath(downloadFile, client.remoteBaseDir); downloadFile = getWebdavPath(downloadFile, client.remoteBaseDir);
// console.info(`downloadFile=${downloadFile}`); // console.info(`downloadFile=${downloadFile}`);
const remoteContent = await downloadFromRemoteRaw(client, downloadFile); const remoteContent = await downloadFromRemoteRaw(client, downloadFile);
let localContent = remoteContent; let localContent = remoteContent;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
localContent = await decryptArrayBuffer(remoteContent, password); localContent = await cipher.decryptContent(remoteContent);
} }
if (!skipSaving) { if (!skipSaving) {
await vault.adapter.writeBinary(fileOrFolderPath, localContent, { await vault.adapter.writeBinary(fileOrFolderPath, localContent, {
@@ -551,14 +547,14 @@ export const downloadFromRemote = async (
export const deleteFromRemote = async ( export const deleteFromRemote = async (
client: WrappedWebdavClient, client: WrappedWebdavClient,
fileOrFolderPath: string, fileOrFolderPath: string,
password: string = "", cipher: Cipher,
remoteEncryptedKey: string = "" remoteEncryptedKey: string = ""
) => { ) => {
if (fileOrFolderPath === "/") { if (fileOrFolderPath === "/") {
return; return;
} }
let remoteFileName = fileOrFolderPath; let remoteFileName = fileOrFolderPath;
if (password !== "") { if (!cipher.isPasswordEmpty()) {
remoteFileName = remoteEncryptedKey; remoteFileName = remoteEncryptedKey;
} }
remoteFileName = getWebdavPath(remoteFileName, client.remoteBaseDir); remoteFileName = getWebdavPath(remoteFileName, client.remoteBaseDir);
+122 -1
View File
@@ -22,6 +22,7 @@ import {
VALID_REQURL, VALID_REQURL,
WebdavAuthType, WebdavAuthType,
WebdavDepthType, WebdavDepthType,
CipherMethodType,
} from "./baseTypes"; } from "./baseTypes";
import { exportVaultSyncPlansToFiles } from "./debugMode"; import { exportVaultSyncPlansToFiles } from "./debugMode";
import { exportQrCodeUri } from "./importExport"; import { exportQrCodeUri } from "./importExport";
@@ -45,7 +46,11 @@ import {
} from "./remoteForOnedrive"; } from "./remoteForOnedrive";
import { messyConfigToNormal } from "./configPersist"; import { messyConfigToNormal } from "./configPersist";
import type { TransItemType } from "./i18n"; import type { TransItemType } from "./i18n";
import { checkHasSpecialCharForDir, stringToFragment } from "./misc"; import {
changeMobileStatusBar,
checkHasSpecialCharForDir,
stringToFragment,
} from "./misc";
import { simpleTransRemotePrefix } from "./remoteForS3"; import { simpleTransRemotePrefix } from "./remoteForS3";
class PasswordModal extends Modal { class PasswordModal extends Modal {
@@ -118,6 +123,45 @@ class PasswordModal extends Modal {
} }
} }
class EncryptionMethodModal extends Modal {
plugin: RemotelySavePlugin;
constructor(app: App, plugin: RemotelySavePlugin) {
super(app);
this.plugin = plugin;
}
onOpen() {
let { contentEl } = this;
const t = (x: TransItemType, vars?: any) => {
return this.plugin.i18n.t(x, vars);
};
// contentEl.setText("Add Or change password.");
contentEl.createEl("h2", { text: t("modal_encryptionmethod_title") });
t("modal_encryptionmethod_shortdesc")
.split("\n")
.forEach((val, idx) => {
contentEl.createEl("p", {
text: stringToFragment(val),
});
});
new Setting(contentEl).addButton((button) => {
button.setButtonText(t("confirm"));
button.onClick(async () => {
this.close();
});
button.setClass("encryptionmethod-second-confirm");
});
}
onClose() {
let { contentEl } = this;
contentEl.empty();
}
}
class ChangeRemoteBaseDirModal extends Modal { class ChangeRemoteBaseDirModal extends Modal {
readonly plugin: RemotelySavePlugin; readonly plugin: RemotelySavePlugin;
readonly newRemoteBaseDir: string; readonly newRemoteBaseDir: string;
@@ -1630,6 +1674,23 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
}); });
}); });
new Setting(basicDiv)
.setName(t("settings_encryptionmethod"))
.setDesc(stringToFragment(t("settings_encryptionmethod_desc")))
.addDropdown((dropdown) => {
dropdown
.addOption("rclone-base64", t("settings_encryptionmethod_rclone"))
.addOption("openssl-base64", t("settings_encryptionmethod_openssl"))
.setValue(this.plugin.settings.encryptionMethod ?? "rclone-base64")
.onChange(async (val: string) => {
this.plugin.settings.encryptionMethod = val as CipherMethodType;
await this.plugin.saveSettings();
if (this.plugin.settings.password !== "") {
new EncryptionMethodModal(this.app, this.plugin).open();
}
});
});
new Setting(basicDiv) new Setting(basicDiv)
.setName(t("settings_autorun")) .setName(t("settings_autorun"))
.setDesc(t("settings_autorun_desc")) .setDesc(t("settings_autorun_desc"))
@@ -2017,6 +2078,42 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
}); });
}); });
if (Platform.isMobile) {
new Setting(advDiv)
.setName(t("settings_enablemobilestatusbar"))
.setDesc(t("settings_enablemobilestatusbar_desc"))
.addDropdown(async (dropdown) => {
dropdown
.addOption("enable", t("enable"))
.addOption("disable", t("disable"));
dropdown
.setValue(
`${
this.plugin.settings.enableMobileStatusBar
? "enable"
: "disable"
}`
)
.onChange(async (val) => {
if (val === "enable") {
this.plugin.settings.enableMobileStatusBar = true;
this.plugin.appContainerObserver =
changeMobileStatusBar("enable");
} else {
this.plugin.settings.enableMobileStatusBar = false;
changeMobileStatusBar(
"disable",
this.plugin.appContainerObserver
);
this.plugin.appContainerObserver?.disconnect();
this.plugin.appContainerObserver = undefined;
}
await this.plugin.saveSettings();
});
});
}
////////////////////////////////////////////////// //////////////////////////////////////////////////
// below for import and export functions // below for import and export functions
////////////////////////////////////////////////// //////////////////////////////////////////////////
@@ -2075,6 +2172,30 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
}); });
}); });
new Setting(debugDiv)
.setName(t("settings_obfuscatesettingfile"))
.setDesc(t("settings_obfuscatesettingfile_desc"))
.addDropdown(async (dropdown) => {
dropdown
.addOption("enable", t("enable"))
.addOption("disable", t("disable"));
dropdown
.setValue(
`${
this.plugin.settings.obfuscateSettingFile ? "enable" : "disable"
}`
)
.onChange(async (val) => {
if (val === "enable") {
this.plugin.settings.obfuscateSettingFile = true;
} else {
this.plugin.settings.obfuscateSettingFile = false;
}
await this.plugin.saveSettings();
});
});
new Setting(debugDiv) new Setting(debugDiv)
.setName(t("settings_viewconsolelog")) .setName(t("settings_viewconsolelog"))
.setDesc(stringToFragment(t("settings_viewconsolelog_desc"))); .setDesc(stringToFragment(t("settings_viewconsolelog_desc")));
+292 -158
View File
@@ -1,10 +1,12 @@
import PQueue from "p-queue"; import PQueue from "p-queue";
import XRegExp from "xregexp"; import XRegExp from "xregexp";
import type { import type {
CipherMethodType,
ConflictActionType, ConflictActionType,
EmptyFolderCleanType, EmptyFolderCleanType,
Entity, Entity,
MixedEntity, MixedEntity,
SUPPORTED_SERVICES_TYPE,
SyncDirectionType, SyncDirectionType,
} from "./baseTypes"; } from "./baseTypes";
import { isInsideObsFolder } from "./obsFolderLister"; import { isInsideObsFolder } from "./obsFolderLister";
@@ -16,19 +18,12 @@ import {
isVaildText, isVaildText,
atWhichLevel, atWhichLevel,
mkdirpInVault, mkdirpInVault,
getFolderLevels,
} from "./misc"; } from "./misc";
import { import {
DEFAULT_FILE_NAME_FOR_METADATAONREMOTE, DEFAULT_FILE_NAME_FOR_METADATAONREMOTE,
DEFAULT_FILE_NAME_FOR_METADATAONREMOTE2, DEFAULT_FILE_NAME_FOR_METADATAONREMOTE2,
} from "./metadataOnRemote"; } from "./metadataOnRemote";
import {
MAGIC_ENCRYPTED_PREFIX_BASE32,
MAGIC_ENCRYPTED_PREFIX_BASE64URL,
decryptBase32ToString,
decryptBase64urlToString,
encryptStringToBase64url,
getSizeFromOrigToEnc,
} from "./encrypt";
import { RemoteClient } from "./remote"; import { RemoteClient } from "./remote";
import { Vault } from "obsidian"; import { Vault } from "obsidian";
@@ -38,6 +33,7 @@ import {
clearPrevSyncRecordByVaultAndProfile, clearPrevSyncRecordByVaultAndProfile,
upsertPrevSyncRecordByVaultAndProfile, upsertPrevSyncRecordByVaultAndProfile,
} from "./localdb"; } from "./localdb";
import { Cipher } from "./encryptUnified";
export type SyncStatusType = export type SyncStatusType =
| "idle" | "idle"
@@ -54,19 +50,18 @@ export type SyncStatusType =
export interface PasswordCheckType { export interface PasswordCheckType {
ok: boolean; ok: boolean;
reason: reason:
| "ok"
| "empty_remote" | "empty_remote"
| "unknown_encryption_method"
| "remote_encrypted_local_no_password" | "remote_encrypted_local_no_password"
| "password_matched" | "password_matched"
| "password_not_matched" | "password_or_method_not_matched_or_remote_not_encrypted"
| "invalid_text_after_decryption" | "likely_no_password_both_sides"
| "remote_not_encrypted_local_has_password" | "encryption_method_not_matched";
| "no_password_both_sides";
} }
export const isPasswordOk = async ( export const isPasswordOk = async (
remote: Entity[], remote: Entity[],
password: string = "" cipher: Cipher
): Promise<PasswordCheckType> => { ): Promise<PasswordCheckType> => {
if (remote === undefined || remote.length === 0) { if (remote === undefined || remote.length === 0) {
// remote empty // remote empty
@@ -76,81 +71,51 @@ export const isPasswordOk = async (
}; };
} }
const santyCheckKey = remote[0].keyRaw; const santyCheckKey = remote[0].keyRaw;
if (santyCheckKey.startsWith(MAGIC_ENCRYPTED_PREFIX_BASE32)) {
// this is encrypted using old base32! if (cipher.isPasswordEmpty()) {
// try to decrypt it using the provided password. // TODO: no way to distinguish remote rclone encrypted
if (password === "") { // if local has no password??
if (Cipher.isLikelyEncryptedName(santyCheckKey)) {
return { return {
ok: false, ok: false,
reason: "remote_encrypted_local_no_password", reason: "remote_encrypted_local_no_password",
}; };
} } else {
try {
const res = await decryptBase32ToString(santyCheckKey, password);
// additional test
// because iOS Safari bypasses decryption with wrong password!
if (isVaildText(res)) {
return {
ok: true,
reason: "password_matched",
};
} else {
return {
ok: false,
reason: "invalid_text_after_decryption",
};
}
} catch (error) {
return { return {
ok: false, ok: true,
reason: "password_not_matched", reason: "likely_no_password_both_sides",
};
}
}
if (santyCheckKey.startsWith(MAGIC_ENCRYPTED_PREFIX_BASE64URL)) {
// this is encrypted using new base64url!
// try to decrypt it using the provided password.
if (password === "") {
return {
ok: false,
reason: "remote_encrypted_local_no_password",
};
}
try {
const res = await decryptBase64urlToString(santyCheckKey, password);
// additional test
// because iOS Safari bypasses decryption with wrong password!
if (isVaildText(res)) {
return {
ok: true,
reason: "password_matched",
};
} else {
return {
ok: false,
reason: "invalid_text_after_decryption",
};
}
} catch (error) {
return {
ok: false,
reason: "password_not_matched",
}; };
} }
} else { } else {
// it is not encrypted! if (cipher.method === "unknown") {
if (password !== "") {
return { return {
ok: false, ok: false,
reason: "remote_not_encrypted_local_has_password", reason: "unknown_encryption_method",
};
}
if (
Cipher.isLikelyEncryptedNameNotMatchMethod(santyCheckKey, cipher.method)
) {
return {
ok: false,
reason: "encryption_method_not_matched",
};
}
try {
const k = await cipher.decryptName(santyCheckKey);
if (k === undefined) {
throw Error(`decryption failed`);
}
return {
ok: true,
reason: "password_matched",
};
} catch (error) {
return {
ok: false,
reason: "password_or_method_not_matched_or_remote_not_encrypted",
}; };
} }
return {
ok: true,
reason: "no_password_both_sides",
};
} }
}; };
@@ -186,12 +151,19 @@ const isSkipItemByName = (
); );
}; };
const copyEntityAndFixTimeFormat = (src: Entity) => { const copyEntityAndFixTimeFormat = (
src: Entity,
serviceType: SUPPORTED_SERVICES_TYPE
) => {
const result = Object.assign({}, src); const result = Object.assign({}, src);
if (result.mtimeCli !== undefined) { if (result.mtimeCli !== undefined) {
if (result.mtimeCli === 0) { if (result.mtimeCli === 0) {
result.mtimeCli = undefined; result.mtimeCli = undefined;
} else { } else {
if (serviceType === "s3" || serviceType === "dropbox") {
// round to second instead of millisecond
result.mtimeCli = Math.floor(result.mtimeCli / 1000.0) * 1000;
}
result.mtimeCliFmt = unixTimeToStr(result.mtimeCli); result.mtimeCliFmt = unixTimeToStr(result.mtimeCli);
} }
} }
@@ -199,6 +171,10 @@ const copyEntityAndFixTimeFormat = (src: Entity) => {
if (result.mtimeSvr === 0) { if (result.mtimeSvr === 0) {
result.mtimeSvr = undefined; result.mtimeSvr = undefined;
} else { } else {
if (serviceType === "s3" || serviceType === "dropbox") {
// round to second instead of millisecond
result.mtimeSvr = Math.floor(result.mtimeSvr / 1000.0) * 1000;
}
result.mtimeSvrFmt = unixTimeToStr(result.mtimeSvr); result.mtimeSvrFmt = unixTimeToStr(result.mtimeSvr);
} }
} }
@@ -206,6 +182,10 @@ const copyEntityAndFixTimeFormat = (src: Entity) => {
if (result.prevSyncTime === 0) { if (result.prevSyncTime === 0) {
result.prevSyncTime = undefined; result.prevSyncTime = undefined;
} else { } else {
if (serviceType === "s3" || serviceType === "dropbox") {
// round to second instead of millisecond
result.prevSyncTime = Math.floor(result.prevSyncTime / 1000.0) * 1000;
}
result.prevSyncTimeFmt = unixTimeToStr(result.prevSyncTime); result.prevSyncTimeFmt = unixTimeToStr(result.prevSyncTime);
} }
} }
@@ -215,12 +195,9 @@ const copyEntityAndFixTimeFormat = (src: Entity) => {
/** /**
* Inplace, no copy again. * Inplace, no copy again.
* @param remote
* @param password
* @returns
*/ */
const decryptRemoteEntityInplace = async (remote: Entity, password: string) => { const decryptRemoteEntityInplace = async (remote: Entity, cipher: Cipher) => {
if (password == undefined || password === "") { if (cipher?.isPasswordEmpty()) {
remote.key = remote.keyRaw; remote.key = remote.keyRaw;
remote.keyEnc = remote.keyRaw; remote.keyEnc = remote.keyRaw;
remote.size = remote.sizeRaw; remote.size = remote.sizeRaw;
@@ -228,19 +205,9 @@ const decryptRemoteEntityInplace = async (remote: Entity, password: string) => {
return remote; return remote;
} }
if (remote.keyRaw.startsWith(MAGIC_ENCRYPTED_PREFIX_BASE32)) { remote.keyEnc = remote.keyRaw;
remote.keyEnc = remote.keyRaw; remote.key = await cipher.decryptName(remote.keyEnc);
remote.key = await decryptBase32ToString(remote.keyEnc, password); remote.sizeEnc = remote.sizeRaw;
remote.sizeEnc = remote.sizeRaw;
} else if (remote.keyRaw.startsWith(MAGIC_ENCRYPTED_PREFIX_BASE64URL)) {
remote.keyEnc = remote.keyRaw;
remote.key = await decryptBase64urlToString(remote.keyEnc, password);
remote.sizeEnc = remote.sizeRaw;
} else {
throw Error(
`unexpected key to decrypt: ${JSON.stringify(remote, null, 2)}`
);
}
// TODO // TODO
// remote.size = getSizeFromEncToOrig(remote.sizeEnc, password); // remote.size = getSizeFromEncToOrig(remote.sizeEnc, password);
@@ -293,13 +260,10 @@ const ensureMTimeOfRemoteEntityValid = (remote: Entity) => {
/** /**
* Inplace, no copy again. * Inplace, no copy again.
* @param local
* @param password
* @returns
*/ */
const encryptLocalEntityInplace = async ( const encryptLocalEntityInplace = async (
local: Entity, local: Entity,
password: string, cipher: Cipher,
remoteKeyEnc: string | undefined remoteKeyEnc: string | undefined
) => { ) => {
// console.debug( // console.debug(
@@ -317,7 +281,7 @@ const encryptLocalEntityInplace = async (
throw Error(`local ${local.keyRaw} is abnormal without key`); throw Error(`local ${local.keyRaw} is abnormal without key`);
} }
if (password === undefined || password === "") { if (cipher.isPasswordEmpty()) {
local.sizeEnc = local.sizeRaw; // if no enc, the remote file has the same size local.sizeEnc = local.sizeRaw; // if no enc, the remote file has the same size
local.keyEnc = local.keyRaw; local.keyEnc = local.keyRaw;
return local; return local;
@@ -328,7 +292,7 @@ const encryptLocalEntityInplace = async (
// it's not filled yet, we fill it // it's not filled yet, we fill it
// local.size is possibly undefined if it's "prevSync" Entity // local.size is possibly undefined if it's "prevSync" Entity
// but local.key should always have value // but local.key should always have value
local.sizeEnc = getSizeFromOrigToEnc(local.size); local.sizeEnc = cipher.getSizeFromOrigToEnc(local.size);
} }
if (local.keyEnc === undefined || local.keyEnc === "") { if (local.keyEnc === undefined || local.keyEnc === "") {
@@ -341,10 +305,7 @@ const encryptLocalEntityInplace = async (
local.keyEnc = remoteKeyEnc; local.keyEnc = remoteKeyEnc;
} else { } else {
// we assign a new encrypted key because of no remote // we assign a new encrypted key because of no remote
// the old version uses base32 local.keyEnc = await cipher.encryptName(local.key);
// local.keyEnc = await encryptStringToBase32(local.key, password);
// the new version users base64url
local.keyEnc = await encryptStringToBase64url(local.key, password);
} }
} }
return local; return local;
@@ -361,16 +322,20 @@ export const ensembleMixedEnties = async (
configDir: string, configDir: string,
syncUnderscoreItems: boolean, syncUnderscoreItems: boolean,
ignorePaths: string[], ignorePaths: string[],
password: string cipher: Cipher,
serviceType: SUPPORTED_SERVICES_TYPE
): Promise<SyncPlanType> => { ): Promise<SyncPlanType> => {
const finalMappings: SyncPlanType = {}; const finalMappings: SyncPlanType = {};
const synthFolders: Record<string, Entity> = {};
// remote has to be first // remote has to be first
// we also have to synthesize folders here
for (const remote of remoteEntityList) { for (const remote of remoteEntityList) {
const remoteCopied = ensureMTimeOfRemoteEntityValid( const remoteCopied = ensureMTimeOfRemoteEntityValid(
await decryptRemoteEntityInplace( await decryptRemoteEntityInplace(
copyEntityAndFixTimeFormat(remote), copyEntityAndFixTimeFormat(remote, serviceType),
password cipher
) )
); );
@@ -391,6 +356,42 @@ export const ensembleMixedEnties = async (
key: key, key: key,
remote: remoteCopied, remote: remoteCopied,
}; };
for (const f of getFolderLevels(key, true)) {
if (finalMappings.hasOwnProperty(f)) {
delete synthFolders[f];
continue;
}
if (
!synthFolders.hasOwnProperty(f) ||
remoteCopied.mtimeSvr! >= synthFolders[f].mtimeSvr!
) {
synthFolders[f] = {
key: f,
keyRaw: `<synth: ${f}>`,
keyEnc: `<enc synth: ${f}>`,
size: 0,
sizeRaw: 0,
sizeEnc: 0,
mtimeSvr: remoteCopied.mtimeSvr,
mtimeSvrFmt: remoteCopied.mtimeSvrFmt,
mtimeCli: remoteCopied.mtimeCli,
mtimeCliFmt: remoteCopied.mtimeCliFmt,
synthesizedFolder: true,
};
}
}
}
console.debug(`synthFolders:`);
console.debug(synthFolders);
// special: add synth folders
for (const key of Object.keys(synthFolders)) {
finalMappings[key] = {
key: key,
remote: synthFolders[key],
};
} }
if (Object.keys(finalMappings).length === 0 || localEntityList.length === 0) { if (Object.keys(finalMappings).length === 0 || localEntityList.length === 0) {
@@ -418,15 +419,15 @@ export const ensembleMixedEnties = async (
if (finalMappings.hasOwnProperty(key)) { if (finalMappings.hasOwnProperty(key)) {
const prevSyncCopied = await encryptLocalEntityInplace( const prevSyncCopied = await encryptLocalEntityInplace(
copyEntityAndFixTimeFormat(prevSync), copyEntityAndFixTimeFormat(prevSync, serviceType),
password, cipher,
finalMappings[key].remote?.keyEnc finalMappings[key].remote?.keyEnc
); );
finalMappings[key].prevSync = prevSyncCopied; finalMappings[key].prevSync = prevSyncCopied;
} else { } else {
const prevSyncCopied = await encryptLocalEntityInplace( const prevSyncCopied = await encryptLocalEntityInplace(
copyEntityAndFixTimeFormat(prevSync), copyEntityAndFixTimeFormat(prevSync, serviceType),
password, cipher,
undefined undefined
); );
finalMappings[key] = { finalMappings[key] = {
@@ -456,15 +457,15 @@ export const ensembleMixedEnties = async (
if (finalMappings.hasOwnProperty(key)) { if (finalMappings.hasOwnProperty(key)) {
const localCopied = await encryptLocalEntityInplace( const localCopied = await encryptLocalEntityInplace(
copyEntityAndFixTimeFormat(local), copyEntityAndFixTimeFormat(local, serviceType),
password, cipher,
finalMappings[key].remote?.keyEnc finalMappings[key].remote?.keyEnc
); );
finalMappings[key].local = localCopied; finalMappings[key].local = localCopied;
} else { } else {
const localCopied = await encryptLocalEntityInplace( const localCopied = await encryptLocalEntityInplace(
copyEntityAndFixTimeFormat(local), copyEntityAndFixTimeFormat(local, serviceType),
password, cipher,
undefined undefined
); );
finalMappings[key] = { finalMappings[key] = {
@@ -474,6 +475,8 @@ export const ensembleMixedEnties = async (
} }
} }
console.debug("in the end of ensembleMixedEnties, finalMappings is:");
console.debug(finalMappings);
return finalMappings; return finalMappings;
}; };
@@ -543,9 +546,41 @@ export const getSyncPlanInplace = async (
mixedEntry.decisionBranch = 105; mixedEntry.decisionBranch = 105;
mixedEntry.decision = "folder_to_skip"; mixedEntry.decision = "folder_to_skip";
} else if (howToCleanEmptyFolder === "clean_both") { } else if (howToCleanEmptyFolder === "clean_both") {
mixedEntry.decisionBranch = 106; if (local !== undefined && remote !== undefined) {
mixedEntry.decision = "folder_to_be_deleted"; if (syncDirection === "bidirectional") {
// TODO: what to do in different sync direction? mixedEntry.decisionBranch = 106;
mixedEntry.decision = "folder_to_be_deleted_on_both";
} else {
// right now it does nothing because of "incremental"
// TODO: should we delete??
mixedEntry.decisionBranch = 109;
mixedEntry.decision = "folder_to_skip";
}
} else if (local !== undefined && remote === undefined) {
if (syncDirection === "bidirectional") {
mixedEntry.decisionBranch = 110;
mixedEntry.decision = "folder_to_be_deleted_on_local";
} else {
// right now it does nothing because of "incremental"
// TODO: should we delete??
mixedEntry.decisionBranch = 111;
mixedEntry.decision = "folder_to_skip";
}
} else if (local === undefined && remote !== undefined) {
if (syncDirection === "bidirectional") {
mixedEntry.decisionBranch = 112;
mixedEntry.decision = "folder_to_be_deleted_on_remote";
} else {
// right now it does nothing because of "incremental"
// TODO: should we delete??
mixedEntry.decisionBranch = 113;
mixedEntry.decision = "folder_to_skip";
}
} else {
// no folder to delete, do nothing
mixedEntry.decisionBranch = 114;
mixedEntry.decision = "folder_to_skip";
}
} else { } else {
throw Error( throw Error(
`do not know how to deal with empty folder ${mixedEntry.key}` `do not know how to deal with empty folder ${mixedEntry.key}`
@@ -743,11 +778,9 @@ export const getSyncPlanInplace = async (
keptFolder.add(getParentFolder(key)); keptFolder.add(getParentFolder(key));
} }
} else { } else {
throw Error( mixedEntry.decisionBranch = 36;
`remote is created (branch 3) but size larger than ${skipSizeLargerThan}, don't know what to do: ${JSON.stringify( mixedEntry.decision = "remote_is_created_too_large_then_do_nothing";
mixedEntry keptFolder.add(getParentFolder(key));
)}`
);
} }
} else if ( } else if (
(prevSync.mtimeSvr === remote.mtimeCli || (prevSync.mtimeSvr === remote.mtimeCli ||
@@ -806,11 +839,9 @@ export const getSyncPlanInplace = async (
keptFolder.add(getParentFolder(key)); keptFolder.add(getParentFolder(key));
} }
} else { } else {
throw Error( mixedEntry.decisionBranch = 37;
`local is created (branch 6) but size larger than ${skipSizeLargerThan}, don't know what to do: ${JSON.stringify( mixedEntry.decision = "local_is_created_too_large_then_do_nothing";
mixedEntry keptFolder.add(getParentFolder(key));
)}`
);
} }
} else if ( } else if (
(prevSync.mtimeSvr === local.mtimeCli || (prevSync.mtimeSvr === local.mtimeCli ||
@@ -872,13 +903,27 @@ export const getSyncPlanInplace = async (
throw Error(`unexpectedly keptFolder no decisions: ${[...keptFolder]}`); throw Error(`unexpectedly keptFolder no decisions: ${[...keptFolder]}`);
} }
// finally we want to make our life easier
const currTime = Date.now();
const currTimeFmt = unixTimeToStr(currTime);
// because the path should not as / in the beginning,
// we should be safe to add these keys:
mixedEntityMappings["/$@meta"] = {
key: "/$@meta", // don't mess up with the types
sideNotes: {
generateTime: currTime,
generateTimeFmt: currTimeFmt,
},
};
return mixedEntityMappings; return mixedEntityMappings;
}; };
const splitThreeStepsOnEntityMappings = ( const splitFourStepsOnEntityMappings = (
mixedEntityMappings: Record<string, MixedEntity> mixedEntityMappings: Record<string, MixedEntity>
) => { ) => {
type StepArrayType = MixedEntity[] | undefined | null; type StepArrayType = MixedEntity[] | undefined | null;
const onlyMarkSyncedOps: StepArrayType[] = [];
const folderCreationOps: StepArrayType[] = []; const folderCreationOps: StepArrayType[] = [];
const deletionOps: StepArrayType[] = []; const deletionOps: StepArrayType[] = [];
const uploadDownloads: StepArrayType[] = []; const uploadDownloads: StepArrayType[] = [];
@@ -894,6 +939,11 @@ const splitThreeStepsOnEntityMappings = (
for (let i = 0; i < sortedKeys.length; ++i) { for (let i = 0; i < sortedKeys.length; ++i) {
const key = sortedKeys[i]; const key = sortedKeys[i];
if (key === "/$@meta") {
continue; // special
}
const val = mixedEntityMappings[key]; const val = mixedEntityMappings[key];
if (!key.endsWith("/")) { if (!key.endsWith("/")) {
@@ -901,12 +951,27 @@ const splitThreeStepsOnEntityMappings = (
} }
if ( if (
val.decision === "equal" || val.decision === "local_is_created_too_large_then_do_nothing" ||
val.decision === "conflict_created_then_do_nothing" || val.decision === "remote_is_created_too_large_then_do_nothing" ||
val.decision === "folder_existed_both_then_do_nothing" ||
val.decision === "folder_to_skip" val.decision === "folder_to_skip"
) { ) {
// pass // pass
} else if (
val.decision === "equal" ||
val.decision === "conflict_created_then_do_nothing" ||
val.decision === "folder_existed_both_then_do_nothing"
) {
if (
onlyMarkSyncedOps.length === 0 ||
onlyMarkSyncedOps[0] === undefined ||
onlyMarkSyncedOps[0] === null
) {
onlyMarkSyncedOps[0] = [val];
} else {
onlyMarkSyncedOps[0].push(val); // only one level is needed here
}
// don't need to update realTotalCount here
} else if ( } else if (
val.decision === "folder_existed_local_then_also_create_remote" || val.decision === "folder_existed_local_then_also_create_remote" ||
val.decision === "folder_existed_remote_then_also_create_local" || val.decision === "folder_existed_remote_then_also_create_local" ||
@@ -926,7 +991,9 @@ const splitThreeStepsOnEntityMappings = (
val.decision === "only_history" || val.decision === "only_history" ||
val.decision === "local_is_deleted_thus_also_delete_remote" || val.decision === "local_is_deleted_thus_also_delete_remote" ||
val.decision === "remote_is_deleted_thus_also_delete_local" || val.decision === "remote_is_deleted_thus_also_delete_local" ||
val.decision === "folder_to_be_deleted" val.decision === "folder_to_be_deleted_on_both" ||
val.decision === "folder_to_be_deleted_on_local" ||
val.decision === "folder_to_be_deleted_on_remote"
) { ) {
const level = atWhichLevel(key); const level = atWhichLevel(key);
const k = deletionOps[level - 1]; const k = deletionOps[level - 1];
@@ -937,7 +1004,11 @@ const splitThreeStepsOnEntityMappings = (
} }
realTotalCount += 1; realTotalCount += 1;
if (val.decision.startsWith("deleted")) { if (
val.decision.includes("deleted") &&
!val.decision.includes("folder")
) {
// only count files here, skip folder
realModifyDeleteCount += 1; realModifyDeleteCount += 1;
} }
} else if ( } else if (
@@ -964,8 +1035,8 @@ const splitThreeStepsOnEntityMappings = (
realTotalCount += 1; realTotalCount += 1;
if ( if (
val.decision.startsWith("modified") || val.decision.includes("modified") ||
val.decision.startsWith("conflict") val.decision.includes("conflict")
) { ) {
realModifyDeleteCount += 1; realModifyDeleteCount += 1;
} }
@@ -980,6 +1051,7 @@ const splitThreeStepsOnEntityMappings = (
deletionOps.reverse(); // inplace reverse deletionOps.reverse(); // inplace reverse
return { return {
onlyMarkSyncedOps: onlyMarkSyncedOps,
folderCreationOps: folderCreationOps, folderCreationOps: folderCreationOps,
deletionOps: deletionOps, deletionOps: deletionOps,
uploadDownloads: uploadDownloads, uploadDownloads: uploadDownloads,
@@ -998,7 +1070,7 @@ const dispatchOperationToActualV3 = async (
db: InternalDBs, db: InternalDBs,
vault: Vault, vault: Vault,
localDeleteFunc: any, localDeleteFunc: any,
password: string cipher: Cipher
) => { ) => {
// console.debug( // console.debug(
// `inside dispatchOperationToActualV3, key=${key}, r=${JSON.stringify( // `inside dispatchOperationToActualV3, key=${key}, r=${JSON.stringify(
@@ -1009,13 +1081,37 @@ const dispatchOperationToActualV3 = async (
// ); // );
if (r.decision === "only_history") { if (r.decision === "only_history") {
clearPrevSyncRecordByVaultAndProfile(db, vaultRandomID, profileID, key); clearPrevSyncRecordByVaultAndProfile(db, vaultRandomID, profileID, key);
} else if (
r.decision === "local_is_created_too_large_then_do_nothing" ||
r.decision === "remote_is_created_too_large_then_do_nothing" ||
r.decision === "folder_to_skip"
) {
// !! no actual sync being kept happens,
// so no sync record here
// pass
} else if ( } else if (
r.decision === "equal" || r.decision === "equal" ||
r.decision === "conflict_created_then_do_nothing" || r.decision === "conflict_created_then_do_nothing" ||
r.decision === "folder_to_skip" ||
r.decision === "folder_existed_both_then_do_nothing" r.decision === "folder_existed_both_then_do_nothing"
) { ) {
// pass // !! we need to upsert the record,
// so that next time we can determine the change delta
const entity = r.remote ?? r.local;
console.debug(
`we are in actual operation of equal, entity=${JSON.stringify(
entity,
null,
2
)}`
);
if (entity !== undefined) {
await upsertPrevSyncRecordByVaultAndProfile(
db,
vaultRandomID,
profileID,
entity
);
}
} else if ( } else if (
r.decision === "local_is_modified_then_push" || r.decision === "local_is_modified_then_push" ||
r.decision === "local_is_created_then_push" || r.decision === "local_is_created_then_push" ||
@@ -1026,7 +1122,7 @@ const dispatchOperationToActualV3 = async (
if ( if (
client.serviceType === "onedrive" && client.serviceType === "onedrive" &&
r.local!.size === 0 && r.local!.size === 0 &&
password === "" cipher.isPasswordEmpty()
) { ) {
// special treatment for empty files for OneDrive // special treatment for empty files for OneDrive
// TODO: it's ugly, any other way? // TODO: it's ugly, any other way?
@@ -1038,10 +1134,10 @@ const dispatchOperationToActualV3 = async (
r.key, r.key,
vault, vault,
false, false,
password, cipher,
r.local!.keyEnc r.local!.keyEnc
); );
await decryptRemoteEntityInplace(entity, password); await decryptRemoteEntityInplace(entity, cipher);
await fullfillMTimeOfRemoteEntityInplace(entity, mtimeCli); await fullfillMTimeOfRemoteEntityInplace(entity, mtimeCli);
await upsertPrevSyncRecordByVaultAndProfile( await upsertPrevSyncRecordByVaultAndProfile(
db, db,
@@ -1062,7 +1158,7 @@ const dispatchOperationToActualV3 = async (
r.key, r.key,
vault, vault,
r.remote!.mtimeCli!, r.remote!.mtimeCli!,
password, cipher,
r.remote!.keyEnc r.remote!.keyEnc
); );
await upsertPrevSyncRecordByVaultAndProfile( await upsertPrevSyncRecordByVaultAndProfile(
@@ -1073,7 +1169,12 @@ const dispatchOperationToActualV3 = async (
); );
} else if (r.decision === "local_is_deleted_thus_also_delete_remote") { } else if (r.decision === "local_is_deleted_thus_also_delete_remote") {
// local is deleted, we need to delete remote now // local is deleted, we need to delete remote now
await client.deleteFromRemote(r.key, password, r.remote!.keyEnc); await client.deleteFromRemote(
r.key,
cipher,
r.remote!.keyEnc,
r.remote!.synthesizedFolder
);
await clearPrevSyncRecordByVaultAndProfile( await clearPrevSyncRecordByVaultAndProfile(
db, db,
vaultRandomID, vaultRandomID,
@@ -1100,11 +1201,11 @@ const dispatchOperationToActualV3 = async (
r.key, r.key,
vault, vault,
false, false,
password, cipher,
r.local!.keyEnc r.local!.keyEnc
); );
// we need to decrypt the key!!! // we need to decrypt the key!!!
await decryptRemoteEntityInplace(entity, password); await decryptRemoteEntityInplace(entity, cipher);
await fullfillMTimeOfRemoteEntityInplace(entity, mtimeCli); await fullfillMTimeOfRemoteEntityInplace(entity, mtimeCli);
await upsertPrevSyncRecordByVaultAndProfile( await upsertPrevSyncRecordByVaultAndProfile(
db, db,
@@ -1112,9 +1213,28 @@ const dispatchOperationToActualV3 = async (
profileID, profileID,
entity entity
); );
} else if (r.decision === "folder_to_be_deleted") { } else if (
await localDeleteFunc(r.key); r.decision === "folder_to_be_deleted_on_both" ||
await client.deleteFromRemote(r.key, password, r.remote!.keyEnc); r.decision === "folder_to_be_deleted_on_local" ||
r.decision === "folder_to_be_deleted_on_remote"
) {
if (
r.decision === "folder_to_be_deleted_on_both" ||
r.decision === "folder_to_be_deleted_on_local"
) {
await localDeleteFunc(r.key);
}
if (
r.decision === "folder_to_be_deleted_on_both" ||
r.decision === "folder_to_be_deleted_on_remote"
) {
await client.deleteFromRemote(
r.key,
cipher,
r.remote!.keyEnc,
r.remote!.synthesizedFolder
);
}
await clearPrevSyncRecordByVaultAndProfile( await clearPrevSyncRecordByVaultAndProfile(
db, db,
vaultRandomID, vaultRandomID,
@@ -1132,7 +1252,7 @@ export const doActualSync = async (
vaultRandomID: string, vaultRandomID: string,
profileID: string, profileID: string,
vault: Vault, vault: Vault,
password: string, cipher: Cipher,
concurrency: number, concurrency: number,
localDeleteFunc: any, localDeleteFunc: any,
protectModifyPercentage: number, protectModifyPercentage: number,
@@ -1142,13 +1262,15 @@ export const doActualSync = async (
) => { ) => {
console.debug(`concurrency === ${concurrency}`); console.debug(`concurrency === ${concurrency}`);
const { const {
onlyMarkSyncedOps,
folderCreationOps, folderCreationOps,
deletionOps, deletionOps,
uploadDownloads, uploadDownloads,
allFilesCount, allFilesCount,
realModifyDeleteCount, realModifyDeleteCount,
realTotalCount, realTotalCount,
} = splitThreeStepsOnEntityMappings(mixedEntityMappings); } = splitFourStepsOnEntityMappings(mixedEntityMappings);
// console.debug(`onlyMarkSyncedOps: ${JSON.stringify(onlyMarkSyncedOps)}`);
// console.debug(`folderCreationOps: ${JSON.stringify(folderCreationOps)}`); // console.debug(`folderCreationOps: ${JSON.stringify(folderCreationOps)}`);
// console.debug(`deletionOps: ${JSON.stringify(deletionOps)}`); // console.debug(`deletionOps: ${JSON.stringify(deletionOps)}`);
// console.debug(`uploadDownloads: ${JSON.stringify(uploadDownloads)}`); // console.debug(`uploadDownloads: ${JSON.stringify(uploadDownloads)}`);
@@ -1164,6 +1286,12 @@ export const doActualSync = async (
allFilesCount > 0 allFilesCount > 0
) { ) {
if ( if (
protectModifyPercentage === 100 &&
realModifyDeleteCount === allFilesCount
) {
// special treatment for 100%
// let it pass, we do nothing here
} else if (
realModifyDeleteCount * 100 >= realModifyDeleteCount * 100 >=
allFilesCount * protectModifyPercentage allFilesCount * protectModifyPercentage
) { ) {
@@ -1177,11 +1305,17 @@ export const doActualSync = async (
} }
} }
const nested = [folderCreationOps, deletionOps, uploadDownloads]; const nested = [
onlyMarkSyncedOps,
folderCreationOps,
deletionOps,
uploadDownloads,
];
const logTexts = [ const logTexts = [
`1. create all folders from shadowest to deepest`, `1. record the items already being synced`,
`2. delete files and folders from deepest to shadowest`, `2. create all folders from shadowest to deepest`,
`3. upload or download files in parallel, with the desired concurrency=${concurrency}`, `3. delete files and folders from deepest to shadowest`,
`4. upload or download files in parallel, with the desired concurrency=${concurrency}`,
]; ];
let realCounter = 0; let realCounter = 0;
@@ -1233,7 +1367,7 @@ export const doActualSync = async (
db, db,
vault, vault,
localDeleteFunc, localDeleteFunc,
password cipher
); );
console.debug(`finished ${key}`); console.debug(`finished ${key}`);
+6
View File
@@ -0,0 +1,6 @@
declare module "*.worker.ts" {
class WebpackWorker extends Worker {
constructor();
}
export default WebpackWorker;
}
+4
View File
@@ -8,6 +8,10 @@
font-weight: bold; font-weight: bold;
} }
.encryptionmethod-second-confirm {
font-weight: bold;
}
.settings-auth-related { .settings-auth-related {
border-top: 1px solid var(--background-modifier-border); border-top: 1px solid var(--background-modifier-border);
padding-top: 18px; padding-top: 18px;
@@ -10,13 +10,13 @@ import {
encryptStringToBase64url, encryptStringToBase64url,
getSizeFromEncToOrig, getSizeFromEncToOrig,
getSizeFromOrigToEnc, getSizeFromOrigToEnc,
} from "../src/encrypt"; } from "../src/encryptOpenSSL";
import { base64ToBase64url, bufferToArrayBuffer } from "../src/misc"; import { base64ToBase64url, bufferToArrayBuffer } from "../src/misc";
chai.use(chaiAsPromised); chai.use(chaiAsPromised);
const expect = chai.expect; const expect = chai.expect;
describe("Encryption tests", () => { describe("Encryption OpenSSL tests", () => {
beforeEach(function () { beforeEach(function () {
global.window = { global.window = {
crypto: require("crypto").webcrypto, crypto: require("crypto").webcrypto,
+53
View File
@@ -285,3 +285,56 @@ describe("Misc: special char for dir", () => {
expect(misc.checkHasSpecialCharForDir("xxx?yyy")).to.be.true; expect(misc.checkHasSpecialCharForDir("xxx?yyy")).to.be.true;
}); });
}); });
describe("Misc: Dropbox: should fix the folder name cases", () => {
it("should do nothing on empty folders", () => {
const input: any[] = [];
expect(misc.fixEntityListCasesInplace(input)).to.be.empty;
});
it("should sort folders by length by side effect", () => {
const input = [
{ keyRaw: "aaaa/" },
{ keyRaw: "bbb/" },
{ keyRaw: "c/" },
{ keyRaw: "dd/" },
];
const output = [
{ keyRaw: "c/" },
{ keyRaw: "dd/" },
{ keyRaw: "bbb/" },
{ keyRaw: "aaaa/" },
];
expect(misc.fixEntityListCasesInplace(input)).to.deep.equal(output);
});
it("should fix folder names", () => {
const input = [
{ keyRaw: "AAA/" },
{ keyRaw: "aaa/bbb/CCC.md" },
{ keyRaw: "aaa/BBB/" },
{ keyRaw: "ddd/" },
{ keyRaw: "DDD/EEE/fff.md" },
{ keyRaw: "DDD/eee/" },
{ keyRaw: "Ggg/" },
{ keyRaw: "ggG/hHH你好/Fff世界.md" },
{ keyRaw: "ggG/Hhh你好/" },
];
const output = [
{ keyRaw: "AAA/" },
{ keyRaw: "ddd/" },
{ keyRaw: "Ggg/" },
{ keyRaw: "AAA/BBB/" },
{ keyRaw: "ddd/eee/" },
{ keyRaw: "Ggg/Hhh你好/" },
{ keyRaw: "AAA/BBB/CCC.md" },
{ keyRaw: "ddd/eee/fff.md" },
{ keyRaw: "Ggg/Hhh你好/Fff世界.md" },
];
expect(misc.fixEntityListCasesInplace(input)).to.deep.equal(output);
});
});
+1 -1
View File
@@ -14,7 +14,7 @@
"esModuleInterop": true, "esModuleInterop": true,
"importHelpers": true, "importHelpers": true,
"isolatedModules": true, "isolatedModules": true,
"lib": ["dom", "es5", "scripthost", "es2015"] "lib": ["dom", "es5", "scripthost", "es2015", "webworker"]
}, },
"include": ["**/*.ts"] "include": ["**/*.ts"]
} }
+7
View File
@@ -32,6 +32,13 @@ module.exports = {
], ],
module: { module: {
rules: [ rules: [
{
test: /\.worker\.ts$/,
loader: "worker-loader",
options: {
inline: "no-fallback",
},
},
{ {
test: /\.tsx?$/, test: /\.tsx?$/,
use: "ts-loader", use: "ts-loader",