Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5481316b83 | ||
|
|
6586c2a43e | ||
|
|
e1d9fc1e9c | ||
|
|
ecc46f2ea1 | ||
|
|
c04876e0c5 | ||
|
|
5402baed0a | ||
|
|
5aa96a4ddb | ||
|
|
2e6848f901 | ||
|
|
9c830c2c14 | ||
|
|
3574b56acb | ||
|
|
18cb8ba413 | ||
|
|
76e61b6ebf | ||
|
|
3dfe215103 | ||
|
|
94c7a4a874 | ||
|
|
b573b2859c | ||
|
|
e2c4d158b1 | ||
|
|
55890611e2 | ||
|
|
5acd1551c9 | ||
|
|
ef2c45a11d | ||
|
|
c1771bb117 | ||
|
|
ddb86745dd | ||
|
|
971719b710 |
@@ -0,0 +1,65 @@
|
||||
name: Bug Report
|
||||
description: File a bug report
|
||||
title: "[Bug]: "
|
||||
labels: ["bug"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this bug report!
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: What happened?
|
||||
description: What did you expect to happen?
|
||||
placeholder: Tell us what you see!
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: os
|
||||
attributes:
|
||||
label: What OS are you using?
|
||||
multiple: true
|
||||
options:
|
||||
- Windows
|
||||
- Linux
|
||||
- macOS
|
||||
- iOS (iPhone, iPad)
|
||||
- Android
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: service
|
||||
attributes:
|
||||
label: What remote cloud services are you using?
|
||||
multiple: true
|
||||
options:
|
||||
- S3
|
||||
- OneDrive for personal
|
||||
- Dropbox
|
||||
- webdav
|
||||
- others
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: version-plugin
|
||||
attributes:
|
||||
label: Version of the plugin
|
||||
description: What version of the plugin are you running?
|
||||
validations:
|
||||
required: false
|
||||
- type: input
|
||||
id: version-obsidian
|
||||
attributes:
|
||||
label: Version of Obsidian
|
||||
description: What version of Obsidian are you running?
|
||||
validations:
|
||||
required: false
|
||||
- type: checkboxes
|
||||
id: ensure-no-sensitive-information
|
||||
attributes:
|
||||
label: Ensure no sensitive information
|
||||
description: By submitting this issue, you ensure that no sensitive information is submitted in the issue.
|
||||
options:
|
||||
- label: I ensure that no sensitive information is submitted in the issue.
|
||||
required: true
|
||||
@@ -0,0 +1 @@
|
||||
blank_issues_enabled: false
|
||||
@@ -0,0 +1,37 @@
|
||||
name: Feature Request
|
||||
description: Some idea about new features
|
||||
title: "[Feature Request]: "
|
||||
labels: ["enhancement"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this bug report!
|
||||
- type: textarea
|
||||
id: what-are-you-expecting
|
||||
attributes:
|
||||
label: What feature are you suggesting?
|
||||
description: What feature are you suggesting?
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: service
|
||||
attributes:
|
||||
label: What remote cloud services are you using, or suggesting adding the feature to?
|
||||
multiple: true
|
||||
options:
|
||||
- S3
|
||||
- OneDrive for personal
|
||||
- Dropbox
|
||||
- webdav
|
||||
- others
|
||||
validations:
|
||||
required: false
|
||||
- type: checkboxes
|
||||
id: ensure-no-sensitive-information
|
||||
attributes:
|
||||
label: Ensure no sensitive information
|
||||
description: By submitting this issue, you ensure that no sensitive information is submitted in the issue.
|
||||
options:
|
||||
- label: I ensure that no sensitive information is submitted in the issue.
|
||||
required: true
|
||||
@@ -51,7 +51,7 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a
|
||||
|
||||
## Download and Install
|
||||
|
||||
- Option #1: Search in the official "community plugin list", or click [obsidian://show-plugin?id=remotely-save](obsidian://show-plugin?id=remotely-save), then install the plugin.
|
||||
- Option #1: Search in the official "community plugin list", or visit this: [https://obsidian.md/plugins?id=remotely-save](https://obsidian.md/plugins?id=remotely-save) (which should redirect you into Obsidian app), then install the plugin.
|
||||
- Option #2: You can also use [Obsidian42 - BRAT](https://github.com/TfTHacker/obsidian42-brat) to install this plugin. Input `fyears/remotely-save` in the configuration of BRAT.
|
||||
- Option #3: [](https://github.com/fyears/remotely-save/releases) Manually download assets (`main.js`, `manifest.json`, `styles.css`) from the latest release.
|
||||
- Option #4: [](https://github.com/fyears/remotely-save/actions/workflows/auto-build.yml) Every artifacts are placed in the "Summary" under every successful builds. It's automatically generated by every commit, may break something.
|
||||
@@ -101,6 +101,10 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a
|
||||
- In auto sync mode, if any error occurs, the plugin would **fail silently**.
|
||||
- Auto sync only works when Obsidian is being opened. It's **technically impossible** to auto sync while Obsidian is in background, because the plugin just works in the browser environment provided by Obsidian.
|
||||
|
||||
## How To Debug
|
||||
|
||||
See [here](./docs/how_to_debug/README.md) for more details.
|
||||
|
||||
## Bonus: Import And Export Not-Oauth2 Plugin Settings By QR Code
|
||||
|
||||
See [here](./docs/import_export_some_settings.md) for more details.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# How To Debug
|
||||
|
||||
Ideally, users do not need to debug anything. But if something bad happened, we have to dig into details.
|
||||
|
||||
## Easy: Export Sync Plans
|
||||
|
||||
See [here](./export_sync_plans.md).
|
||||
|
||||
## Advanced: Check Console Output
|
||||
|
||||
See [here](./check_console_output.md).
|
||||
@@ -0,0 +1,17 @@
|
||||
# Check Console Output
|
||||
|
||||
If you are using Obsidian on desktop, you can check the Obsidian console.
|
||||
|
||||
## Disable Auto Sync Firstly
|
||||
|
||||
You should disable auto sync to avoid any unexpected running.
|
||||
|
||||
## Set The Output Level To Debug
|
||||
|
||||
Go to the plugin settings, scroll down to the section "Debug" -> "alter console log level", and change it from "info" to "debug".
|
||||
|
||||
## Check The Output
|
||||
|
||||
Then, press the keyboard shortcut "ctrl+shift+i" if you are on Windows or Linux, or press "cmd+shift+i" if you are on macOS. You should be able to see the console of Obsidian.
|
||||
|
||||
Trigger the sync manually (by clicking the icon on the ribbon sidebar). Something (hopefully) helpful should show up in the console. You could understand what happened and what goes wrong more explictly by checking the output.
|
||||
@@ -0,0 +1,95 @@
|
||||
# Export Sync Plans
|
||||
|
||||
## What's this?
|
||||
|
||||
Everytime the plugin starts a sync, it gathers all required information together, generates a "sync plan" of every operations to every files and folders, and assign the corresponding actual operations.
|
||||
|
||||
Thus, if something goes wrong, we should check the sync plan firstly.
|
||||
|
||||
## How To Export The Plans?
|
||||
|
||||
Please read through the following instructions.
|
||||
|
||||
### Disable Auto Sync Firstly
|
||||
|
||||
You should disable auto sync to avoid any unexpected running.
|
||||
|
||||
### Manual Sync If Not Yet
|
||||
|
||||
You should at least sync once, so that at least one sync plan is generated and saved. If you have synced the vualt before, there should be some sync plans already saved.
|
||||
|
||||
### Export To The File
|
||||
|
||||
Go to the plugin settings, scroll down to the section "Debug" -> "export sync plans", and click the button "Export". \*\*It would generate a new folder `_debug_remotely_save/` in your vault, and generate a file `sync_plans_hist_exported_on_{a_timestamp},md.` inside that folder.
|
||||
|
||||
## How To Read The Plans
|
||||
|
||||
Open the genrated `sync_plans_hist_exported_on_{a_timestamp},md.`. You should see a json, or multiple jsons. Every json represents a sync plan.
|
||||
|
||||
A sync plan looks like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"ts": 1646960867560,
|
||||
"remoteType": "onedrive",
|
||||
"mixedStates": {
|
||||
"abc.md": {
|
||||
"key": "abc.md",
|
||||
"existRemote": true,
|
||||
"mtimeRemote": 1646566632000,
|
||||
"sizeRemote": 56797,
|
||||
"remoteEncryptedKey": "abc.md",
|
||||
"changeMtimeUsingMapping": true,
|
||||
"existLocal": true,
|
||||
"mtimeLocal": 1646566632000,
|
||||
"sizeLocal": 56797,
|
||||
"decision": "skipUploading",
|
||||
"decisionBranch": 1
|
||||
},
|
||||
"New folder/": {
|
||||
"key": "New folder/",
|
||||
"deltimeRemote": 1646925354372,
|
||||
"existLocal": false,
|
||||
"existRemote": false,
|
||||
"decision": "keepRemoteDelHistFolder",
|
||||
"decisionBranch": 9
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
We usually care about the `mixedStates` property. As you may guess, every item in `mixedStates` represent a file or a folder.
|
||||
|
||||
We should find out the file/folder we are interested in (or we believe something goes wrong), then checkout the following properties:
|
||||
|
||||
```
|
||||
decision
|
||||
What decision is made.
|
||||
|
||||
decisionBranch
|
||||
It's a mark of the actual logic in the sync code. Useful to debug.
|
||||
|
||||
existRemote
|
||||
Does the file/folder exist on the remote service?
|
||||
|
||||
mtimeRemote
|
||||
The "last modeified time" on the remote service.
|
||||
|
||||
deltimeRemote
|
||||
The "deletion time" on the remote record.
|
||||
|
||||
existLocal
|
||||
Does the file/folder exist locally?
|
||||
|
||||
mtimeLocal
|
||||
The max of "last modeified time" and "creation time" locally.
|
||||
|
||||
deltimeLocal
|
||||
The "deletion time" locally.
|
||||
```
|
||||
|
||||
The `decision` SHOULD be determined by the modified times and deletion times, by the logic described in [the doc of sync alogorithm](../sync_algorithm_v2.md). In short, we collect four timestamps (`mtimeRemote`, `deltimeRemote`, `mtimeLocal`, `deltimeLocal`), and respect the max timestamp and its corresponding operation.
|
||||
|
||||
## Common Issues
|
||||
|
||||
Some users report that their "last modeified time"s or "creation time"s are not set correctly by the operating system. In this case, the plugin cannot do anything because it determines the sync plan by comparing the timestamps. It's suggested to check the settings of the operating system or check whether other programs are doing something to the files.
|
||||
@@ -17,6 +17,8 @@ We list all combinations mutually exclusive and collectively exhaustive.
|
||||
|
||||
### Files
|
||||
|
||||
In short, we collect four timestamps, and respect the max timestamp and its corresponding operation.
|
||||
|
||||
| t1 | t2 | t3 | t4 | local file to do | remote file to do | local del history to do | remote del history to do | equal to sync v2 branch |
|
||||
| -------------- | -------------- | -------------- | -------------- | ---------------- | ----------------- | ----------------------- | ------------------------ | ----------------------- |
|
||||
| mtime_remote | mtime_local | deltime_remote | deltime_local | del_if_exists | del_if_exists | clean | upload_local_del_history | |
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"id": "remotely-save",
|
||||
"name": "Remotely Save",
|
||||
"version": "0.3.0",
|
||||
"minAppVersion": "0.12.15",
|
||||
"version": "0.3.5",
|
||||
"minAppVersion": "0.13.21",
|
||||
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
|
||||
"author": "fyears",
|
||||
"authorUrl": "https://github.com/fyears",
|
||||
|
||||
+9
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "remotely-save",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.5",
|
||||
"description": "This is yet another sync plugin for Obsidian app.",
|
||||
"scripts": {
|
||||
"dev2": "node esbuild.config.mjs",
|
||||
@@ -52,8 +52,12 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.37.0",
|
||||
"@aws-sdk/lib-storage": "^3.40.1",
|
||||
"@aws-sdk/fetch-http-handler": "^3.53.0",
|
||||
"@aws-sdk/lib-storage": "^3.53.1",
|
||||
"@aws-sdk/protocol-http": "^3.53.0",
|
||||
"@aws-sdk/querystring-builder": "^3.53.0",
|
||||
"@aws-sdk/signature-v4-crt": "^3.37.0",
|
||||
"@aws-sdk/types": "^3.53.0",
|
||||
"@azure/msal-node": "^1.6.0",
|
||||
"@fyears/tsqueue": "^1.0.1",
|
||||
"@microsoft/microsoft-graph-client": "^3.0.1",
|
||||
@@ -65,12 +69,14 @@
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"dropbox": "^10.22.0",
|
||||
"feather-icons": "^4.28.0",
|
||||
"http-status-codes": "^2.2.0",
|
||||
"localforage": "^1.10.0",
|
||||
"lodash": "^4.17.21",
|
||||
"loglevel": "^1.8.0",
|
||||
"mime-types": "^2.1.33",
|
||||
"nanoid": "^3.1.30",
|
||||
"obsidian": "^0.12.0",
|
||||
"obsidian": "^0.13.26",
|
||||
"p-queue": "^7.2.0",
|
||||
"path-browserify": "^1.0.1",
|
||||
"process": "^0.11.10",
|
||||
"qrcode": "^1.5.0",
|
||||
|
||||
@@ -11,6 +11,7 @@ export interface S3Config {
|
||||
s3AccessKeyID: string;
|
||||
s3SecretAccessKey: string;
|
||||
s3BucketName: string;
|
||||
bypassCorsLocally?: boolean;
|
||||
}
|
||||
|
||||
export interface DropboxConfig {
|
||||
@@ -56,7 +57,9 @@ export interface RemotelySavePluginSettings {
|
||||
currLogLevel?: string;
|
||||
vaultRandomID?: string;
|
||||
autoRunEveryMilliseconds?: number;
|
||||
initRunAfterMilliseconds?: number;
|
||||
agreeToUploadExtraMetadata?: boolean;
|
||||
concurrency?: number;
|
||||
}
|
||||
|
||||
export interface RemoteItem {
|
||||
@@ -113,3 +116,6 @@ export interface FileOrFolderMixedState {
|
||||
syncDone?: "done";
|
||||
remoteEncryptedKey?: string;
|
||||
}
|
||||
|
||||
export const API_VER_STAT_FOLDER = "0.13.27";
|
||||
export const API_VER_REQURL = "0.13.26";
|
||||
|
||||
+30
-7
@@ -53,7 +53,9 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
|
||||
currLogLevel: "info",
|
||||
vaultRandomID: "",
|
||||
autoRunEveryMilliseconds: -1,
|
||||
initRunAfterMilliseconds: -1,
|
||||
agreeToUploadExtraMetadata: false,
|
||||
concurrency: 5,
|
||||
};
|
||||
|
||||
interface OAuth2Info {
|
||||
@@ -64,7 +66,7 @@ interface OAuth2Info {
|
||||
revokeAuthSetting?: Setting;
|
||||
}
|
||||
|
||||
type SyncTriggerSourceType = "manual" | "auto" | "dry";
|
||||
type SyncTriggerSourceType = "manual" | "auto" | "dry" | "autoOnceInit";
|
||||
|
||||
const iconNameSyncWait = `remotely-save-sync-wait`;
|
||||
const iconNameSyncRunning = `remotely-save-sync-running`;
|
||||
@@ -152,7 +154,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
() => self.saveSettings()
|
||||
);
|
||||
const remoteRsp = await client.listFromRemote();
|
||||
log.info(remoteRsp);
|
||||
log.debug(remoteRsp);
|
||||
|
||||
getNotice(`3/${MAX_STEPS} Checking password correct or not.`);
|
||||
this.syncStatus = "checking_password";
|
||||
@@ -199,6 +201,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
origMetadataOnRemote.deletions,
|
||||
localHistory,
|
||||
client.serviceType,
|
||||
this.app.vault,
|
||||
this.settings.password
|
||||
);
|
||||
log.info(plan.mixedStates); // for debugging
|
||||
@@ -229,6 +232,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
deletions,
|
||||
(key: string) => self.trash(key),
|
||||
this.settings.password,
|
||||
this.settings.concurrency,
|
||||
(i: number, totalCount: number, pathName: string, decision: string) =>
|
||||
self.setCurrSyncMsg(i, totalCount, pathName, decision)
|
||||
);
|
||||
@@ -531,6 +535,9 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
if (!this.settings.agreeToUploadExtraMetadata) {
|
||||
const syncAlgoV2Modal = new SyncAlgoV2Modal(this.app, this);
|
||||
syncAlgoV2Modal.open();
|
||||
} else {
|
||||
this.enableAutoSyncIfSet();
|
||||
this.enableInitSyncIfSet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,11 +666,27 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
this.settings.autoRunEveryMilliseconds !== null &&
|
||||
this.settings.autoRunEveryMilliseconds > 0
|
||||
) {
|
||||
const intervalID = window.setInterval(() => {
|
||||
this.syncRun("auto");
|
||||
}, this.settings.autoRunEveryMilliseconds);
|
||||
this.autoRunIntervalID = intervalID;
|
||||
this.registerInterval(intervalID);
|
||||
this.app.workspace.onLayoutReady(() => {
|
||||
const intervalID = window.setInterval(() => {
|
||||
this.syncRun("auto");
|
||||
}, this.settings.autoRunEveryMilliseconds);
|
||||
this.autoRunIntervalID = intervalID;
|
||||
this.registerInterval(intervalID);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
enableInitSyncIfSet() {
|
||||
if (
|
||||
this.settings.initRunAfterMilliseconds !== undefined &&
|
||||
this.settings.initRunAfterMilliseconds !== null &&
|
||||
this.settings.initRunAfterMilliseconds > 0
|
||||
) {
|
||||
this.app.workspace.onLayoutReady(() => {
|
||||
window.setTimeout(() => {
|
||||
this.syncRun("autoOnceInit");
|
||||
}, this.settings.initRunAfterMilliseconds);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+31
-1
@@ -79,7 +79,9 @@ export const mkdirpInVault = async (thePath: string, vault: Vault) => {
|
||||
* @param b Buffer
|
||||
* @returns ArrayBuffer
|
||||
*/
|
||||
export const bufferToArrayBuffer = (b: Buffer | Uint8Array) => {
|
||||
export const bufferToArrayBuffer = (
|
||||
b: Buffer | Uint8Array | ArrayBufferView
|
||||
) => {
|
||||
return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
|
||||
};
|
||||
|
||||
@@ -230,3 +232,31 @@ export const getRandomArrayBuffer = (byteLength: number) => {
|
||||
export const reverseString = (x: string) => {
|
||||
return [...x].reverse().join("");
|
||||
};
|
||||
|
||||
export interface SplitRange {
|
||||
partNum: number; // startting from 1
|
||||
start: number;
|
||||
end: number; // exclusive
|
||||
}
|
||||
export const getSplitRanges = (bytesTotal: number, bytesEachPart: number) => {
|
||||
const res: SplitRange[] = [];
|
||||
if (bytesEachPart >= bytesTotal) {
|
||||
res.push({
|
||||
partNum: 1,
|
||||
start: 0,
|
||||
end: bytesTotal,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
const remainder = bytesTotal % bytesEachPart;
|
||||
const howMany =
|
||||
Math.floor(bytesTotal / bytesEachPart) + (remainder === 0 ? 0 : 1);
|
||||
for (let i = 0; i < howMany; ++i) {
|
||||
res.push({
|
||||
partNum: i + 1,
|
||||
start: bytesEachPart * i,
|
||||
end: Math.min(bytesEachPart * (i + 1), bytesTotal),
|
||||
});
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
+10
-3
@@ -156,13 +156,20 @@ const fixLastModifiedTimeInplace = (allFilesFolders: RemoteItem[]) => {
|
||||
// see https://dropbox.tech/developers/pkce--what-and-why-
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
export const getAuthUrlAndVerifier = async (appKey: string) => {
|
||||
export const getAuthUrlAndVerifier = async (
|
||||
appKey: string,
|
||||
needManualPatse: boolean = false
|
||||
) => {
|
||||
const auth = new DropboxAuth({
|
||||
clientId: appKey,
|
||||
});
|
||||
|
||||
const callback = needManualPatse
|
||||
? undefined
|
||||
: `obsidian://${COMMAND_CALLBACK_DROPBOX}`;
|
||||
const authUrl = (
|
||||
await auth.getAuthenticationUrl(
|
||||
`obsidian://${COMMAND_CALLBACK_DROPBOX}`,
|
||||
callback,
|
||||
undefined,
|
||||
"code",
|
||||
"offline",
|
||||
@@ -456,7 +463,7 @@ export const uploadToRemote = async (
|
||||
let localContent = undefined;
|
||||
if (uploadRaw) {
|
||||
if (typeof rawContent === "string") {
|
||||
localContent = new TextEncoder().encode(rawContent);
|
||||
localContent = new TextEncoder().encode(rawContent).buffer;
|
||||
} else {
|
||||
localContent = rawContent;
|
||||
}
|
||||
|
||||
+112
-65
@@ -7,8 +7,9 @@ import type {
|
||||
} from "@microsoft/microsoft-graph-types";
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import * as origLog from "loglevel";
|
||||
import { request, Vault } from "obsidian";
|
||||
import { request, requestUrl, requireApiVersion, Vault } from "obsidian";
|
||||
import {
|
||||
API_VER_REQURL,
|
||||
COMMAND_CALLBACK_ONEDRIVE,
|
||||
OAUTH2_FORCE_EXPIRE_MILLISECONDS,
|
||||
OnedriveConfig,
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
} from "./baseTypes";
|
||||
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
|
||||
import {
|
||||
bufferToArrayBuffer,
|
||||
getRandomArrayBuffer,
|
||||
getRandomIntInclusive,
|
||||
mkdirpInVault,
|
||||
@@ -482,28 +484,45 @@ export class WrappedOnedriveClient {
|
||||
deleteJson = async (pathFragOrig: string) => {
|
||||
const theUrl = this.buildUrl(pathFragOrig);
|
||||
log.debug(`deleteJson, theUrl=${theUrl}`);
|
||||
// TODO: delete does not have response, so Obsidian request may have error
|
||||
// currently downgraded to fetch()!
|
||||
await fetch(theUrl, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: `Bearer ${await this.authGetter.getAccessToken()}`,
|
||||
},
|
||||
});
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
await requestUrl({
|
||||
url: theUrl,
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: `Bearer ${await this.authGetter.getAccessToken()}`,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await fetch(theUrl, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: `Bearer ${await this.authGetter.getAccessToken()}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
putArrayBuffer = async (pathFragOrig: string, payload: ArrayBuffer) => {
|
||||
const theUrl = this.buildUrl(pathFragOrig);
|
||||
log.debug(`putArrayBuffer, theUrl=${theUrl}`);
|
||||
// TODO: Obsidian doesn't support ArrayBuffer
|
||||
// currently downgraded to fetch()!
|
||||
await fetch(theUrl, {
|
||||
method: "PUT",
|
||||
body: payload,
|
||||
headers: {
|
||||
Authorization: `Bearer ${await this.authGetter.getAccessToken()}`,
|
||||
},
|
||||
});
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
await requestUrl({
|
||||
url: theUrl,
|
||||
method: "PUT",
|
||||
body: payload,
|
||||
headers: {
|
||||
Authorization: `Bearer ${await this.authGetter.getAccessToken()}`,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await fetch(theUrl, {
|
||||
method: "PUT",
|
||||
body: payload,
|
||||
headers: {
|
||||
Authorization: `Bearer ${await this.authGetter.getAccessToken()}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -527,20 +546,31 @@ export class WrappedOnedriveClient {
|
||||
rangeEnd - 1
|
||||
}, len=${rangeEnd - rangeStart}, size=${size}`
|
||||
);
|
||||
// TODO: Obsidian doesn't support ArrayBuffer
|
||||
// currently downgraded to fetch()!
|
||||
// AND, NO AUTH HEADER here!
|
||||
const res = await fetch(theUrl, {
|
||||
method: "PUT",
|
||||
body: payload.subarray(rangeStart, rangeEnd),
|
||||
headers: {
|
||||
"Content-Length": `${rangeEnd - rangeStart}`,
|
||||
"Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`,
|
||||
"Content-Type": "application/octet-stream",
|
||||
},
|
||||
});
|
||||
|
||||
return res.json() as DriveItem | UploadSession;
|
||||
// NO AUTH HEADER here!
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
const res = await requestUrl({
|
||||
url: theUrl,
|
||||
method: "PUT",
|
||||
body: bufferToArrayBuffer(payload.subarray(rangeStart, rangeEnd)),
|
||||
headers: {
|
||||
// no "Content-Length" allowed here
|
||||
"Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`,
|
||||
"Content-Type": "application/octet-stream",
|
||||
},
|
||||
});
|
||||
return res.json as DriveItem | UploadSession;
|
||||
} else {
|
||||
const res = await fetch(theUrl, {
|
||||
method: "PUT",
|
||||
body: payload.subarray(rangeStart, rangeEnd),
|
||||
headers: {
|
||||
"Content-Length": `${rangeEnd - rangeStart}`,
|
||||
"Content-Range": `bytes ${rangeStart}-${rangeEnd - 1}/${size}`,
|
||||
"Content-Type": "application/octet-stream",
|
||||
},
|
||||
});
|
||||
return (await res.json()) as DriveItem | UploadSession;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -690,7 +720,7 @@ export const uploadToRemote = async (
|
||||
let localContent = undefined;
|
||||
if (uploadRaw) {
|
||||
if (typeof rawContent === "string") {
|
||||
localContent = new TextEncoder().encode(rawContent);
|
||||
localContent = new TextEncoder().encode(rawContent).buffer;
|
||||
} else {
|
||||
localContent = rawContent;
|
||||
}
|
||||
@@ -704,40 +734,52 @@ export const uploadToRemote = async (
|
||||
|
||||
// no need to create parent folders firstly, cool!
|
||||
|
||||
// upload large files!
|
||||
// ref: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online
|
||||
|
||||
// 1. create uploadSession
|
||||
// uploadFile already starts with /drive/special/approot:/${vaultName}
|
||||
const s: UploadSession = await client.postJson(
|
||||
`${uploadFile}:/createUploadSession`,
|
||||
{
|
||||
item: {
|
||||
"@microsoft.graph.conflictBehavior": "replace",
|
||||
},
|
||||
}
|
||||
);
|
||||
const uploadUrl = s.uploadUrl;
|
||||
log.debug("uploadSession = ");
|
||||
log.debug(s);
|
||||
|
||||
// 2. upload by ranges
|
||||
// convert to uint8
|
||||
const uint8 = new Uint8Array(remoteContent);
|
||||
// hard code range size
|
||||
const MIN_UNIT = 327680; // bytes in msft doc, about 0.32768 MB
|
||||
const RANGE_SIZE = MIN_UNIT * 20; // about 6.5536 MB
|
||||
// upload the ranges one by one
|
||||
let rangeStart = 0;
|
||||
while (rangeStart < uint8.byteLength) {
|
||||
await client.putUint8ArrayByRange(
|
||||
uploadUrl,
|
||||
uint8,
|
||||
rangeStart,
|
||||
Math.min(rangeStart + RANGE_SIZE, uint8.byteLength),
|
||||
uint8.byteLength
|
||||
|
||||
if (remoteContent.byteLength <= RANGE_SIZE) {
|
||||
// directly using put!
|
||||
await client.putArrayBuffer(
|
||||
`${uploadFile}:/content?${new URLSearchParams({
|
||||
"@microsoft.graph.conflictBehavior": "replace",
|
||||
})}`,
|
||||
remoteContent
|
||||
);
|
||||
rangeStart += RANGE_SIZE;
|
||||
} else {
|
||||
// upload large files!
|
||||
// ref: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online
|
||||
|
||||
// 1. create uploadSession
|
||||
// uploadFile already starts with /drive/special/approot:/${vaultName}
|
||||
const s: UploadSession = await client.postJson(
|
||||
`${uploadFile}:/createUploadSession`,
|
||||
{
|
||||
item: {
|
||||
"@microsoft.graph.conflictBehavior": "replace",
|
||||
},
|
||||
}
|
||||
);
|
||||
const uploadUrl = s.uploadUrl;
|
||||
log.debug("uploadSession = ");
|
||||
log.debug(s);
|
||||
|
||||
// 2. upload by ranges
|
||||
// convert to uint8
|
||||
const uint8 = new Uint8Array(remoteContent);
|
||||
|
||||
// upload the ranges one by one
|
||||
let rangeStart = 0;
|
||||
while (rangeStart < uint8.byteLength) {
|
||||
await client.putUint8ArrayByRange(
|
||||
uploadUrl,
|
||||
uint8,
|
||||
rangeStart,
|
||||
Math.min(rangeStart + RANGE_SIZE, uint8.byteLength),
|
||||
uint8.byteLength
|
||||
);
|
||||
rangeStart += RANGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
const res = await getRemoteMeta(client, uploadFile);
|
||||
@@ -755,8 +797,13 @@ const downloadFromRemoteRaw = async (
|
||||
`${key}?$select=@microsoft.graph.downloadUrl`
|
||||
);
|
||||
const downloadUrl: string = rsp["@microsoft.graph.downloadUrl"];
|
||||
const content = await (await fetch(downloadUrl)).arrayBuffer();
|
||||
return content;
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
const content = (await requestUrl({ url: downloadUrl })).arrayBuffer;
|
||||
return content;
|
||||
} else {
|
||||
const content = await (await fetch(downloadUrl)).arrayBuffer();
|
||||
return content;
|
||||
}
|
||||
};
|
||||
|
||||
export const downloadFromRemote = async (
|
||||
|
||||
+151
-16
@@ -11,11 +11,26 @@ import {
|
||||
S3Client,
|
||||
} from "@aws-sdk/client-s3";
|
||||
import { Upload } from "@aws-sdk/lib-storage";
|
||||
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
|
||||
import {
|
||||
FetchHttpHandler,
|
||||
FetchHttpHandlerOptions,
|
||||
} from "@aws-sdk/fetch-http-handler";
|
||||
// @ts-ignore
|
||||
import { requestTimeout } from "@aws-sdk/fetch-http-handler/dist-es/request-timeout";
|
||||
import { buildQueryString } from "@aws-sdk/querystring-builder";
|
||||
import { HeaderBag, HttpHandlerOptions, Provider } from "@aws-sdk/types";
|
||||
import { Buffer } from "buffer";
|
||||
import * as mime from "mime-types";
|
||||
import { Vault } from "obsidian";
|
||||
import {
|
||||
Vault,
|
||||
requestUrl,
|
||||
RequestUrlParam,
|
||||
RequestUrlResponse,
|
||||
requireApiVersion,
|
||||
} from "obsidian";
|
||||
import { Readable } from "stream";
|
||||
import { RemoteItem, S3Config } from "./baseTypes";
|
||||
import { API_VER_REQURL, RemoteItem, S3Config } from "./baseTypes";
|
||||
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
|
||||
import {
|
||||
arrayBufferToBuffer,
|
||||
@@ -28,12 +43,117 @@ export { S3Client } from "@aws-sdk/client-s3";
|
||||
import * as origLog from "loglevel";
|
||||
const log = origLog.getLogger("rs-default");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// special handler using Obsidian requestUrl
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* This is close to origin implementation of FetchHttpHandler
|
||||
* https://github.com/aws/aws-sdk-js-v3/blob/main/packages/fetch-http-handler/src/fetch-http-handler.ts
|
||||
* that is released under Apache 2 License.
|
||||
* But this uses Obsidian requestUrl instead.
|
||||
*/
|
||||
class ObsHttpHandler extends FetchHttpHandler {
|
||||
requestTimeoutInMs: number;
|
||||
constructor(options?: FetchHttpHandlerOptions) {
|
||||
super(options);
|
||||
this.requestTimeoutInMs =
|
||||
options === undefined ? undefined : options.requestTimeout;
|
||||
}
|
||||
async handle(
|
||||
request: HttpRequest,
|
||||
{ abortSignal }: HttpHandlerOptions = {}
|
||||
): Promise<{ response: HttpResponse }> {
|
||||
if (abortSignal?.aborted) {
|
||||
const abortError = new Error("Request aborted");
|
||||
abortError.name = "AbortError";
|
||||
return Promise.reject(abortError);
|
||||
}
|
||||
|
||||
let path = request.path;
|
||||
if (request.query) {
|
||||
const queryString = buildQueryString(request.query);
|
||||
if (queryString) {
|
||||
path += `?${queryString}`;
|
||||
}
|
||||
}
|
||||
|
||||
const { port, method } = request;
|
||||
const url = `${request.protocol}//${request.hostname}${
|
||||
port ? `:${port}` : ""
|
||||
}${path}`;
|
||||
const body =
|
||||
method === "GET" || method === "HEAD" ? undefined : request.body;
|
||||
|
||||
const transformedHeaders = { ...request.headers };
|
||||
delete transformedHeaders["host"];
|
||||
delete transformedHeaders["Host"];
|
||||
delete transformedHeaders["content-length"];
|
||||
delete transformedHeaders["Content-Length"];
|
||||
|
||||
let contentType: string = undefined;
|
||||
if (transformedHeaders["content-type"] !== undefined) {
|
||||
contentType = transformedHeaders["content-type"];
|
||||
}
|
||||
|
||||
let transformedBody: any = body;
|
||||
if (ArrayBuffer.isView(body)) {
|
||||
transformedBody = bufferToArrayBuffer(body);
|
||||
}
|
||||
|
||||
const param: RequestUrlParam = {
|
||||
body: transformedBody,
|
||||
headers: transformedHeaders,
|
||||
method: method,
|
||||
url: url,
|
||||
contentType: contentType,
|
||||
};
|
||||
|
||||
const raceOfPromises = [
|
||||
requestUrl(param).then((rsp) => {
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
start(controller) {
|
||||
controller.enqueue(new Uint8Array(rsp.arrayBuffer));
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
return {
|
||||
response: new HttpResponse({
|
||||
headers: rsp.headers,
|
||||
statusCode: rsp.status,
|
||||
body: stream,
|
||||
}),
|
||||
};
|
||||
}),
|
||||
requestTimeout(this.requestTimeoutInMs),
|
||||
];
|
||||
|
||||
if (abortSignal) {
|
||||
raceOfPromises.push(
|
||||
new Promise<never>((resolve, reject) => {
|
||||
abortSignal.onabort = () => {
|
||||
const abortError = new Error("Request aborted");
|
||||
abortError.name = "AbortError";
|
||||
reject(abortError);
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
return Promise.race(raceOfPromises);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// other stuffs
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
export const DEFAULT_S3_CONFIG = {
|
||||
s3Endpoint: "",
|
||||
s3Region: "",
|
||||
s3AccessKeyID: "",
|
||||
s3SecretAccessKey: "",
|
||||
s3BucketName: "",
|
||||
bypassCorsLocally: true,
|
||||
};
|
||||
|
||||
export type S3ObjectType = _Object;
|
||||
@@ -66,15 +186,29 @@ export const getS3Client = (s3Config: S3Config) => {
|
||||
if (!(endpoint.startsWith("http://") || endpoint.startsWith("https://"))) {
|
||||
endpoint = `https://${endpoint}`;
|
||||
}
|
||||
const s3Client = new S3Client({
|
||||
region: s3Config.s3Region,
|
||||
endpoint: endpoint,
|
||||
credentials: {
|
||||
accessKeyId: s3Config.s3AccessKeyID,
|
||||
secretAccessKey: s3Config.s3SecretAccessKey,
|
||||
},
|
||||
});
|
||||
return s3Client;
|
||||
|
||||
if (requireApiVersion(API_VER_REQURL) && s3Config.bypassCorsLocally) {
|
||||
const s3Client = new S3Client({
|
||||
region: s3Config.s3Region,
|
||||
endpoint: endpoint,
|
||||
credentials: {
|
||||
accessKeyId: s3Config.s3AccessKeyID,
|
||||
secretAccessKey: s3Config.s3SecretAccessKey,
|
||||
},
|
||||
requestHandler: new ObsHttpHandler(),
|
||||
});
|
||||
return s3Client;
|
||||
} else {
|
||||
const s3Client = new S3Client({
|
||||
region: s3Config.s3Region,
|
||||
endpoint: endpoint,
|
||||
credentials: {
|
||||
accessKeyId: s3Config.s3AccessKeyID,
|
||||
secretAccessKey: s3Config.s3SecretAccessKey,
|
||||
},
|
||||
});
|
||||
return s3Client;
|
||||
}
|
||||
};
|
||||
|
||||
export const getRemoteMeta = async (
|
||||
@@ -141,7 +275,7 @@ export const uploadToRemote = async (
|
||||
let localContent = undefined;
|
||||
if (uploadRaw) {
|
||||
if (typeof rawContent === "string") {
|
||||
localContent = new TextEncoder().encode(rawContent);
|
||||
localContent = new TextEncoder().encode(rawContent).buffer;
|
||||
} else {
|
||||
localContent = rawContent;
|
||||
}
|
||||
@@ -152,12 +286,13 @@ export const uploadToRemote = async (
|
||||
if (password !== "") {
|
||||
remoteContent = await encryptArrayBuffer(localContent, password);
|
||||
}
|
||||
const body = arrayBufferToBuffer(remoteContent);
|
||||
|
||||
const bytesIn5MB = 5242880;
|
||||
const body = new Uint8Array(remoteContent);
|
||||
const upload = new Upload({
|
||||
client: s3Client,
|
||||
queueSize: 20, // concurrency
|
||||
partSize: 5242880, // minimal 5MB by default
|
||||
partSize: bytesIn5MB, // minimal 5MB by default
|
||||
leavePartsOnError: false,
|
||||
params: {
|
||||
Bucket: s3Config.s3BucketName,
|
||||
@@ -190,7 +325,6 @@ export const listFromRemote = async (
|
||||
const contents = [] as _Object[];
|
||||
|
||||
let isTruncated = true;
|
||||
let continuationToken = "";
|
||||
do {
|
||||
const rsp = await s3Client.send(new ListObjectsV2Command(confCmd));
|
||||
|
||||
@@ -206,7 +340,8 @@ export const listFromRemote = async (
|
||||
confCmd.ContinuationToken = rsp.NextContinuationToken;
|
||||
if (
|
||||
isTruncated &&
|
||||
(continuationToken === undefined || continuationToken === "")
|
||||
(confCmd.ContinuationToken === undefined ||
|
||||
confCmd.ContinuationToken === "")
|
||||
) {
|
||||
throw Error("isTruncated is true but no continuationToken provided");
|
||||
}
|
||||
|
||||
+107
-8
@@ -1,18 +1,117 @@
|
||||
import { Buffer } from "buffer";
|
||||
import { Vault } from "obsidian";
|
||||
import type { FileStat, WebDAVClient } from "webdav/web";
|
||||
import { AuthType, BufferLike, createClient } from "webdav/web";
|
||||
import { Vault, request, requestUrl, requireApiVersion } from "obsidian";
|
||||
|
||||
import { Queue } from "@fyears/tsqueue";
|
||||
import chunk from "lodash/chunk";
|
||||
import flatten from "lodash/flatten";
|
||||
import type { RemoteItem, WebdavConfig } from "./baseTypes";
|
||||
import { getReasonPhrase } from "http-status-codes";
|
||||
import { API_VER_REQURL, RemoteItem, WebdavConfig } from "./baseTypes";
|
||||
import { decryptArrayBuffer, encryptArrayBuffer } from "./encrypt";
|
||||
import { bufferToArrayBuffer, getPathFolder, mkdirpInVault } from "./misc";
|
||||
export type { WebDAVClient } from "webdav/web";
|
||||
|
||||
import * as origLog from "loglevel";
|
||||
const log = origLog.getLogger("rs-default");
|
||||
|
||||
import type {
|
||||
FileStat,
|
||||
WebDAVClient,
|
||||
RequestOptionsWithState,
|
||||
Response,
|
||||
ResponseDataDetailed,
|
||||
} from "webdav/web";
|
||||
import { getPatcher } from "webdav/web";
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
getPatcher().patch(
|
||||
"request",
|
||||
async (
|
||||
options: RequestOptionsWithState
|
||||
): Promise<Response | ResponseDataDetailed<any>> => {
|
||||
const transformedHeaders = { ...options.headers };
|
||||
delete transformedHeaders["host"];
|
||||
delete transformedHeaders["Host"];
|
||||
delete transformedHeaders["content-length"];
|
||||
delete transformedHeaders["Content-Length"];
|
||||
const r = await requestUrl({
|
||||
url: options.url,
|
||||
method: options.method,
|
||||
body: options.data as string | ArrayBuffer,
|
||||
headers: transformedHeaders,
|
||||
});
|
||||
|
||||
let r2: Response | ResponseDataDetailed<any> = undefined;
|
||||
if (options.responseType === undefined) {
|
||||
r2 = {
|
||||
data: undefined,
|
||||
status: r.status,
|
||||
statusText: getReasonPhrase(r.status),
|
||||
headers: r.headers,
|
||||
};
|
||||
} else if (options.responseType === "json") {
|
||||
r2 = {
|
||||
data: r.json,
|
||||
status: r.status,
|
||||
statusText: getReasonPhrase(r.status),
|
||||
headers: r.headers,
|
||||
};
|
||||
} else if (options.responseType === "text") {
|
||||
r2 = {
|
||||
data: r.text,
|
||||
status: r.status,
|
||||
statusText: getReasonPhrase(r.status),
|
||||
headers: r.headers,
|
||||
};
|
||||
} else if (options.responseType === "arraybuffer") {
|
||||
r2 = {
|
||||
data: r.arrayBuffer,
|
||||
status: r.status,
|
||||
statusText: getReasonPhrase(r.status),
|
||||
headers: r.headers,
|
||||
};
|
||||
} else {
|
||||
throw Error(
|
||||
`do not know how to deal with responseType = ${options.responseType}`
|
||||
);
|
||||
}
|
||||
return r2;
|
||||
}
|
||||
);
|
||||
}
|
||||
// getPatcher().patch("request", (options: any) => {
|
||||
// // console.log("using fetch");
|
||||
// const r = fetch(options.url, {
|
||||
// method: options.method,
|
||||
// body: options.data as any,
|
||||
// headers: options.headers,
|
||||
// signal: options.signal,
|
||||
// })
|
||||
// .then((rsp) => {
|
||||
// if (options.responseType === undefined) {
|
||||
// return Promise.all([undefined, rsp]);
|
||||
// }
|
||||
// if (options.responseType === "json") {
|
||||
// return Promise.all([rsp.json(), rsp]);
|
||||
// }
|
||||
// if (options.responseType === "text") {
|
||||
// return Promise.all([rsp.text(), rsp]);
|
||||
// }
|
||||
// if (options.responseType === "arraybuffer") {
|
||||
// return Promise.all([rsp.arrayBuffer(), rsp]);
|
||||
// }
|
||||
// })
|
||||
// .then(([d, r]) => {
|
||||
// return {
|
||||
// data: d,
|
||||
// status: r.status,
|
||||
// statusText: r.statusText,
|
||||
// headers: r.headers,
|
||||
// };
|
||||
// });
|
||||
// // console.log("using fetch");
|
||||
// return r;
|
||||
// });
|
||||
import { AuthType, BufferLike, createClient } from "webdav/web";
|
||||
export type { WebDAVClient } from "webdav/web";
|
||||
|
||||
export const DEFAULT_WEBDAV_CONFIG = {
|
||||
address: "",
|
||||
username: "",
|
||||
@@ -169,7 +268,7 @@ export const uploadToRemote = async (
|
||||
// if encrypted, upload a fake file with the encrypted file name
|
||||
await client.client.putFileContents(uploadFile, "", {
|
||||
overwrite: true,
|
||||
onUploadProgress: (progress) => {
|
||||
onUploadProgress: (progress: any) => {
|
||||
// log.info(`Uploaded ${progress.loaded} bytes of ${progress.total}`);
|
||||
},
|
||||
});
|
||||
@@ -182,7 +281,7 @@ export const uploadToRemote = async (
|
||||
let localContent = undefined;
|
||||
if (uploadRaw) {
|
||||
if (typeof rawContent === "string") {
|
||||
localContent = new TextEncoder().encode(rawContent);
|
||||
localContent = new TextEncoder().encode(rawContent).buffer;
|
||||
} else {
|
||||
localContent = rawContent;
|
||||
}
|
||||
@@ -200,7 +299,7 @@ export const uploadToRemote = async (
|
||||
}
|
||||
await client.client.putFileContents(uploadFile, remoteContent, {
|
||||
overwrite: true,
|
||||
onUploadProgress: (progress) => {
|
||||
onUploadProgress: (progress: any) => {
|
||||
log.info(`Uploaded ${progress.loaded} bytes of ${progress.total}`);
|
||||
},
|
||||
});
|
||||
|
||||
+228
-25
@@ -1,5 +1,17 @@
|
||||
import { App, Modal, Notice, PluginSettingTab, Setting } from "obsidian";
|
||||
import type { SUPPORTED_SERVICES_TYPE, WebdavAuthType } from "./baseTypes";
|
||||
import {
|
||||
App,
|
||||
Modal,
|
||||
Notice,
|
||||
PluginSettingTab,
|
||||
Setting,
|
||||
Platform,
|
||||
requireApiVersion,
|
||||
} from "obsidian";
|
||||
import {
|
||||
API_VER_REQURL,
|
||||
SUPPORTED_SERVICES_TYPE,
|
||||
WebdavAuthType,
|
||||
} from "./baseTypes";
|
||||
import { exportVaultSyncPlansToFiles } from "./debugMode";
|
||||
import { exportQrCodeUri } from "./importExport";
|
||||
import {
|
||||
@@ -110,17 +122,45 @@ class DropboxAuthModal extends Modal {
|
||||
async onOpen() {
|
||||
let { contentEl } = this;
|
||||
|
||||
const { authUrl, verifier } = await getAuthUrlAndVerifierDropbox(
|
||||
this.plugin.settings.dropbox.clientID
|
||||
);
|
||||
this.plugin.oauth2Info.verifier = verifier;
|
||||
let needManualPatse = false;
|
||||
const userAgent = window.navigator.userAgent.toLocaleLowerCase() || "";
|
||||
// some users report that,
|
||||
// the Linux would open another instance Obsidian if jumping back,
|
||||
// so fallback to manual paste on Linux
|
||||
if (
|
||||
Platform.isDesktopApp &&
|
||||
!Platform.isMacOS &&
|
||||
(/linux/.test(userAgent) ||
|
||||
/ubuntu/.test(userAgent) ||
|
||||
/debian/.test(userAgent) ||
|
||||
/fedora/.test(userAgent) ||
|
||||
/centos/.test(userAgent))
|
||||
) {
|
||||
needManualPatse = true;
|
||||
}
|
||||
|
||||
contentEl.createEl("p", {
|
||||
text: "Visit the address in a browser, and follow the steps.",
|
||||
});
|
||||
contentEl.createEl("p", {
|
||||
text: "Finally you should be redirected to Obsidian.",
|
||||
});
|
||||
const { authUrl, verifier } = await getAuthUrlAndVerifierDropbox(
|
||||
this.plugin.settings.dropbox.clientID,
|
||||
needManualPatse
|
||||
);
|
||||
|
||||
if (needManualPatse) {
|
||||
contentEl.createEl("p", {
|
||||
text: "Step 1: Visit the address in a browser, and follow the steps.",
|
||||
});
|
||||
contentEl.createEl("p", {
|
||||
text: 'Step 2: In the end of the web flow, you obtain a long code. Paste it here then click "Submit".',
|
||||
});
|
||||
} else {
|
||||
this.plugin.oauth2Info.verifier = verifier;
|
||||
|
||||
contentEl.createEl("p", {
|
||||
text: "Visit the address in a browser, and follow the steps.",
|
||||
});
|
||||
contentEl.createEl("p", {
|
||||
text: "Finally you should be redirected to Obsidian.",
|
||||
});
|
||||
}
|
||||
|
||||
const div2 = contentEl.createDiv();
|
||||
div2.createEl(
|
||||
@@ -140,6 +180,70 @@ class DropboxAuthModal extends Modal {
|
||||
href: authUrl,
|
||||
text: authUrl,
|
||||
});
|
||||
|
||||
if (needManualPatse) {
|
||||
let authCode = "";
|
||||
new Setting(contentEl)
|
||||
.setName("Auth Code from web page")
|
||||
.setDesc('You need to click "Confirm".')
|
||||
.addText((text) =>
|
||||
text
|
||||
.setPlaceholder("")
|
||||
.setValue("")
|
||||
.onChange((val) => {
|
||||
authCode = val.trim();
|
||||
})
|
||||
)
|
||||
.addButton(async (button) => {
|
||||
button.setButtonText("Confirm");
|
||||
button.onClick(async () => {
|
||||
new Notice("Trying to connect to Dropbox");
|
||||
try {
|
||||
const authRes = await sendAuthReqDropbox(
|
||||
this.plugin.settings.dropbox.clientID,
|
||||
verifier,
|
||||
authCode
|
||||
);
|
||||
const self = this;
|
||||
setConfigBySuccessfullAuthInplace(
|
||||
this.plugin.settings.dropbox,
|
||||
authRes,
|
||||
() => self.plugin.saveSettings()
|
||||
);
|
||||
const client = new RemoteClient(
|
||||
"dropbox",
|
||||
undefined,
|
||||
undefined,
|
||||
this.plugin.settings.dropbox,
|
||||
undefined,
|
||||
this.app.vault.getName(),
|
||||
() => self.plugin.saveSettings()
|
||||
);
|
||||
const username = await client.getUser();
|
||||
this.plugin.settings.dropbox.username = username;
|
||||
await this.plugin.saveSettings();
|
||||
new Notice(
|
||||
`Good! We've connected to Dropbox as user ${username}!`
|
||||
);
|
||||
this.authDiv.toggleClass(
|
||||
"dropbox-auth-button-hide",
|
||||
this.plugin.settings.dropbox.username !== ""
|
||||
);
|
||||
this.revokeAuthDiv.toggleClass(
|
||||
"dropbox-revoke-auth-button-hide",
|
||||
this.plugin.settings.dropbox.username === ""
|
||||
);
|
||||
this.revokeAuthSetting.setDesc(
|
||||
`You've connected as user ${this.plugin.settings.dropbox.username}. If you want to disconnect, click this button.`
|
||||
);
|
||||
this.close();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
new Notice("Something goes wrong while connecting to Dropbox.");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onClose() {
|
||||
@@ -422,6 +526,55 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
});
|
||||
});
|
||||
|
||||
const runOnceStartUpDiv = generalDiv.createEl("div");
|
||||
new Setting(runOnceStartUpDiv)
|
||||
.setName("run once on start up automatically")
|
||||
.setDesc(
|
||||
`This settings allows setting running ONCE on start up automatically. This will take effect on NEXT start up after changing. This setting, is different from "schedule for auto run" which starts syncing after EVERY interval.`
|
||||
)
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown.addOption("-1", "(not set)");
|
||||
dropdown.addOption(
|
||||
`${1000 * 10 * 1}`,
|
||||
"sync once after 10 seconds of start up"
|
||||
);
|
||||
dropdown.addOption(
|
||||
`${1000 * 30 * 1}`,
|
||||
"sync once after 30 seconds of start up"
|
||||
);
|
||||
dropdown
|
||||
.setValue(`${this.plugin.settings.initRunAfterMilliseconds}`)
|
||||
.onChange(async (val: string) => {
|
||||
const realVal = parseInt(val);
|
||||
this.plugin.settings.initRunAfterMilliseconds = realVal;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
const concurrencyDiv = generalDiv.createEl("div");
|
||||
new Setting(concurrencyDiv)
|
||||
.setName("Concurrency")
|
||||
.setDesc(
|
||||
"How many files do you want to download or upload in parallel at most? By default it's set to 5. If you meet any problems such as rate limit, you can reduce the concurrency to a lower value."
|
||||
)
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown.addOption("1", "1");
|
||||
dropdown.addOption("2", "2");
|
||||
dropdown.addOption("3", "3");
|
||||
dropdown.addOption("5", "5 (default)");
|
||||
dropdown.addOption("10", "10");
|
||||
dropdown.addOption("15", "15");
|
||||
dropdown.addOption("20", "20");
|
||||
|
||||
dropdown
|
||||
.setValue(`${this.plugin.settings.concurrency}`)
|
||||
.onChange(async (val) => {
|
||||
const realVal = parseInt(val);
|
||||
this.plugin.settings.concurrency = realVal;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// below for general chooser (part 1/2)
|
||||
//////////////////////////////////////////////////
|
||||
@@ -447,9 +600,11 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
cls: "s3-disclaimer",
|
||||
});
|
||||
|
||||
s3Div.createEl("p", {
|
||||
text: "You need to configure CORS to allow requests from origin app://obsidian.md and capacitor://localhost and http://localhost",
|
||||
});
|
||||
if (!requireApiVersion(API_VER_REQURL)) {
|
||||
s3Div.createEl("p", {
|
||||
text: "You need to configure CORS to allow requests from origin app://obsidian.md and capacitor://localhost and http://localhost",
|
||||
});
|
||||
}
|
||||
|
||||
s3Div.createEl("p", {
|
||||
text: "Some Amazon S3 official docs for references:",
|
||||
@@ -467,10 +622,12 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
text: "Access key ID and Secret access key info",
|
||||
});
|
||||
|
||||
s3LinksUl.createEl("li").createEl("a", {
|
||||
href: "https://docs.aws.amazon.com/AmazonS3/latest/userguide/enabling-cors-examples.html",
|
||||
text: "Configuring CORS",
|
||||
});
|
||||
if (!requireApiVersion(API_VER_REQURL)) {
|
||||
s3LinksUl.createEl("li").createEl("a", {
|
||||
href: "https://docs.aws.amazon.com/AmazonS3/latest/userguide/enabling-cors-examples.html",
|
||||
text: "Configuring CORS",
|
||||
});
|
||||
}
|
||||
|
||||
new Setting(s3Div)
|
||||
.setName("s3Endpoint")
|
||||
@@ -539,6 +696,34 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
})
|
||||
);
|
||||
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
new Setting(s3Div)
|
||||
.setName("bypass CORS issue locally")
|
||||
.setDesc(
|
||||
`The plugin allows skipping server CORS config in new version (Obsidian>=${API_VER_REQURL}). If you encounter any issues, please disable this setting and config CORS (app://obsidian.md and capacitor://localhost and http://localhost) on server.`
|
||||
)
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown
|
||||
.addOption("disable", "disable")
|
||||
.addOption("enable", "enable");
|
||||
|
||||
dropdown
|
||||
.setValue(
|
||||
`${
|
||||
this.plugin.settings.s3.bypassCorsLocally ? "enable" : "disable"
|
||||
}`
|
||||
)
|
||||
.onChange(async (value) => {
|
||||
if (value === "enable") {
|
||||
this.plugin.settings.s3.bypassCorsLocally = true;
|
||||
} else {
|
||||
this.plugin.settings.s3.bypassCorsLocally = false;
|
||||
}
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
new Setting(s3Div)
|
||||
.setName("check connectivity")
|
||||
.setDesc("check connectivity")
|
||||
@@ -812,9 +997,11 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
cls: "webdav-disclaimer",
|
||||
});
|
||||
|
||||
webdavDiv.createEl("p", {
|
||||
text: "You need to configure CORS to allow requests from origin app://obsidian.md and capacitor://localhost and http://localhost",
|
||||
});
|
||||
if (!requireApiVersion(API_VER_REQURL)) {
|
||||
webdavDiv.createEl("p", {
|
||||
text: "You need to configure CORS to allow requests from origin app://obsidian.md and capacitor://localhost and http://localhost",
|
||||
});
|
||||
}
|
||||
|
||||
webdavDiv.createEl("p", {
|
||||
text: `We will create and sync inside the folder /${this.app.vault.getName()} on your server.`,
|
||||
@@ -862,9 +1049,20 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
new Setting(webdavDiv)
|
||||
.setName("server auth type")
|
||||
.setDesc("If no password, this option would be ignored.")
|
||||
.addDropdown((dropdown) => {
|
||||
.addDropdown(async (dropdown) => {
|
||||
dropdown.addOption("basic", "basic");
|
||||
// dropdown.addOption("digest", "digest");
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
dropdown.addOption("digest", "digest");
|
||||
}
|
||||
|
||||
// new version config, copied to old version, we need to reset it
|
||||
if (
|
||||
!requireApiVersion(API_VER_REQURL) &&
|
||||
this.plugin.settings.webdav.authType !== "basic"
|
||||
) {
|
||||
this.plugin.settings.webdav.authType = "basic";
|
||||
await this.plugin.saveSettings();
|
||||
}
|
||||
|
||||
dropdown
|
||||
.setValue(this.plugin.settings.webdav.authType)
|
||||
@@ -919,8 +1117,13 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
if (res) {
|
||||
new Notice("Great! The webdav server can be accessed.");
|
||||
} else {
|
||||
let corsErrMsg = "/CORS";
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
corsErrMsg = "";
|
||||
}
|
||||
|
||||
new Notice(
|
||||
"The webdav server cannot be reached (possible to be any of address/username/password/authtype/CORS errors)."
|
||||
`The webdav server cannot be reached (possible to be any of address/username/password/authtype${corsErrMsg} errors).`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
+187
-41
@@ -1,9 +1,17 @@
|
||||
import { TAbstractFile, TFile, TFolder, Vault } from "obsidian";
|
||||
import type {
|
||||
import {
|
||||
TAbstractFile,
|
||||
TFile,
|
||||
TFolder,
|
||||
Vault,
|
||||
requireApiVersion,
|
||||
} from "obsidian";
|
||||
import PQueue from "p-queue";
|
||||
import {
|
||||
RemoteItem,
|
||||
SUPPORTED_SERVICES_TYPE,
|
||||
DecisionType,
|
||||
FileOrFolderMixedState,
|
||||
API_VER_STAT_FOLDER,
|
||||
} from "./baseTypes";
|
||||
import {
|
||||
decryptBase32ToString,
|
||||
@@ -293,7 +301,7 @@ const ensembleMixedStates = async (
|
||||
r = {
|
||||
key: entry.path,
|
||||
existLocal: true,
|
||||
mtimeLocal: entry.stat.mtime,
|
||||
mtimeLocal: Math.max(entry.stat.mtime, entry.stat.ctime),
|
||||
sizeLocal: entry.stat.size,
|
||||
};
|
||||
} else if (entry instanceof TFolder) {
|
||||
@@ -505,9 +513,10 @@ const assignOperationToFileInplace = (
|
||||
throw Error(`no decision for ${JSON.stringify(r)}`);
|
||||
};
|
||||
|
||||
const assignOperationToFolderInplace = (
|
||||
const assignOperationToFolderInplace = async (
|
||||
origRecord: FileOrFolderMixedState,
|
||||
keptFolder: Set<string>,
|
||||
vault: Vault,
|
||||
password: string = ""
|
||||
) => {
|
||||
let r = origRecord;
|
||||
@@ -523,10 +532,42 @@ const assignOperationToFolderInplace = (
|
||||
|
||||
if (r.deltimeLocal !== undefined || r.deltimeRemote !== undefined) {
|
||||
// it has some deletion "commands"
|
||||
if (
|
||||
r.deltimeLocal !== undefined &&
|
||||
r.deltimeLocal >= (r.deltimeRemote !== undefined ? r.deltimeRemote : -1)
|
||||
) {
|
||||
|
||||
const deltimeLocal = r.deltimeLocal !== undefined ? r.deltimeLocal : -1;
|
||||
const deltimeRemote =
|
||||
r.deltimeRemote !== undefined ? r.deltimeRemote : -1;
|
||||
|
||||
// if it was created after deletion, we should keep it as is
|
||||
if (requireApiVersion(API_VER_STAT_FOLDER)) {
|
||||
if (r.existLocal) {
|
||||
try {
|
||||
const { ctime, mtime } = await vault.adapter.stat(r.key);
|
||||
const cmtime = Math.max(ctime, mtime);
|
||||
if (
|
||||
cmtime > 0 &&
|
||||
cmtime >= deltimeLocal &&
|
||||
cmtime >= deltimeRemote
|
||||
) {
|
||||
keptFolder.add(getParentFolder(r.key));
|
||||
if (r.existLocal && r.existRemote) {
|
||||
r.decision = "skipFolder";
|
||||
r.decisionBranch = 14;
|
||||
} else if (r.existLocal || r.existRemote) {
|
||||
r.decision = "createFolder";
|
||||
r.decisionBranch = 15;
|
||||
} else {
|
||||
throw Error(
|
||||
`Error: Folder ${r.key} doesn't exist locally and remotely but is marked must be kept. Abort.`
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (deltimeLocal > 0 && deltimeLocal > deltimeRemote) {
|
||||
r.decision = "uploadLocalDelHistToRemoteFolder";
|
||||
r.decisionBranch = 8;
|
||||
} else {
|
||||
@@ -585,6 +626,7 @@ export const getSyncPlan = async (
|
||||
remoteDeleteHistory: DeletionOnRemote[],
|
||||
localDeleteHistory: FileFolderHistoryRecord[],
|
||||
remoteType: SUPPORTED_SERVICES_TYPE,
|
||||
vault: Vault,
|
||||
password: string = ""
|
||||
) => {
|
||||
const mixedStates = await ensembleMixedStates(
|
||||
@@ -609,7 +651,7 @@ export const getSyncPlan = async (
|
||||
// decide some folders
|
||||
// because the keys are sorted by length
|
||||
// so all the children must have been shown up before in the iteration
|
||||
assignOperationToFolderInplace(val, keptFolder, password);
|
||||
await assignOperationToFolderInplace(val, keptFolder, vault, password);
|
||||
} else {
|
||||
// get all operations of files
|
||||
// and at the same time get some helper info for folders
|
||||
@@ -850,10 +892,10 @@ export const doActualSync = async (
|
||||
deletions: DeletionOnRemote[],
|
||||
localDeleteFunc: any,
|
||||
password: string = "",
|
||||
concurrency: number = 1,
|
||||
callbackSyncProcess?: any
|
||||
) => {
|
||||
const mixedStates = syncPlan.mixedStates;
|
||||
let i = 0;
|
||||
const totalCount = sortedKeys.length || 0;
|
||||
|
||||
log.debug(`start syncing extra data firstly`);
|
||||
@@ -866,41 +908,145 @@ export const doActualSync = async (
|
||||
);
|
||||
log.debug(`finish syncing extra data firstly`);
|
||||
|
||||
for (let i = 0; i < sortedKeys.length; ++i) {
|
||||
const key = sortedKeys[i];
|
||||
const val = mixedStates[key];
|
||||
log.debug(`concurrency === ${concurrency}`);
|
||||
if (concurrency === 1) {
|
||||
// run everything in sequence
|
||||
// good old way
|
||||
for (let i = 0; i < sortedKeys.length; ++i) {
|
||||
const key = sortedKeys[i];
|
||||
const val = mixedStates[key];
|
||||
|
||||
log.debug(`start syncing "${key}" with plan ${JSON.stringify(val)}`);
|
||||
log.debug(`start syncing "${key}" with plan ${JSON.stringify(val)}`);
|
||||
|
||||
if (callbackSyncProcess !== undefined) {
|
||||
await callbackSyncProcess(i, totalCount, key, val.decision);
|
||||
if (callbackSyncProcess !== undefined) {
|
||||
await callbackSyncProcess(i, totalCount, key, val.decision);
|
||||
}
|
||||
|
||||
await dispatchOperationToActual(
|
||||
key,
|
||||
vaultRandomID,
|
||||
val,
|
||||
client,
|
||||
db,
|
||||
vault,
|
||||
localDeleteFunc,
|
||||
password
|
||||
);
|
||||
log.debug(`finished ${key}`);
|
||||
}
|
||||
} else {
|
||||
let realCounter = 0;
|
||||
|
||||
log.debug(
|
||||
`1. create all folders from shadowest to deepest, also check undefined decision`
|
||||
);
|
||||
for (let i = sortedKeys.length - 1; i >= 0; --i) {
|
||||
const key = sortedKeys[i];
|
||||
const val = mixedStates[key];
|
||||
|
||||
if (
|
||||
val.decision === undefined ||
|
||||
val.decision === "skipFolder" ||
|
||||
val.decision === "createFolder"
|
||||
) {
|
||||
log.debug(`start syncing "${key}" with plan ${JSON.stringify(val)}`);
|
||||
|
||||
if (callbackSyncProcess !== undefined) {
|
||||
await callbackSyncProcess(realCounter, totalCount, key, val.decision);
|
||||
}
|
||||
realCounter += 1;
|
||||
|
||||
await dispatchOperationToActual(
|
||||
key,
|
||||
vaultRandomID,
|
||||
val,
|
||||
client,
|
||||
db,
|
||||
vault,
|
||||
localDeleteFunc,
|
||||
password
|
||||
);
|
||||
log.debug(`finished ${key}`);
|
||||
}
|
||||
}
|
||||
|
||||
await dispatchOperationToActual(
|
||||
key,
|
||||
vaultRandomID,
|
||||
val,
|
||||
client,
|
||||
db,
|
||||
vault,
|
||||
localDeleteFunc,
|
||||
password
|
||||
);
|
||||
log.debug(`finished ${key}`);
|
||||
log.debug(`2. delete files and folders from deepest to shadowest`);
|
||||
for (let i = 0; i < sortedKeys.length; ++i) {
|
||||
const key = sortedKeys[i];
|
||||
const val = mixedStates[key];
|
||||
if (
|
||||
val.decision === "uploadLocalDelHistToRemoteFolder" ||
|
||||
val.decision === "keepRemoteDelHistFolder" ||
|
||||
val.decision === "uploadLocalDelHistToRemote" ||
|
||||
val.decision === "keepRemoteDelHist"
|
||||
) {
|
||||
log.debug(`start syncing "${key}" with plan ${JSON.stringify(val)}`);
|
||||
|
||||
// await Promise.all(
|
||||
// Object.entries(mixedStates).map(async ([k, v]) =>
|
||||
// dispatchOperationToActual(
|
||||
// k as string,
|
||||
// vaultRandomID,
|
||||
// v as FileOrFolderMixedState,
|
||||
// client,
|
||||
// db,
|
||||
// vault,
|
||||
// localDeleteFunc,
|
||||
// password
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
if (callbackSyncProcess !== undefined) {
|
||||
await callbackSyncProcess(realCounter, totalCount, key, val.decision);
|
||||
}
|
||||
realCounter += 1;
|
||||
|
||||
await dispatchOperationToActual(
|
||||
key,
|
||||
vaultRandomID,
|
||||
val,
|
||||
client,
|
||||
db,
|
||||
vault,
|
||||
localDeleteFunc,
|
||||
password
|
||||
);
|
||||
log.debug(`finished ${key}`);
|
||||
}
|
||||
}
|
||||
|
||||
log.debug(
|
||||
`3. upload or download files in parallel, with the desired concurrency=${concurrency}`
|
||||
);
|
||||
const queue = new PQueue({ concurrency: concurrency, autoStart: true });
|
||||
|
||||
// const commands: any[] = [];
|
||||
|
||||
for (let i = 0; i < sortedKeys.length; ++i) {
|
||||
const key = sortedKeys[i];
|
||||
const val = mixedStates[key];
|
||||
if (
|
||||
val.decision === "skipUploading" ||
|
||||
val.decision === "uploadLocalToRemote" ||
|
||||
val.decision === "downloadRemoteToLocal"
|
||||
) {
|
||||
const fn = async () => {
|
||||
log.debug(`start syncing "${key}" with plan ${JSON.stringify(val)}`);
|
||||
|
||||
if (callbackSyncProcess !== undefined) {
|
||||
await callbackSyncProcess(
|
||||
realCounter,
|
||||
totalCount,
|
||||
key,
|
||||
val.decision
|
||||
);
|
||||
|
||||
realCounter += 1;
|
||||
}
|
||||
|
||||
await dispatchOperationToActual(
|
||||
key,
|
||||
vaultRandomID,
|
||||
val,
|
||||
client,
|
||||
db,
|
||||
vault,
|
||||
localDeleteFunc,
|
||||
password
|
||||
);
|
||||
|
||||
log.debug(`finished ${key}`);
|
||||
};
|
||||
queue.add(fn);
|
||||
}
|
||||
}
|
||||
|
||||
await queue.onIdle();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ export class SyncAlgoV2Modal extends Modal {
|
||||
const texts = [
|
||||
"Welcome to use Remotely Save!",
|
||||
|
||||
"From this version 0.3.0, a new algorithm has been developed, but it needs uploading extra meta data files _remotely-save-metadata-on-remote.{json,bin} to YOUR configured cloud destinations, besides your notes.",
|
||||
"From version 0.3.0, a new algorithm has been developed, but it needs uploading extra meta data files _remotely-save-metadata-on-remote.{json,bin} to YOUR configured cloud destinations, besides your notes.",
|
||||
|
||||
"So that, for example, the second device can know that what files/folders have been deleted on the first device by reading those files.",
|
||||
|
||||
@@ -60,6 +60,7 @@ export class SyncAlgoV2Modal extends Modal {
|
||||
log.info("agree to use the new algorithm");
|
||||
this.plugin.saveAgreeToUseNewSyncAlgorithm();
|
||||
this.plugin.enableAutoSyncIfSet();
|
||||
this.plugin.enableInitSyncIfSet();
|
||||
} else {
|
||||
log.info("do not agree to use the new algorithm");
|
||||
this.plugin.unload();
|
||||
|
||||
@@ -180,3 +180,56 @@ describe("Misc: extract svg", () => {
|
||||
expect(y).to.equal("<rect/><g/>");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Misc: get split ranges", () => {
|
||||
it("should deal with big parts", () => {
|
||||
const k = misc.getSplitRanges(10, 20);
|
||||
const k2: misc.SplitRange[] = [
|
||||
{
|
||||
partNum: 1,
|
||||
start: 0,
|
||||
end: 10,
|
||||
},
|
||||
];
|
||||
expect(k).to.deep.equal(k2);
|
||||
});
|
||||
|
||||
it("should deal with 0 remainder", () => {
|
||||
const k = misc.getSplitRanges(20, 10);
|
||||
const k2: misc.SplitRange[] = [
|
||||
{
|
||||
partNum: 1,
|
||||
start: 0,
|
||||
end: 10,
|
||||
},
|
||||
{
|
||||
partNum: 2,
|
||||
start: 10,
|
||||
end: 20,
|
||||
},
|
||||
];
|
||||
expect(k).to.deep.equal(k2);
|
||||
});
|
||||
|
||||
it("should deal with not-0 remainder", () => {
|
||||
const k = misc.getSplitRanges(25, 10);
|
||||
const k2: misc.SplitRange[] = [
|
||||
{
|
||||
partNum: 1,
|
||||
start: 0,
|
||||
end: 10,
|
||||
},
|
||||
{
|
||||
partNum: 2,
|
||||
start: 10,
|
||||
end: 20,
|
||||
},
|
||||
{
|
||||
partNum: 3,
|
||||
start: 20,
|
||||
end: 25,
|
||||
},
|
||||
];
|
||||
expect(k).to.deep.equal(k2);
|
||||
});
|
||||
});
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"0.3.0": "0.12.15"
|
||||
"0.3.2": "0.12.15",
|
||||
"0.3.5": "0.13.21"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user