Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b13bd8708b | ||
|
|
83c3aac317 | ||
|
|
712979fb0d | ||
|
|
e460c563af | ||
|
|
580397fbf9 | ||
|
|
537fae1a2b | ||
|
|
dbc9e02ff3 | ||
|
|
6474faad51 | ||
|
|
a5e415aeaf | ||
|
|
3e75e31696 | ||
|
|
9c8cc1c8b8 | ||
|
|
cccc4969cd | ||
|
|
1ba1591c75 | ||
|
|
1581cb3822 | ||
|
|
99926adbbd | ||
|
|
4edd8caaea | ||
|
|
005b698862 | ||
|
|
e76a5e4c12 |
@@ -1,5 +1,5 @@
|
||||
name: Bug Report
|
||||
description: File a bug report
|
||||
description: Fire a bug report
|
||||
title: "[Bug]: "
|
||||
labels: ["bug"]
|
||||
body:
|
||||
@@ -55,6 +55,14 @@ body:
|
||||
description: What version of Obsidian are you running?
|
||||
validations:
|
||||
required: false
|
||||
- type: checkboxes
|
||||
id: using-password
|
||||
attributes:
|
||||
label: Using password or not
|
||||
description: Are you using password (end-to-end encryption) or not?
|
||||
options:
|
||||
- label: Yes.
|
||||
required: false
|
||||
- type: checkboxes
|
||||
id: ensure-no-sensitive-information
|
||||
attributes:
|
||||
|
||||
@@ -61,8 +61,8 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a
|
||||
|
||||
- Prepare your S3 (-compatible) service information: [endpoint, region](https://docs.aws.amazon.com/general/latest/gr/s3.html), [access key id, secret access key](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-your-credentials.html), bucket name. The bucket should be empty and solely for syncing a vault.
|
||||
- About CORS:
|
||||
- If you are using Obsidian >= 0.13.25, you can skip this CORS part.
|
||||
- If you are using Obsidian < 0.13.25, you need to configure (enable) [CORS](https://docs.aws.amazon.com/AmazonS3/latest/userguide/enabling-cors-examples.html) for requests from `app://obsidian.md` and `capacitor://localhost` and `http://localhost`, and add at least `ETag` into exposed headers. Full example is [here](./docs/s3_cors_configure.md). It's unfortunately required, because the plugin sends requests from a browser-like envirement. And those addresses are tested and found on desktop and ios and android.
|
||||
- If you are using Obsidian desktop >= 0.13.25 or mobile >= 1.1.1, you can skip this CORS part.
|
||||
- If you are using Obsidian desktop < 0.13.25 or mobile < 1.1.1, you need to configure (enable) [CORS](https://docs.aws.amazon.com/AmazonS3/latest/userguide/enabling-cors-examples.html) for requests from `app://obsidian.md` and `capacitor://localhost` and `http://localhost`, and add at least `ETag` into exposed headers. Full example is [here](./docs/s3_cors_configure.md). It's unfortunately required, because the plugin sends requests from a browser-like envirement. And those addresses are tested and found on desktop and ios and android.
|
||||
- Download and enable this plugin.
|
||||
- Enter your information to the settings of this plugin.
|
||||
- If you want to enable end-to-end encryption, also set a password in settings. If you do not specify a password, the files and folders are synced in plain, original content to the cloud.
|
||||
@@ -87,8 +87,8 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a
|
||||
### webdav
|
||||
|
||||
- About CORS:
|
||||
- If you are using Obsidian >= 0.13.25, you can skip this CORS part.
|
||||
- If you are using Obsidian < 0.13.25:
|
||||
- If you are using Obsidian desktop >= 0.13.25 or iOS >= 1.1.1, you can skip this CORS part.
|
||||
- If you are using Obsidian desktop < 0.13.25 or iOS < 1.1.1 or any Android version:
|
||||
- The webdav server has to be enabled CORS for requests from `app://obsidian.md` and `capacitor://localhost` and `http://localhost`, **AND** all webdav HTTP methods, **AND** all webdav headers. These are required, because Obsidian mobile works like a browser and mobile plugins are limited by CORS policies unless under a upgraded Obsidian version.
|
||||
- Popular software NextCloud, OwnCloud, `rclone serve webdav` do **NOT** enable CORS by default. If you are using any of them, you should evaluate the risk, and find a way to enable CORS, before using this plugin, or use a upgraded Obsidian version.
|
||||
- The plugin is tested successfully under python package [`wsgidav` (version 4.0)](https://github.com/mar10/wsgidav). See [this issue](https://github.com/mar10/wsgidav/issues/239) for some details.
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ Technically, the plugin (or any plugin?) runs in the js environment provided by
|
||||
|
||||
Then some limitations are applied:
|
||||
|
||||
1. [The CORS issue (solved in the new Obsidian version).](./browser_env_cors.md)
|
||||
1. [The CORS issue (solved in the new Obsidian version on some platforms).](./browser_env_cors.md)
|
||||
2. [No Node.js environment.](./browser_env_no_nodejs.md)
|
||||
3. If the cloud service uses OAuth flow, it needs to support PKCE. More details are [here](./browser_env_oauth2_pkce.md).
|
||||
4. [No background running after Obsidian is closes.](./browser_env_no_background_after_closing.md)
|
||||
|
||||
@@ -4,6 +4,6 @@ The plugin is developed for the browser environment. The "fake" browser behind t
|
||||
|
||||
[MDN has a doc about CORS.](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
|
||||
|
||||
From Obsidian version >= insider 0.13.25, Obsidian [provides a new API `requiestUrl`](https://forum.obsidian.md/t/obsidian-release-v0-13-25-insider-build/32701), that allows the plugin to fully bypass the CORS issue. As of Mar 2022, the latest public-released Obsidian desktop has supported this API, but the Obsidian mobile still stays in insider.
|
||||
From Obsidian desktop >= 0.13.25 or mobile >= 1.1.1, Obsidian [provides a new API `requiestUrl`](https://forum.obsidian.md/t/obsidian-release-v0-13-25-insider-build/32701), that allows the plugin to fully bypass the CORS issue. As of Mar 2022, the latest public-released Obsidian desktop has supported this API, but the Obsidian mobile still stays in insider.
|
||||
|
||||
For using this plugin in Obsidian version < 0.13.25, we need to configure the server side to return the header `Access-Control-Allow-Origin` allowing the origins `app://obsidian.md` and `capacitor://localhost` and `http://localhost`. Here is an example [configuration for Amazon S3](./s3_cors_configure.md).
|
||||
For using this plugin in Obsidian desktop < 0.13.25 or mobile < 1.1.1, we need to configure the server side to return the header `Access-Control-Allow-Origin` allowing the origins `app://obsidian.md` and `capacitor://localhost` and `http://localhost`. Here is an example [configuration for Amazon S3](./s3_cors_configure.md).
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# How To Configure S3 CORS Rules
|
||||
|
||||
If you are using the latest version of this plugin AND Obsidian >= 0.13.25, you do not need to configure it any more. If you are using Obsidian < 0.13.25, you are required to configure the rules as following.
|
||||
If you are using the latest version of this plugin AND Obsidian desktop >= 0.13.25, mobile >= 1.1.1, you do not need to configure it any more. If you are using Obsidian desktop < 0.13.25, moble < 1.1.1, you are required to configure the rules as following.
|
||||
|
||||
Thanks to [@NAL100 in the Discussion](https://github.com/fyears/remotely-save/discussions/28).
|
||||
|
||||
|
||||
@@ -2,41 +2,41 @@
|
||||
|
||||
Here is an overview of the connectability ("connectable" or "not connectable" or "in the plan" or "never") to some services by this plugin.
|
||||
|
||||
The plugin works under the browser environment in Obsidian, so CORS is an issue. Obsidian starts to provide a rich API `requestUrl` for version >= 0.13.25 to bypass the CORS issue. But if the users are still using an older version of Obsidian, they need to configure CORS on server.
|
||||
The plugin works under the browser environment in Obsidian, so CORS is an issue. Obsidian starts to provide a rich API `requestUrl` for desktop version >= 0.13.25, mobile >= 1.1.1 to bypass the CORS issue. But if the users are still using an older version of Obsidian, they need to configure CORS on server.
|
||||
|
||||
The list is for information purposes only.
|
||||
|
||||
| Service | Connectable | by S3 | by WebDAV | by other protocol | can bypass CORS issue in Obsidian>=0.13.25 | need CORS config in Obsidian<0.13.25 |
|
||||
| ------------------------------------------------------------------------------------- | ----------- | ----- | --------- | ---------------------------------------------------------------- | ------------------------------------------ | ------------------------------------------------ |
|
||||
| Amazon S3 | Yes | Yes | | | Yes | [CORS config needed.](./s3_cors_configure.md) |
|
||||
| Tencent Cloud - Cloud Object Storage (COS) 腾讯云对象存储 | Yes | Yes | | | Yes | CORS config needed. |
|
||||
| Alibaba Cloud - Object Storage Service 阿里云对象存储 | Yes | Yes | | | Yes | CORS config needed. |
|
||||
| Backblaze B2 Cloud Storage | Yes | Yes | | | Yes | Its CORS rules doesn't allow no-http(s) origins. |
|
||||
| [Wasabi](https://wasabi.com) | ? | ? | | | | |
|
||||
| [filebase](https://filebase.com/) | Yes | Yes | | | Yes | CORS config needed. |
|
||||
| QingStor 青云 | ? | ? | | | | |
|
||||
| [MinIO](https://min.io/) | ? | ? | | | | |
|
||||
| [WsgiDAV](https://github.com/mar10/wsgidav) | Yes | | Yes | | Yes | CORS rules can be set. |
|
||||
| [Nginx `ngx_http_dav_module`](http://nginx.org/en/docs/http/ngx_http_dav_module.html) | Yes? | | Yes? | | Yes? | ? |
|
||||
| NextCloud | Yes? | | Yes? | | Yes? | No CORS config by default. |
|
||||
| OwnCloud | Yes? | | Yes? | | Yes? | No CORS config by default. |
|
||||
| Seafile | Yes? | | Yes? | | Yes? | |
|
||||
| `rclone serve webdav` | Yes | | Yes | | Yes | No CORS support. |
|
||||
| [Nutstore 坚果云](https://www.jianguoyun.com/) | Yes | | Yes | | Yes | No CORS support. |
|
||||
| [TeraCLOUD](https://teracloud.jp/en/) | Yes | | Yes | | Yes | No CORS support. |
|
||||
| Dropbox | Yes | | | Yes | | |
|
||||
| OneDrive for personal | Yes | | | Yes | | |
|
||||
| OneDrive for Business | In the plan | | | ? | | |
|
||||
| Google Drive | In the plan | | | ? | | |
|
||||
| [Box](https://www.box.com/) | ? | | | May be possible but needs further development. | | |
|
||||
| Google Cloud Storage | ? | | | May be possible but needs further development. | | |
|
||||
| Microsoft Azure Blob Storage | ? | | | May be possible but needs further development. | | |
|
||||
| [OpenStack Storage (Swift)](https://github.com/openstack/swift) | ? | | | May be possible but needs further development. | | |
|
||||
| https://put.io/ | ? | | | ? | | |
|
||||
| Yandex Disk | ? | | | ? | | |
|
||||
| FTP / FTPS | Never | | | Technically never possible to be implemented. | | |
|
||||
| SFTP | Never | | | Technically never possible to be implemented. | | |
|
||||
| Jottacloud | No | | | No. It seems that no open api is available. | | |
|
||||
| Mega | Never | | | No. No js api is available. | | |
|
||||
| Git | Never | | | No. Technically very hard, if not impossible, to be implemented. | | |
|
||||
| | | | | | | |
|
||||
| Service | Connectable | by S3 | by WebDAV | by other protocol | can bypass CORS issue in latest Obsidian | need CORS config in old Obsidian |
|
||||
| ------------------------------------------------------------------------------------- | ----------- | ----- | --------- | ---------------------------------------------------------------- | ---------------------------------------- | ------------------------------------------------ |
|
||||
| Amazon S3 | Yes | Yes | | | Yes | [CORS config needed.](./s3_cors_configure.md) |
|
||||
| Tencent Cloud - Cloud Object Storage (COS) 腾讯云对象存储 | Yes | Yes | | | Yes | CORS config needed. |
|
||||
| Alibaba Cloud - Object Storage Service 阿里云对象存储 | Yes | Yes | | | Yes | CORS config needed. |
|
||||
| Backblaze B2 Cloud Storage | Yes | Yes | | | Yes | Its CORS rules doesn't allow no-http(s) origins. |
|
||||
| [Wasabi](https://wasabi.com) | ? | ? | | | | |
|
||||
| [filebase](https://filebase.com/) | Yes | Yes | | | Yes | CORS config needed. |
|
||||
| QingStor 青云 | ? | ? | | | | |
|
||||
| [MinIO](https://min.io/) | ? | ? | | | | |
|
||||
| [WsgiDAV](https://github.com/mar10/wsgidav) | Yes | | Yes | | Yes | CORS rules can be set. |
|
||||
| [Nginx `ngx_http_dav_module`](http://nginx.org/en/docs/http/ngx_http_dav_module.html) | Yes? | | Yes? | | Yes? | ? |
|
||||
| NextCloud | Yes? | | Yes? | | Yes? | No CORS config by default. |
|
||||
| OwnCloud | Yes? | | Yes? | | Yes? | No CORS config by default. |
|
||||
| Seafile | Yes? | | Yes? | | Yes? | |
|
||||
| `rclone serve webdav` | Yes | | Yes | | Yes | No CORS support. |
|
||||
| [Nutstore 坚果云](https://www.jianguoyun.com/) | Yes | | Yes | | Yes | No CORS support. |
|
||||
| [TeraCLOUD](https://teracloud.jp/en/) | Yes | | Yes | | Yes | No CORS support. |
|
||||
| Dropbox | Yes | | | Yes | | |
|
||||
| OneDrive for personal | Yes | | | Yes | | |
|
||||
| OneDrive for Business | In the plan | | | ? | | |
|
||||
| Google Drive | In the plan | | | ? | | |
|
||||
| [Box](https://www.box.com/) | ? | | | May be possible but needs further development. | | |
|
||||
| Google Cloud Storage | ? | | | May be possible but needs further development. | | |
|
||||
| Microsoft Azure Blob Storage | ? | | | May be possible but needs further development. | | |
|
||||
| [OpenStack Storage (Swift)](https://github.com/openstack/swift) | ? | | | May be possible but needs further development. | | |
|
||||
| https://put.io/ | ? | | | ? | | |
|
||||
| Yandex Disk | ? | | | ? | | |
|
||||
| FTP / FTPS | Never | | | Technically never possible to be implemented. | | |
|
||||
| SFTP | Never | | | Technically never possible to be implemented. | | |
|
||||
| Jottacloud | No | | | No. It seems that no open api is available. | | |
|
||||
| Mega | Never | | | No. No js api is available. | | |
|
||||
| Git | Never | | | No. Technically very hard, if not impossible, to be implemented. | | |
|
||||
| | | | | | | |
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "remotely-save",
|
||||
"name": "Remotely Save",
|
||||
"version": "0.3.11",
|
||||
"version": "0.3.14",
|
||||
"minAppVersion": "0.13.21",
|
||||
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
|
||||
"author": "fyears",
|
||||
|
||||
+2
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "remotely-save",
|
||||
"version": "0.3.11",
|
||||
"version": "0.3.14",
|
||||
"description": "This is yet another sync plugin for Obsidian app.",
|
||||
"scripts": {
|
||||
"dev2": "node esbuild.config.mjs",
|
||||
@@ -38,7 +38,7 @@
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"dotenv": "^10.0.0",
|
||||
"esbuild": "^0.14.3",
|
||||
"esbuild": "^0.14.27",
|
||||
"jsdom": "^19.0.0",
|
||||
"mocha": "^9.1.3",
|
||||
"prettier": "^2.4.1",
|
||||
@@ -65,7 +65,6 @@
|
||||
"assert": "^2.0.0",
|
||||
"aws-crt": "^1.10.1",
|
||||
"buffer": "^6.0.3",
|
||||
"codemirror": "^5.63.1",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"dropbox": "^10.22.0",
|
||||
"http-status-codes": "^2.2.0",
|
||||
|
||||
+7
-2
@@ -66,7 +66,6 @@ export interface RemotelySavePluginSettings {
|
||||
password: string;
|
||||
serviceType: SUPPORTED_SERVICES_TYPE;
|
||||
currLogLevel?: string;
|
||||
vaultRandomID?: string;
|
||||
autoRunEveryMilliseconds?: number;
|
||||
initRunAfterMilliseconds?: number;
|
||||
agreeToUploadExtraMetadata?: boolean;
|
||||
@@ -74,6 +73,11 @@ export interface RemotelySavePluginSettings {
|
||||
syncConfigDir?: boolean;
|
||||
syncUnderscoreItems?: boolean;
|
||||
lang?: LangTypeAndAuto;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
vaultRandomID?: string;
|
||||
}
|
||||
|
||||
export interface RemoteItem {
|
||||
@@ -124,7 +128,8 @@ export interface FileOrFolderMixedState {
|
||||
deltimeRemote?: number;
|
||||
sizeLocal?: number;
|
||||
sizeRemote?: number;
|
||||
changeMtimeUsingMapping?: boolean;
|
||||
changeRemoteMtimeUsingMapping?: boolean;
|
||||
changeLocalMtimeUsingMapping?: boolean;
|
||||
decision?: DecisionType;
|
||||
decisionBranch?: number;
|
||||
syncDone?: "done";
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as origLog from "loglevel";
|
||||
const log = origLog.getLogger("rs-default");
|
||||
|
||||
const DEFAULT_README: string =
|
||||
"Do NOT modify this manually. It's generated automatically.";
|
||||
"The file contains sensitive info, so DO NOT take screenshot of, copy, or share it to anyone! It's also generated automatically, so do not edit it manually.";
|
||||
|
||||
interface MessyConfigType {
|
||||
readme: string;
|
||||
|
||||
+1
-1
Submodule src/langs updated: 28730585f8...230fee440e
+163
-33
@@ -1,21 +1,23 @@
|
||||
import localforage from "localforage";
|
||||
import { TAbstractFile, TFile, TFolder } from "obsidian";
|
||||
import { requireApiVersion, TAbstractFile, TFile, TFolder } from "obsidian";
|
||||
|
||||
import type { SUPPORTED_SERVICES_TYPE } from "./baseTypes";
|
||||
import { API_VER_STAT_FOLDER, SUPPORTED_SERVICES_TYPE } from "./baseTypes";
|
||||
import type { SyncPlanType } from "./sync";
|
||||
|
||||
export type LocalForage = typeof localforage;
|
||||
|
||||
import * as origLog from "loglevel";
|
||||
import { nanoid } from "nanoid";
|
||||
const log = origLog.getLogger("rs-default");
|
||||
|
||||
const DB_VERSION_NUMBER_IN_HISTORY = [20211114, 20220108];
|
||||
export const DEFAULT_DB_VERSION_NUMBER: number = 20220108;
|
||||
const DB_VERSION_NUMBER_IN_HISTORY = [20211114, 20220108, 20220326];
|
||||
export const DEFAULT_DB_VERSION_NUMBER: number = 20220326;
|
||||
export const DEFAULT_DB_NAME = "remotelysavedb";
|
||||
export const DEFAULT_TBL_VERSION = "schemaversion";
|
||||
export const DEFAULT_TBL_DELETE_HISTORY = "filefolderoperationhistory";
|
||||
export const DEFAULT_TBL_FILE_HISTORY = "filefolderoperationhistory";
|
||||
export const DEFAULT_TBL_SYNC_MAPPING = "syncmetadatahistory";
|
||||
export const DEFAULT_SYNC_PLANS_HISTORY = "syncplanshistory";
|
||||
export const DEFAULT_TBL_VAULT_RANDOM_ID_MAPPING = "vaultrandomidmapping";
|
||||
|
||||
export interface FileFolderHistoryRecord {
|
||||
key: string;
|
||||
@@ -23,7 +25,7 @@ export interface FileFolderHistoryRecord {
|
||||
mtime: number;
|
||||
size: number;
|
||||
actionWhen: number;
|
||||
actionType: "delete" | "rename";
|
||||
actionType: "delete" | "rename" | "renameDestination";
|
||||
keyType: "folder" | "file";
|
||||
renameTo: string;
|
||||
vaultRandomID: string;
|
||||
@@ -51,9 +53,10 @@ interface SyncPlanRecord {
|
||||
|
||||
export interface InternalDBs {
|
||||
versionTbl: LocalForage;
|
||||
deleteHistoryTbl: LocalForage;
|
||||
fileHistoryTbl: LocalForage;
|
||||
syncMappingTbl: LocalForage;
|
||||
syncPlansTbl: LocalForage;
|
||||
vaultRandomIDMappingTbl: LocalForage;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,12 +75,12 @@ const migrateDBsFrom20211114To20220108 = async (
|
||||
const allPromisesToWait: Promise<any>[] = [];
|
||||
|
||||
log.debug("assign vault id to any delete history");
|
||||
const keysInDeleteHistoryTbl = await db.deleteHistoryTbl.keys();
|
||||
const keysInDeleteHistoryTbl = await db.fileHistoryTbl.keys();
|
||||
for (const key of keysInDeleteHistoryTbl) {
|
||||
if (key.startsWith(vaultRandomID)) {
|
||||
continue;
|
||||
}
|
||||
const value = (await db.deleteHistoryTbl.getItem(
|
||||
const value = (await db.fileHistoryTbl.getItem(
|
||||
key
|
||||
)) as FileFolderHistoryRecord;
|
||||
if (value === null || value === undefined) {
|
||||
@@ -87,8 +90,8 @@ const migrateDBsFrom20211114To20220108 = async (
|
||||
value.vaultRandomID = vaultRandomID;
|
||||
}
|
||||
const newKey = `${vaultRandomID}\t${key}`;
|
||||
allPromisesToWait.push(db.deleteHistoryTbl.setItem(newKey, value));
|
||||
allPromisesToWait.push(db.deleteHistoryTbl.removeItem(key));
|
||||
allPromisesToWait.push(db.fileHistoryTbl.setItem(newKey, value));
|
||||
allPromisesToWait.push(db.fileHistoryTbl.removeItem(key));
|
||||
}
|
||||
|
||||
log.debug("assign vault id to any sync mapping");
|
||||
@@ -136,6 +139,23 @@ const migrateDBsFrom20211114To20220108 = async (
|
||||
log.debug(`finish upgrading internal db from ${oldVer} to ${newVer}`);
|
||||
};
|
||||
|
||||
/**
|
||||
* no need to do anything except changing version
|
||||
* we just add more file operations in db, and no schema is changed.
|
||||
* @param db
|
||||
* @param vaultRandomID
|
||||
*/
|
||||
const migrateDBsFrom20220108To20220326 = async (
|
||||
db: InternalDBs,
|
||||
vaultRandomID: string
|
||||
) => {
|
||||
const oldVer = 20220108;
|
||||
const newVer = 20220326;
|
||||
log.debug(`start upgrading internal db from ${oldVer} to ${newVer}`);
|
||||
await db.versionTbl.setItem("version", newVer);
|
||||
log.debug(`finish upgrading internal db from ${oldVer} to ${newVer}`);
|
||||
};
|
||||
|
||||
const migrateDBs = async (
|
||||
db: InternalDBs,
|
||||
oldVer: number,
|
||||
@@ -148,19 +168,36 @@ const migrateDBs = async (
|
||||
if (oldVer === 20211114 && newVer === 20220108) {
|
||||
return await migrateDBsFrom20211114To20220108(db, vaultRandomID);
|
||||
}
|
||||
if (oldVer === 20220108 && newVer === 20220326) {
|
||||
return await migrateDBsFrom20220108To20220326(db, vaultRandomID);
|
||||
}
|
||||
if (oldVer === 20211114 && newVer === 20220326) {
|
||||
// TODO: more steps with more versions in the future
|
||||
await migrateDBsFrom20211114To20220108(db, vaultRandomID);
|
||||
await migrateDBsFrom20220108To20220326(db, vaultRandomID);
|
||||
return;
|
||||
}
|
||||
if (newVer < oldVer) {
|
||||
throw Error(
|
||||
"You've installed a new version, but then downgrade to an old version. Stop working!"
|
||||
);
|
||||
}
|
||||
// not implemented
|
||||
throw Error(`not supported internal db changes from ${oldVer} to ${newVer}`);
|
||||
};
|
||||
|
||||
export const prepareDBs = async (vaultRandomID: string) => {
|
||||
export const prepareDBs = async (
|
||||
vaultBasePath: string,
|
||||
vaultRandomIDFromOldConfigFile: string
|
||||
) => {
|
||||
const db = {
|
||||
versionTbl: localforage.createInstance({
|
||||
name: DEFAULT_DB_NAME,
|
||||
storeName: DEFAULT_TBL_VERSION,
|
||||
}),
|
||||
deleteHistoryTbl: localforage.createInstance({
|
||||
fileHistoryTbl: localforage.createInstance({
|
||||
name: DEFAULT_DB_NAME,
|
||||
storeName: DEFAULT_TBL_DELETE_HISTORY,
|
||||
storeName: DEFAULT_TBL_FILE_HISTORY,
|
||||
}),
|
||||
syncMappingTbl: localforage.createInstance({
|
||||
name: DEFAULT_DB_NAME,
|
||||
@@ -170,9 +207,42 @@ export const prepareDBs = async (vaultRandomID: string) => {
|
||||
name: DEFAULT_DB_NAME,
|
||||
storeName: DEFAULT_SYNC_PLANS_HISTORY,
|
||||
}),
|
||||
vaultRandomIDMappingTbl: localforage.createInstance({
|
||||
name: DEFAULT_DB_NAME,
|
||||
storeName: DEFAULT_TBL_VAULT_RANDOM_ID_MAPPING,
|
||||
}),
|
||||
} as InternalDBs;
|
||||
|
||||
const originalVersion = (await db.versionTbl.getItem("version")) as number;
|
||||
// try to get vaultRandomID firstly
|
||||
let vaultRandomID = "";
|
||||
const vaultRandomIDInDB: string | null =
|
||||
await db.vaultRandomIDMappingTbl.getItem(`path2id\t${vaultBasePath}`);
|
||||
if (vaultRandomIDInDB === null) {
|
||||
if (vaultRandomIDFromOldConfigFile !== "") {
|
||||
// reuse the old config id
|
||||
vaultRandomID = vaultRandomIDFromOldConfigFile;
|
||||
} else {
|
||||
// no old config id, we create a random one
|
||||
vaultRandomID = nanoid();
|
||||
}
|
||||
// save the id back
|
||||
await db.vaultRandomIDMappingTbl.setItem(
|
||||
`path2id\t${vaultBasePath}`,
|
||||
vaultRandomID
|
||||
);
|
||||
await db.vaultRandomIDMappingTbl.setItem(
|
||||
`id2path\t${vaultRandomID}`,
|
||||
vaultBasePath
|
||||
);
|
||||
} else {
|
||||
vaultRandomID = vaultRandomIDInDB;
|
||||
}
|
||||
|
||||
if (vaultRandomID === "") {
|
||||
throw Error("no vaultRandomID found or generated");
|
||||
}
|
||||
|
||||
const originalVersion: number | null = await db.versionTbl.getItem("version");
|
||||
if (originalVersion === null) {
|
||||
log.debug(
|
||||
`no internal db version, setting it to ${DEFAULT_DB_VERSION_NUMBER}`
|
||||
@@ -193,7 +263,10 @@ export const prepareDBs = async (vaultRandomID: string) => {
|
||||
}
|
||||
|
||||
log.info("db connected");
|
||||
return db;
|
||||
return {
|
||||
db: db,
|
||||
vaultRandomID: vaultRandomID,
|
||||
};
|
||||
};
|
||||
|
||||
export const destroyDBs = async () => {
|
||||
@@ -206,20 +279,20 @@ export const destroyDBs = async () => {
|
||||
log.info("db deleted");
|
||||
};
|
||||
req.onblocked = (event) => {
|
||||
console.warn("trying to delete db but it was blocked");
|
||||
log.warn("trying to delete db but it was blocked");
|
||||
};
|
||||
req.onerror = (event) => {
|
||||
console.error("tried to delete db but something bad!");
|
||||
console.error(event);
|
||||
log.error("tried to delete db but something goes wrong!");
|
||||
log.error(event);
|
||||
};
|
||||
};
|
||||
|
||||
export const loadDeleteRenameHistoryTableByVault = async (
|
||||
export const loadFileHistoryTableByVault = async (
|
||||
db: InternalDBs,
|
||||
vaultRandomID: string
|
||||
) => {
|
||||
const records = [] as FileFolderHistoryRecord[];
|
||||
await db.deleteHistoryTbl.iterate((value, key, iterationNumber) => {
|
||||
await db.fileHistoryTbl.iterate((value, key, iterationNumber) => {
|
||||
if (key.startsWith(`${vaultRandomID}\t`)) {
|
||||
records.push(value as FileFolderHistoryRecord);
|
||||
}
|
||||
@@ -233,7 +306,16 @@ export const clearDeleteRenameHistoryOfKeyAndVault = async (
|
||||
key: string,
|
||||
vaultRandomID: string
|
||||
) => {
|
||||
await db.deleteHistoryTbl.removeItem(`${vaultRandomID}\t${key}`);
|
||||
const fullKey = `${vaultRandomID}\t${key}`;
|
||||
const item: FileFolderHistoryRecord | null = await db.fileHistoryTbl.getItem(
|
||||
fullKey
|
||||
);
|
||||
if (
|
||||
item !== null &&
|
||||
(item.actionType === "delete" || item.actionType === "rename")
|
||||
) {
|
||||
await db.fileHistoryTbl.removeItem(fullKey);
|
||||
}
|
||||
};
|
||||
|
||||
export const insertDeleteRecordByVault = async (
|
||||
@@ -260,10 +342,12 @@ export const insertDeleteRecordByVault = async (
|
||||
const key = fileOrFolder.path.endsWith("/")
|
||||
? fileOrFolder.path
|
||||
: `${fileOrFolder.path}/`;
|
||||
const ctime = 0; // they are deleted, so no way to get ctime, mtime
|
||||
const mtime = 0; // they are deleted, so no way to get ctime, mtime
|
||||
k = {
|
||||
key: key,
|
||||
ctime: 0,
|
||||
mtime: 0,
|
||||
ctime: ctime,
|
||||
mtime: mtime,
|
||||
size: 0,
|
||||
actionWhen: Date.now(),
|
||||
actionType: "delete",
|
||||
@@ -272,9 +356,19 @@ export const insertDeleteRecordByVault = async (
|
||||
vaultRandomID: vaultRandomID,
|
||||
};
|
||||
}
|
||||
await db.deleteHistoryTbl.setItem(`${vaultRandomID}\t${k.key}`, k);
|
||||
await db.fileHistoryTbl.setItem(`${vaultRandomID}\t${k.key}`, k);
|
||||
};
|
||||
|
||||
/**
|
||||
* A file/folder is renamed from A to B
|
||||
* We insert two records:
|
||||
* A with actionType="rename"
|
||||
* B with actionType="renameDestination"
|
||||
* @param db
|
||||
* @param fileOrFolder
|
||||
* @param oldPath
|
||||
* @param vaultRandomID
|
||||
*/
|
||||
export const insertRenameRecordByVault = async (
|
||||
db: InternalDBs,
|
||||
fileOrFolder: TAbstractFile,
|
||||
@@ -282,37 +376,73 @@ export const insertRenameRecordByVault = async (
|
||||
vaultRandomID: string
|
||||
) => {
|
||||
// log.info(fileOrFolder);
|
||||
let k: FileFolderHistoryRecord;
|
||||
let k1: FileFolderHistoryRecord;
|
||||
let k2: FileFolderHistoryRecord;
|
||||
const actionWhen = Date.now();
|
||||
if (fileOrFolder instanceof TFile) {
|
||||
k = {
|
||||
k1 = {
|
||||
key: oldPath,
|
||||
ctime: fileOrFolder.stat.ctime,
|
||||
mtime: fileOrFolder.stat.mtime,
|
||||
size: fileOrFolder.stat.size,
|
||||
actionWhen: Date.now(),
|
||||
actionWhen: actionWhen,
|
||||
actionType: "rename",
|
||||
keyType: "file",
|
||||
renameTo: fileOrFolder.path,
|
||||
vaultRandomID: vaultRandomID,
|
||||
};
|
||||
k2 = {
|
||||
key: fileOrFolder.path,
|
||||
ctime: fileOrFolder.stat.ctime,
|
||||
mtime: fileOrFolder.stat.mtime,
|
||||
size: fileOrFolder.stat.size,
|
||||
actionWhen: actionWhen,
|
||||
actionType: "renameDestination",
|
||||
keyType: "file",
|
||||
renameTo: "", // itself is the destination, so no need to set this field
|
||||
vaultRandomID: vaultRandomID,
|
||||
};
|
||||
} else if (fileOrFolder instanceof TFolder) {
|
||||
const key = oldPath.endsWith("/") ? oldPath : `${oldPath}/`;
|
||||
const renameTo = fileOrFolder.path.endsWith("/")
|
||||
? fileOrFolder.path
|
||||
: `${fileOrFolder.path}/`;
|
||||
k = {
|
||||
let ctime = 0;
|
||||
let mtime = 0;
|
||||
if (requireApiVersion(API_VER_STAT_FOLDER)) {
|
||||
// TAbstractFile does not contain these info
|
||||
// but from API_VER_STAT_FOLDER we can manually stat them by path.
|
||||
const s = await fileOrFolder.vault.adapter.stat(fileOrFolder.path);
|
||||
ctime = s.ctime;
|
||||
mtime = s.mtime;
|
||||
}
|
||||
k1 = {
|
||||
key: key,
|
||||
ctime: 0,
|
||||
mtime: 0,
|
||||
ctime: ctime,
|
||||
mtime: mtime,
|
||||
size: 0,
|
||||
actionWhen: Date.now(),
|
||||
actionWhen: actionWhen,
|
||||
actionType: "rename",
|
||||
keyType: "folder",
|
||||
renameTo: renameTo,
|
||||
vaultRandomID: vaultRandomID,
|
||||
};
|
||||
k2 = {
|
||||
key: renameTo,
|
||||
ctime: ctime,
|
||||
mtime: mtime,
|
||||
size: 0,
|
||||
actionWhen: actionWhen,
|
||||
actionType: "renameDestination",
|
||||
keyType: "folder",
|
||||
renameTo: "", // itself is the destination, so no need to set this field
|
||||
vaultRandomID: vaultRandomID,
|
||||
};
|
||||
}
|
||||
await db.deleteHistoryTbl.setItem(`${vaultRandomID}\t${k.key}`, k);
|
||||
await Promise.all([
|
||||
db.fileHistoryTbl.setItem(`${vaultRandomID}\t${k1.key}`, k1),
|
||||
db.fileHistoryTbl.setItem(`${vaultRandomID}\t${k2.key}`, k2),
|
||||
]);
|
||||
};
|
||||
|
||||
export const upsertSyncMetaMappingDataByVault = async (
|
||||
|
||||
+95
-41
@@ -1,6 +1,13 @@
|
||||
import { Modal, Notice, Plugin, Setting, addIcon, setIcon } from "obsidian";
|
||||
import {
|
||||
Modal,
|
||||
Notice,
|
||||
Plugin,
|
||||
Setting,
|
||||
addIcon,
|
||||
setIcon,
|
||||
FileSystemAdapter,
|
||||
} from "obsidian";
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import { nanoid } from "nanoid";
|
||||
import { createElement, RotateCcw, RefreshCcw } from "lucide";
|
||||
import type { RemotelySavePluginSettings } from "./baseTypes";
|
||||
import {
|
||||
@@ -10,13 +17,13 @@ import {
|
||||
COMMAND_URI,
|
||||
} from "./baseTypes";
|
||||
import { importQrCodeUri } from "./importExport";
|
||||
import type { InternalDBs } from "./localdb";
|
||||
import {
|
||||
insertDeleteRecordByVault,
|
||||
insertRenameRecordByVault,
|
||||
insertSyncPlanRecordByVault,
|
||||
loadDeleteRenameHistoryTableByVault,
|
||||
loadFileHistoryTableByVault,
|
||||
prepareDBs,
|
||||
InternalDBs,
|
||||
} from "./localdb";
|
||||
import { RemoteClient } from "./remote";
|
||||
import {
|
||||
@@ -54,7 +61,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
|
||||
password: "",
|
||||
serviceType: "s3",
|
||||
currLogLevel: "info",
|
||||
vaultRandomID: "",
|
||||
// vaultRandomID: "", // deprecated
|
||||
autoRunEveryMilliseconds: -1,
|
||||
initRunAfterMilliseconds: -1,
|
||||
agreeToUploadExtraMetadata: false,
|
||||
@@ -77,16 +84,25 @@ type SyncTriggerSourceType = "manual" | "auto" | "dry" | "autoOnceInit";
|
||||
const iconNameSyncWait = `remotely-save-sync-wait`;
|
||||
const iconNameSyncRunning = `remotely-save-sync-running`;
|
||||
|
||||
const iconSvgSyncWait = createElement(RotateCcw);
|
||||
iconSvgSyncWait.setAttribute("width", "100");
|
||||
iconSvgSyncWait.setAttribute("height", "100");
|
||||
const iconSvgSyncRunning = createElement(RefreshCcw);
|
||||
iconSvgSyncRunning.setAttribute("width", "100");
|
||||
iconSvgSyncRunning.setAttribute("height", "100");
|
||||
const getIconSvg = () => {
|
||||
const iconSvgSyncWait = createElement(RotateCcw);
|
||||
iconSvgSyncWait.setAttribute("width", "100");
|
||||
iconSvgSyncWait.setAttribute("height", "100");
|
||||
const iconSvgSyncRunning = createElement(RefreshCcw);
|
||||
iconSvgSyncRunning.setAttribute("width", "100");
|
||||
iconSvgSyncRunning.setAttribute("height", "100");
|
||||
const res = {
|
||||
iconSvgSyncWait: iconSvgSyncWait.outerHTML,
|
||||
iconSvgSyncRunning: iconSvgSyncRunning.outerHTML,
|
||||
};
|
||||
|
||||
iconSvgSyncWait.empty();
|
||||
iconSvgSyncRunning.empty();
|
||||
return res;
|
||||
};
|
||||
|
||||
export default class RemotelySavePlugin extends Plugin {
|
||||
settings: RemotelySavePluginSettings;
|
||||
// cm: CodeMirror.Editor;
|
||||
db: InternalDBs;
|
||||
syncStatus: SyncStatusType;
|
||||
oauth2Info: OAuth2Info;
|
||||
@@ -95,6 +111,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
syncRibbon?: HTMLElement;
|
||||
autoRunIntervalID?: number;
|
||||
i18n: I18n;
|
||||
vaultRandomID: string;
|
||||
|
||||
async syncRun(triggerSource: SyncTriggerSourceType = "manual") {
|
||||
const t = (x: TransItemType, vars?: any) => {
|
||||
@@ -207,7 +224,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
const { remoteStates, metadataFile } = await parseRemoteItems(
|
||||
remoteRsp.Contents,
|
||||
this.db,
|
||||
this.settings.vaultRandomID,
|
||||
this.vaultRandomID,
|
||||
client.serviceType,
|
||||
this.settings.password
|
||||
);
|
||||
@@ -225,9 +242,9 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
);
|
||||
this.syncStatus = "getting_local_meta";
|
||||
const local = this.app.vault.getAllLoadedFiles();
|
||||
const localHistory = await loadDeleteRenameHistoryTableByVault(
|
||||
const localHistory = await loadFileHistoryTableByVault(
|
||||
this.db,
|
||||
this.settings.vaultRandomID
|
||||
this.vaultRandomID
|
||||
);
|
||||
let localConfigDirContents: ObsConfigDirFileType[] = undefined;
|
||||
if (this.settings.syncConfigDir) {
|
||||
@@ -261,11 +278,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
);
|
||||
log.info(plan.mixedStates); // for debugging
|
||||
if (triggerSource !== "dry") {
|
||||
await insertSyncPlanRecordByVault(
|
||||
this.db,
|
||||
plan,
|
||||
this.settings.vaultRandomID
|
||||
);
|
||||
await insertSyncPlanRecordByVault(this.db, plan, this.vaultRandomID);
|
||||
}
|
||||
|
||||
// The operations above are almost read only and kind of safe.
|
||||
@@ -282,7 +295,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
await doActualSync(
|
||||
client,
|
||||
this.db,
|
||||
this.settings.vaultRandomID,
|
||||
this.vaultRandomID,
|
||||
this.app.vault,
|
||||
plan,
|
||||
sortedKeys,
|
||||
@@ -344,8 +357,10 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
async onload() {
|
||||
log.info(`loading plugin ${this.manifest.id}`);
|
||||
|
||||
addIcon(iconNameSyncWait, iconSvgSyncWait.outerHTML);
|
||||
addIcon(iconNameSyncRunning, iconSvgSyncRunning.outerHTML);
|
||||
const { iconSvgSyncWait, iconSvgSyncRunning } = getIconSvg();
|
||||
|
||||
addIcon(iconNameSyncWait, iconSvgSyncWait);
|
||||
addIcon(iconNameSyncRunning, iconSvgSyncRunning);
|
||||
|
||||
this.oauth2Info = {
|
||||
verifier: "",
|
||||
@@ -373,12 +388,27 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
}
|
||||
|
||||
await this.checkIfOauthExpires();
|
||||
await this.checkIfVaultIDAssigned(); // MUST before prepareDB()
|
||||
|
||||
// MUST before prepareDB()
|
||||
// And, it's also possible to be an empty string,
|
||||
// which means the vaultRandomID is read from db later!
|
||||
const vaultRandomIDFromOldConfigFile =
|
||||
await this.getVaultRandomIDFromOldConfigFile();
|
||||
|
||||
// no need to await this
|
||||
this.tryToAddIgnoreFile();
|
||||
|
||||
await this.prepareDB();
|
||||
const vaultBasePath = this.getVaultBasePath();
|
||||
|
||||
try {
|
||||
await this.prepareDBAndVaultRandomID(
|
||||
vaultBasePath,
|
||||
vaultRandomIDFromOldConfigFile
|
||||
);
|
||||
} catch (err) {
|
||||
new Notice(err.message, 10 * 1000);
|
||||
throw err;
|
||||
}
|
||||
|
||||
this.syncStatus = "idle";
|
||||
|
||||
@@ -387,7 +417,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
await insertDeleteRecordByVault(
|
||||
this.db,
|
||||
fileOrFolder,
|
||||
this.settings.vaultRandomID
|
||||
this.vaultRandomID
|
||||
);
|
||||
})
|
||||
);
|
||||
@@ -398,7 +428,7 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
this.db,
|
||||
fileOrFolder,
|
||||
oldPath,
|
||||
this.settings.vaultRandomID
|
||||
this.vaultRandomID
|
||||
);
|
||||
})
|
||||
);
|
||||
@@ -629,9 +659,13 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
onunload() {
|
||||
async onunload() {
|
||||
log.info(`unloading plugin ${this.manifest.id}`);
|
||||
this.destroyDBs();
|
||||
this.syncRibbon = undefined;
|
||||
if (this.oauth2Info !== undefined) {
|
||||
this.oauth2Info.helperModal = undefined;
|
||||
this.oauth2Info = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
@@ -737,14 +771,20 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
async checkIfVaultIDAssigned() {
|
||||
if (
|
||||
this.settings.vaultRandomID === undefined ||
|
||||
this.settings.vaultRandomID === ""
|
||||
) {
|
||||
this.settings.vaultRandomID = nanoid();
|
||||
async getVaultRandomIDFromOldConfigFile() {
|
||||
let vaultRandomID = "";
|
||||
if (this.settings.vaultRandomID !== undefined) {
|
||||
// In old version, the vault id is saved in data.json
|
||||
// But we want to store it in localForage later
|
||||
if (this.settings.vaultRandomID !== "") {
|
||||
// a real string was assigned before
|
||||
vaultRandomID = this.settings.vaultRandomID;
|
||||
}
|
||||
log.debug("vaultRandomID is no longer saved in data.json");
|
||||
delete this.settings.vaultRandomID;
|
||||
await this.saveSettings();
|
||||
}
|
||||
return vaultRandomID;
|
||||
}
|
||||
|
||||
async trash(x: string) {
|
||||
@@ -753,8 +793,26 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
async prepareDB() {
|
||||
this.db = await prepareDBs(this.settings.vaultRandomID);
|
||||
getVaultBasePath() {
|
||||
if (this.app.vault.adapter instanceof FileSystemAdapter) {
|
||||
// in desktop
|
||||
return this.app.vault.adapter.getBasePath().split("?")[0];
|
||||
} else {
|
||||
// in mobile
|
||||
return this.app.vault.adapter.getResourcePath("").split("?")[0];
|
||||
}
|
||||
}
|
||||
|
||||
async prepareDBAndVaultRandomID(
|
||||
vaultBasePath: string,
|
||||
vaultRandomIDFromOldConfigFile: string
|
||||
) {
|
||||
const { db, vaultRandomID } = await prepareDBs(
|
||||
vaultBasePath,
|
||||
vaultRandomIDFromOldConfigFile
|
||||
);
|
||||
this.db = db;
|
||||
this.vaultRandomID = vaultRandomID;
|
||||
}
|
||||
|
||||
enableAutoSyncIfSet() {
|
||||
@@ -792,10 +850,6 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
await this.saveSettings();
|
||||
}
|
||||
|
||||
destroyDBs() {
|
||||
/* destroyDBs(this.db); */
|
||||
}
|
||||
|
||||
async setCurrSyncMsg(
|
||||
i: number,
|
||||
totalCount: number,
|
||||
|
||||
+21
-12
@@ -1,5 +1,13 @@
|
||||
import { Buffer } from "buffer";
|
||||
import { Vault, request, requestUrl, requireApiVersion } from "obsidian";
|
||||
import {
|
||||
Vault,
|
||||
request,
|
||||
requestUrl,
|
||||
requireApiVersion,
|
||||
Platform,
|
||||
Notice,
|
||||
RequestUrlResponse,
|
||||
} from "obsidian";
|
||||
|
||||
import { Queue } from "@fyears/tsqueue";
|
||||
import chunk from "lodash/chunk";
|
||||
@@ -20,7 +28,7 @@ import type {
|
||||
ResponseDataDetailed,
|
||||
} from "webdav/web";
|
||||
import { getPatcher } from "webdav/web";
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
if (requireApiVersion(API_VER_REQURL) && !Platform.isAndroidApp) {
|
||||
getPatcher().patch(
|
||||
"request",
|
||||
async (
|
||||
@@ -204,13 +212,13 @@ export class WrappedWebdavClient {
|
||||
if (this.vaultFolderExists) {
|
||||
// pass
|
||||
} else {
|
||||
const res = await this.client.exists(`/${this.vaultName}`);
|
||||
const res = await this.client.exists(`/${this.vaultName}/`);
|
||||
if (res) {
|
||||
// log.info("remote vault folder exits!");
|
||||
this.vaultFolderExists = true;
|
||||
} else {
|
||||
log.info("remote vault folder not exists, creating");
|
||||
await this.client.createDirectory(`/${this.vaultName}`);
|
||||
await this.client.createDirectory(`/${this.vaultName}/`);
|
||||
log.info("remote vault folder created!");
|
||||
this.vaultFolderExists = true;
|
||||
}
|
||||
@@ -220,7 +228,7 @@ export class WrappedWebdavClient {
|
||||
if (this.webdavConfig.depth === "auto_unknown") {
|
||||
let testPassed = false;
|
||||
try {
|
||||
const res = await this.client.customRequest(`/${this.vaultName}`, {
|
||||
const res = await this.client.customRequest(`/${this.vaultName}/`, {
|
||||
method: "PROPFIND",
|
||||
headers: {
|
||||
Depth: "infinity",
|
||||
@@ -239,7 +247,7 @@ export class WrappedWebdavClient {
|
||||
}
|
||||
if (!testPassed) {
|
||||
try {
|
||||
const res = await this.client.customRequest(`/${this.vaultName}`, {
|
||||
const res = await this.client.customRequest(`/${this.vaultName}/`, {
|
||||
method: "PROPFIND",
|
||||
headers: {
|
||||
Depth: "1",
|
||||
@@ -321,7 +329,7 @@ export const uploadToRemote = async (
|
||||
if (password === "") {
|
||||
// if not encrypted, mkdir a remote folder
|
||||
await client.client.createDirectory(uploadFile, {
|
||||
recursive: true,
|
||||
recursive: false, // the sync algo should guarantee no need to recursive
|
||||
});
|
||||
const res = await getRemoteMeta(client, uploadFile);
|
||||
return res;
|
||||
@@ -353,11 +361,12 @@ export const uploadToRemote = async (
|
||||
if (password !== "") {
|
||||
remoteContent = await encryptArrayBuffer(localContent, password);
|
||||
}
|
||||
// we need to create folders before uploading
|
||||
const dir = getPathFolder(uploadFile);
|
||||
if (dir !== "/" && dir !== "") {
|
||||
await client.client.createDirectory(dir, { recursive: true });
|
||||
}
|
||||
// updated 20220326: the algorithm guarantee this
|
||||
// // we need to create folders before uploading
|
||||
// const dir = getPathFolder(uploadFile);
|
||||
// if (dir !== "/" && dir !== "") {
|
||||
// await client.client.createDirectory(dir, { recursive: false });
|
||||
// }
|
||||
await client.client.putFileContents(uploadFile, remoteContent, {
|
||||
overwrite: true,
|
||||
onUploadProgress: (progress: any) => {
|
||||
|
||||
+61
-25
@@ -1105,6 +1105,9 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
this.plugin.settings.serviceType !== "webdav"
|
||||
);
|
||||
|
||||
const webdavReq =
|
||||
requireApiVersion(API_VER_REQURL) && !Platform.isAndroidApp;
|
||||
|
||||
webdavDiv.createEl("h2", { text: t("settings_webdav") });
|
||||
|
||||
webdavDiv.createEl("p", {
|
||||
@@ -1112,7 +1115,17 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
cls: "webdav-disclaimer",
|
||||
});
|
||||
|
||||
if (!requireApiVersion(API_VER_REQURL)) {
|
||||
if (!webdavReq) {
|
||||
if (Platform.isAndroidApp) {
|
||||
webdavDiv.createEl("p", {
|
||||
text: t("settings_webdav_cors_android"),
|
||||
});
|
||||
} else {
|
||||
webdavDiv.createEl("p", {
|
||||
text: t("settings_webdav_cors_otheros"),
|
||||
});
|
||||
}
|
||||
|
||||
webdavDiv.createEl("p", {
|
||||
text: t("settings_webdav_cors"),
|
||||
});
|
||||
@@ -1133,6 +1146,12 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
.setValue(this.plugin.settings.webdav.address)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.webdav.address = value.trim();
|
||||
if (
|
||||
this.plugin.settings.webdav.depth === "auto_1" ||
|
||||
this.plugin.settings.webdav.depth === "auto_infinity"
|
||||
) {
|
||||
this.plugin.settings.webdav.depth = "auto_unknown";
|
||||
}
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
@@ -1146,6 +1165,12 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
.setValue(this.plugin.settings.webdav.username)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.webdav.username = value.trim();
|
||||
if (
|
||||
this.plugin.settings.webdav.depth === "auto_1" ||
|
||||
this.plugin.settings.webdav.depth === "auto_infinity"
|
||||
) {
|
||||
this.plugin.settings.webdav.depth = "auto_unknown";
|
||||
}
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
@@ -1159,6 +1184,12 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
.setValue(this.plugin.settings.webdav.password)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.webdav.password = value.trim();
|
||||
if (
|
||||
this.plugin.settings.webdav.depth === "auto_1" ||
|
||||
this.plugin.settings.webdav.depth === "auto_infinity"
|
||||
) {
|
||||
this.plugin.settings.webdav.depth = "auto_unknown";
|
||||
}
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
@@ -1168,15 +1199,12 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
.setDesc(t("settings_webdav_auth_desc"))
|
||||
.addDropdown(async (dropdown) => {
|
||||
dropdown.addOption("basic", "basic");
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
if (webdavReq) {
|
||||
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"
|
||||
) {
|
||||
if (!webdavReq && this.plugin.settings.webdav.authType !== "basic") {
|
||||
this.plugin.settings.webdav.authType = "basic";
|
||||
await this.plugin.saveSettings();
|
||||
}
|
||||
@@ -1249,16 +1277,11 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
if (res) {
|
||||
new Notice(t("settings_webdav_connect_succ"));
|
||||
} else {
|
||||
let corsErrMsg = "/CORS";
|
||||
if (requireApiVersion(API_VER_REQURL)) {
|
||||
corsErrMsg = "";
|
||||
if (webdavReq) {
|
||||
new Notice(t("settings_webdav_connect_fail"));
|
||||
} else {
|
||||
new Notice(t("settings_webdav_connect_fail_withcors"));
|
||||
}
|
||||
|
||||
new Notice(
|
||||
t("settings_webdav_connect_fail", {
|
||||
corsErrMsg: corsErrMsg,
|
||||
})
|
||||
);
|
||||
new Notice(errors.msg);
|
||||
}
|
||||
});
|
||||
@@ -1371,15 +1394,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
.onChange(async (val) => {
|
||||
if (val === "enable" && !bridge.secondConfirm) {
|
||||
dropdown.setValue("disable");
|
||||
const modal = new SyncConfigDirModal(
|
||||
this.app,
|
||||
this.plugin,
|
||||
() => {
|
||||
bridge.secondConfirm = true;
|
||||
dropdown.setValue("enable");
|
||||
}
|
||||
);
|
||||
modal.open();
|
||||
new SyncConfigDirModal(this.app, this.plugin, () => {
|
||||
bridge.secondConfirm = true;
|
||||
dropdown.setValue("enable");
|
||||
}).open();
|
||||
} else {
|
||||
bridge.secondConfirm = false;
|
||||
this.plugin.settings.syncConfigDir = false;
|
||||
@@ -1461,7 +1479,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
await exportVaultSyncPlansToFiles(
|
||||
this.plugin.db,
|
||||
this.app.vault,
|
||||
this.plugin.settings.vaultRandomID
|
||||
this.plugin.vaultRandomID
|
||||
);
|
||||
new Notice(t("settings_syncplans_notice"));
|
||||
});
|
||||
@@ -1489,6 +1507,18 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
});
|
||||
});
|
||||
|
||||
const outputCurrBasePathVaultIDDiv = debugDiv.createDiv("div");
|
||||
new Setting(outputCurrBasePathVaultIDDiv)
|
||||
.setName(t("settings_outputbasepathvaultid"))
|
||||
.setDesc(t("settings_outputbasepathvaultid_desc"))
|
||||
.addButton(async (button) => {
|
||||
button.setButtonText(t("settings_outputbasepathvaultid_button"));
|
||||
button.onClick(async () => {
|
||||
new Notice(this.plugin.getVaultBasePath());
|
||||
new Notice(this.plugin.vaultRandomID);
|
||||
});
|
||||
});
|
||||
|
||||
const dbsResetDiv = debugDiv.createEl("div");
|
||||
new Setting(dbsResetDiv)
|
||||
.setName(t("settings_resetcache"))
|
||||
@@ -1501,4 +1531,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
hide() {
|
||||
let { containerEl } = this;
|
||||
containerEl.empty();
|
||||
super.hide();
|
||||
}
|
||||
}
|
||||
|
||||
+72
-25
@@ -218,7 +218,7 @@ export const parseRemoteItems = async (
|
||||
mtimeRemote: backwardMapping.localMtime || entry.lastModified,
|
||||
sizeRemote: backwardMapping.localSize || entry.size,
|
||||
remoteEncryptedKey: remoteEncryptedKey,
|
||||
changeMtimeUsingMapping: true,
|
||||
changeRemoteMtimeUsingMapping: true,
|
||||
};
|
||||
} else {
|
||||
r = {
|
||||
@@ -227,7 +227,7 @@ export const parseRemoteItems = async (
|
||||
mtimeRemote: entry.lastModified,
|
||||
sizeRemote: entry.size,
|
||||
remoteEncryptedKey: remoteEncryptedKey,
|
||||
changeMtimeUsingMapping: false,
|
||||
changeRemoteMtimeUsingMapping: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ const ensembleMixedStates = async (
|
||||
local: TAbstractFile[],
|
||||
localConfigDirContents: ObsConfigDirFileType[] | undefined,
|
||||
remoteDeleteHistory: DeletionOnRemote[],
|
||||
localDeleteHistory: FileFolderHistoryRecord[],
|
||||
localFileHistory: FileFolderHistoryRecord[],
|
||||
syncConfigDir: boolean,
|
||||
configDir: string,
|
||||
syncUnderscoreItems: boolean
|
||||
@@ -397,7 +397,7 @@ const ensembleMixedStates = async (
|
||||
}
|
||||
}
|
||||
|
||||
for (const entry of localDeleteHistory) {
|
||||
for (const entry of localFileHistory) {
|
||||
let key = entry.key;
|
||||
if (entry.keyType === "folder") {
|
||||
if (!entry.key.endsWith("/")) {
|
||||
@@ -409,23 +409,45 @@ const ensembleMixedStates = async (
|
||||
throw Error(`unexpected ${entry}`);
|
||||
}
|
||||
|
||||
const r = {
|
||||
key: key,
|
||||
deltimeLocal: entry.actionWhen,
|
||||
} as FileOrFolderMixedState;
|
||||
|
||||
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (results.hasOwnProperty(key)) {
|
||||
results[key].key = r.key;
|
||||
results[key].deltimeLocal = r.deltimeLocal;
|
||||
} else {
|
||||
results[key] = r;
|
||||
if (entry.actionType === "delete" || entry.actionType === "rename") {
|
||||
const r = {
|
||||
key: key,
|
||||
deltimeLocal: entry.actionWhen,
|
||||
} as FileOrFolderMixedState;
|
||||
|
||||
results[key].existLocal = false;
|
||||
results[key].existRemote = false;
|
||||
if (results.hasOwnProperty(key)) {
|
||||
results[key].deltimeLocal = r.deltimeLocal;
|
||||
} else {
|
||||
results[key] = r;
|
||||
results[key].existLocal = false; // we have already checked local
|
||||
results[key].existRemote = false; // we have already checked remote
|
||||
}
|
||||
} else if (entry.actionType === "renameDestination") {
|
||||
const r = {
|
||||
key: key,
|
||||
mtimeLocal: entry.actionWhen,
|
||||
changeLocalMtimeUsingMapping: true,
|
||||
};
|
||||
if (results.hasOwnProperty(key)) {
|
||||
results[key].mtimeLocal = Math.max(
|
||||
r.mtimeLocal || 0,
|
||||
results[key].mtimeLocal || 0
|
||||
);
|
||||
results[key].changeLocalMtimeUsingMapping =
|
||||
r.changeLocalMtimeUsingMapping;
|
||||
} else {
|
||||
results[key] = r;
|
||||
results[key].existLocal = false; // we have already checked local
|
||||
results[key].existRemote = false; // we have already checked remote
|
||||
}
|
||||
} else {
|
||||
throw Error(
|
||||
`do not know how to deal with local file history ${entry.key} with ${entry.actionType}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,12 +502,12 @@ const assignOperationToFileInplace = (
|
||||
// 1. mtimeLocal
|
||||
if (r.existLocal) {
|
||||
const mtimeRemote = r.existRemote ? r.mtimeRemote : -1;
|
||||
const deltime_remote = r.deltimeRemote !== undefined ? r.deltimeRemote : -1;
|
||||
const deltimeRemote = r.deltimeRemote !== undefined ? r.deltimeRemote : -1;
|
||||
const deltimeLocal = r.deltimeLocal !== undefined ? r.deltimeLocal : -1;
|
||||
if (
|
||||
r.mtimeLocal >= mtimeRemote &&
|
||||
r.mtimeLocal >= deltimeLocal &&
|
||||
r.mtimeLocal >= deltime_remote
|
||||
r.mtimeLocal >= deltimeRemote
|
||||
) {
|
||||
if (r.mtimeLocal === r.mtimeRemote) {
|
||||
// mtime the same
|
||||
@@ -516,12 +538,12 @@ const assignOperationToFileInplace = (
|
||||
// 2. mtimeRemote
|
||||
if (r.existRemote) {
|
||||
const mtimeLocal = r.existLocal ? r.mtimeLocal : -1;
|
||||
const deltime_remote = r.deltimeRemote !== undefined ? r.deltimeRemote : -1;
|
||||
const deltimeRemote = r.deltimeRemote !== undefined ? r.deltimeRemote : -1;
|
||||
const deltimeLocal = r.deltimeLocal !== undefined ? r.deltimeLocal : -1;
|
||||
if (
|
||||
r.mtimeRemote > mtimeLocal &&
|
||||
r.mtimeRemote >= deltimeLocal &&
|
||||
r.mtimeRemote >= deltime_remote
|
||||
r.mtimeRemote >= deltimeRemote
|
||||
) {
|
||||
r.decision = "downloadRemoteToLocal";
|
||||
r.decisionBranch = 5;
|
||||
@@ -534,11 +556,11 @@ const assignOperationToFileInplace = (
|
||||
if (r.deltimeLocal !== undefined && r.deltimeLocal !== 0) {
|
||||
const mtimeLocal = r.existLocal ? r.mtimeLocal : -1;
|
||||
const mtimeRemote = r.existRemote ? r.mtimeRemote : -1;
|
||||
const deltime_remote = r.deltimeRemote !== undefined ? r.deltimeRemote : -1;
|
||||
const deltimeRemote = r.deltimeRemote !== undefined ? r.deltimeRemote : -1;
|
||||
if (
|
||||
r.deltimeLocal >= mtimeLocal &&
|
||||
r.deltimeLocal >= mtimeRemote &&
|
||||
r.deltimeLocal >= deltime_remote
|
||||
r.deltimeLocal >= deltimeRemote
|
||||
) {
|
||||
r.decision = "uploadLocalDelHistToRemote";
|
||||
r.decisionBranch = 6;
|
||||
@@ -549,7 +571,7 @@ const assignOperationToFileInplace = (
|
||||
}
|
||||
}
|
||||
|
||||
// 4. deltime_remote
|
||||
// 4. deltimeRemote
|
||||
if (r.deltimeRemote !== undefined && r.deltimeRemote !== 0) {
|
||||
const mtimeLocal = r.existLocal ? r.mtimeLocal : -1;
|
||||
const mtimeRemote = r.existRemote ? r.mtimeRemote : -1;
|
||||
@@ -617,6 +639,31 @@ const assignOperationToFolderInplace = async (
|
||||
}
|
||||
}
|
||||
|
||||
// If it was moved to here, after deletion, we should keep it as is.
|
||||
// The logic not necessarily needs API_VER_STAT_FOLDER.
|
||||
// The folder needs this logic because it's also determined by file children.
|
||||
// But the file do not need this logic because the mtimeLocal is checked firstly.
|
||||
if (
|
||||
r.existLocal &&
|
||||
r.changeLocalMtimeUsingMapping &&
|
||||
r.mtimeLocal > 0 &&
|
||||
r.mtimeLocal > deltimeLocal &&
|
||||
r.mtimeLocal > deltimeRemote
|
||||
) {
|
||||
keptFolder.add(getParentFolder(r.key));
|
||||
if (r.existLocal && r.existRemote) {
|
||||
r.decision = "skipFolder";
|
||||
r.decisionBranch = 16;
|
||||
} else if (r.existLocal || r.existRemote) {
|
||||
r.decision = "createFolder";
|
||||
r.decisionBranch = 17;
|
||||
} else {
|
||||
throw Error(
|
||||
`Error: Folder ${r.key} doesn't exist locally and remotely but is marked must be kept. Abort.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (r.decision === undefined) {
|
||||
// not yet decided by the above reason
|
||||
if (deltimeLocal > 0 && deltimeLocal > deltimeRemote) {
|
||||
@@ -678,7 +725,7 @@ export const getSyncPlan = async (
|
||||
local: TAbstractFile[],
|
||||
localConfigDirContents: ObsConfigDirFileType[] | undefined,
|
||||
remoteDeleteHistory: DeletionOnRemote[],
|
||||
localDeleteHistory: FileFolderHistoryRecord[],
|
||||
localFileHistory: FileFolderHistoryRecord[],
|
||||
remoteType: SUPPORTED_SERVICES_TYPE,
|
||||
vault: Vault,
|
||||
syncConfigDir: boolean,
|
||||
@@ -691,7 +738,7 @@ export const getSyncPlan = async (
|
||||
local,
|
||||
localConfigDirContents,
|
||||
remoteDeleteHistory,
|
||||
localDeleteHistory,
|
||||
localFileHistory,
|
||||
syncConfigDir,
|
||||
configDir,
|
||||
syncUnderscoreItems
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"0.3.2": "0.12.15",
|
||||
"0.3.11": "0.13.21"
|
||||
"0.3.14": "0.13.21"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user