Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d286a79a1 | ||
|
|
e69674e34e | ||
|
|
c3ed69af66 | ||
|
|
832828e6f6 | ||
|
|
b3c9ac8cbb | ||
|
|
8a631ee809 | ||
|
|
b49e545759 | ||
|
|
6588952227 | ||
|
|
0f8b1951a6 | ||
|
|
8b838656ce | ||
|
|
37d36fe5b3 | ||
|
|
d1cfe0c978 | ||
|
|
e3e8db04e2 | ||
|
|
084a04f4e9 | ||
|
|
7b2343e879 | ||
|
|
6969c555da | ||
|
|
229f74b5e8 | ||
|
|
30d94986c6 | ||
|
|
4f03024200 |
@@ -26,7 +26,7 @@ This is yet another unofficial sync plugin for Obsidian. If you like it or find
|
|||||||
- **[End-to-end encryption](./docs/encryption.md) supported.** Files would be encrypted using openssl format before being sent to the cloud **if** user specify a password.
|
- **[End-to-end encryption](./docs/encryption.md) supported.** Files would be encrypted using openssl format before being sent to the cloud **if** user specify a password.
|
||||||
- **Scheduled auto sync supported.** You can also manually trigger the sync using sidebar ribbon, or using the command from the command palette (or even bind the hot key combination to the command then press the hot key combination).
|
- **Scheduled auto sync supported.** You can also manually trigger the sync using sidebar ribbon, or using the command from the command palette (or even bind the hot key combination to the command then press the hot key combination).
|
||||||
- **[Minimal Intrusive](./docs/minimal_intrusive_design.md).**
|
- **[Minimal Intrusive](./docs/minimal_intrusive_design.md).**
|
||||||
- **Skip Large files and skip paths by custom regex conditions!
|
- \*\*Skip Large files and skip paths by custom regex conditions!
|
||||||
- **Fully open source under [Apache-2.0 License](./LICENSE).**
|
- **Fully open source under [Apache-2.0 License](./LICENSE).**
|
||||||
- **[Sync Algorithm open](./docs/sync_algorithm_v2.md) for discussion.**
|
- **[Sync Algorithm open](./docs/sync_algorithm_v2.md) for discussion.**
|
||||||
|
|
||||||
@@ -65,9 +65,8 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a
|
|||||||
- [Cloudflare R2](./docs/remote_services/s3_cloudflare_r2/README.md)
|
- [Cloudflare R2](./docs/remote_services/s3_cloudflare_r2/README.md)
|
||||||
- [MinIO](./docs/remote_services/s3_minio/README.md)
|
- [MinIO](./docs/remote_services/s3_minio/README.md)
|
||||||
- Prepare your S3 (-compatible) service information: [endpoint, region](https://docs.aws.amazon.com/general/latest/gr/s3.html), [access key id, secret access key](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-your-credentials.html), bucket name. The bucket should be empty and solely for syncing a vault.
|
- 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 AWS S3, create [policy and user](./docs/remote_services/s3_general/s3_user_policy.md).
|
||||||
- If you are using Obsidian desktop >= 0.13.25 or mobile >= 1.1.1, you can skip this CORS part.
|
- Very old version of Obsidian needs [configuring CORS](./docs/remote_services/s3_general/s3_cors_configure.md).
|
||||||
- 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.
|
- Download and enable this plugin.
|
||||||
- Enter your information to the settings of 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.
|
- 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.
|
||||||
@@ -95,14 +94,7 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a
|
|||||||
- [ownCloud](./docs/remote_services/webdav_owncloud/README.md)
|
- [ownCloud](./docs/remote_services/webdav_owncloud/README.md)
|
||||||
- [InfiniCloud](./docs/remote_services/webdav_infinicloud_teracloud/README.md)
|
- [InfiniCloud](./docs/remote_services/webdav_infinicloud_teracloud/README.md)
|
||||||
- [坚果云 JianGuoYun/NutStore](./docs/remote_services/webdav_jianguoyun/README.md)
|
- [坚果云 JianGuoYun/NutStore](./docs/remote_services/webdav_jianguoyun/README.md)
|
||||||
- About CORS:
|
- Very old version of Obsidian needs [configuring CORS](./docs/remote_services/webdav_general/webav_cors.md).
|
||||||
- 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.
|
|
||||||
- **Unofficial** workaround: NextCloud users can **evaluate the risk by themselves**, and if decide to accept the risk, they can install [WebAppPassword](https://apps.nextcloud.com/apps/webapppassword) app, and add `app://obsidian.md`, `capacitor://localhost`, `http://localhost` to `Allowed origins`
|
|
||||||
- **Unofficial** workaround: OwnCloud users can **evaluate the risk by themselves**, and if decide to accept the risk, they can download `.tar.gz` of `WebAppPassword` above and manually install and configure it on their instances.
|
|
||||||
- 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.
|
|
||||||
- Your data would be synced to a `${vaultName}` sub folder on your webdav server.
|
- Your data would be synced to a `${vaultName}` sub folder on your webdav server.
|
||||||
- Password-based end-to-end encryption is also supported. But please be aware that **the vault name itself is not encrypted**.
|
- Password-based end-to-end encryption is also supported. But please be aware that **the vault name itself is not encrypted**.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
# AWS S3 Bucket: How to configure user's policy
|
||||||
|
|
||||||
|
## Attention
|
||||||
|
|
||||||
|
Please read the doc carefully and adjust the optional fields accordingly. The doc is not fully tested and contributions are welcome.
|
||||||
|
|
||||||
|
## AWS Official Docs
|
||||||
|
|
||||||
|
- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-policy-language-overview.html>
|
||||||
|
- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-with-s3-actions.html>
|
||||||
|
- <https://docs.aws.amazon.com/AmazonS3/latest/API/API_Operations.html>
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
Using the principle of least privilege is crucial for security when allowing a third party system to access your AWS resources.
|
||||||
|
|
||||||
|
**Prerequisites**: Ensure you have an AWS account and administrative access to manage IAM policies.
|
||||||
|
|
||||||
|
## Step 1: Create a new IAM Policy
|
||||||
|
|
||||||
|
1. Log in to your AWS Management Console.
|
||||||
|
1. Navigate to the IAM Policies section.
|
||||||
|
1. Create a new policy with the following configuration.
|
||||||
|
|
||||||
|
**Note**: `my-bucket` is a placeholder. For example, if your bucket's name is `obsidian-data`, the resource line should read `arn:aws:s3:::obsidian-data`.
|
||||||
|
|
||||||
|
```JSON
|
||||||
|
{
|
||||||
|
"Version": "2012-10-17",
|
||||||
|
"Statement": [
|
||||||
|
{
|
||||||
|
"Sid": "ObsidianBucket",
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Action": [
|
||||||
|
"s3:HeadBucket"
|
||||||
|
],
|
||||||
|
"Resource": "arn:aws:s3:::my-bucket"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Sid": "ObsidianObjects",
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Action": [
|
||||||
|
"s3:HeadObject",
|
||||||
|
"s3:PutObject",
|
||||||
|
"s3:CopyObject",
|
||||||
|
"s3:UploadPart",
|
||||||
|
"s3:UploadPartCopy",
|
||||||
|
"s3:ListMultipartUploads",
|
||||||
|
"s3:AbortMultipartUpload",
|
||||||
|
"s3:CompleteMultipartUpload",
|
||||||
|
"s3:ListObjects",
|
||||||
|
"s3:ListObjectsV2",
|
||||||
|
"s3:ListParts",
|
||||||
|
"s3:GetObject",
|
||||||
|
"s3:GetObjectAttributes",
|
||||||
|
"s3:DeleteObject",
|
||||||
|
"s3:DeleteObjects"
|
||||||
|
],
|
||||||
|
"Resource": "arn:aws:s3:::my-bucket/*"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> The policy allows the Obsidian plugin to list, add, retrieve, and delete objects in the specified S3 bucket.
|
||||||
|
|
||||||
|
## Step 2: Attach the Policy to Obsidian user
|
||||||
|
|
||||||
|
1. Create a new user in the IAM console. (Never use your own root user, as it would have full access to your AWS account).
|
||||||
|
1. When creating the user, select "Attach policy directly" and select the policy created.
|
||||||
|
1. Edit the recent created user and go to "Security Credentials" tab to create your access key.
|
||||||
|
1. Create an Access Key. If asked for a "use case", select "other"
|
||||||
|
1. Use the credentials in the plugin settings. (NEVER share these credentials)
|
||||||
|
|
||||||
|
> PS. The bucket doesn't need to have a policy, only the user.
|
||||||
|
|
||||||
|
## Verifying the Policy
|
||||||
|
|
||||||
|
After attaching the policy, test it by trying to access the S3 bucket through the Obsidian plugin. Ensure that all intended actions can be performed without errors.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
If you encounter permission errors, check the policy for typos in the bucket name or actions. Ensure the policy is attached to the correct user.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
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.
|
||||||
|
- **Unofficial** workaround: NextCloud users can **evaluate the risk by themselves**, and if decide to accept the risk, they can install [WebAppPassword](https://apps.nextcloud.com/apps/webapppassword) app, and add `app://obsidian.md`, `capacitor://localhost`, `http://localhost` to `Allowed origins`
|
||||||
|
- **Unofficial** workaround: OwnCloud users can **evaluate the risk by themselves**, and if decide to accept the risk, they can download `.tar.gz` of `WebAppPassword` above and manually install and configure it on their instances.
|
||||||
|
- [Apache is also possible](./webdav_apache_cors.md).
|
||||||
|
- 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
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "remotely-save",
|
"id": "remotely-save",
|
||||||
"name": "Remotely Save",
|
"name": "Remotely Save",
|
||||||
"version": "0.3.29",
|
"version": "0.3.31",
|
||||||
"minAppVersion": "0.13.21",
|
"minAppVersion": "0.13.21",
|
||||||
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
|
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
|
||||||
"author": "fyears",
|
"author": "fyears",
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ export interface RemotelySavePluginSettings {
|
|||||||
logToDB?: boolean;
|
logToDB?: boolean;
|
||||||
skipSizeLargerThan?: number;
|
skipSizeLargerThan?: number;
|
||||||
ignorePaths?: string[];
|
ignorePaths?: string[];
|
||||||
|
enableStatusBarInfo?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
|
|||||||
+1
-1
Submodule src/langs updated: c75336a2a5...cdbb220a6b
+78
-2
@@ -18,6 +18,7 @@ export const DEFAULT_TBL_SYNC_MAPPING = "syncmetadatahistory";
|
|||||||
export const DEFAULT_SYNC_PLANS_HISTORY = "syncplanshistory";
|
export const DEFAULT_SYNC_PLANS_HISTORY = "syncplanshistory";
|
||||||
export const DEFAULT_TBL_VAULT_RANDOM_ID_MAPPING = "vaultrandomidmapping";
|
export const DEFAULT_TBL_VAULT_RANDOM_ID_MAPPING = "vaultrandomidmapping";
|
||||||
export const DEFAULT_TBL_LOGGER_OUTPUT = "loggeroutput";
|
export const DEFAULT_TBL_LOGGER_OUTPUT = "loggeroutput";
|
||||||
|
export const DEFAULT_TBL_SIMPLE_KV_FOR_MISC = "simplekvformisc";
|
||||||
|
|
||||||
export interface FileFolderHistoryRecord {
|
export interface FileFolderHistoryRecord {
|
||||||
key: string;
|
key: string;
|
||||||
@@ -58,6 +59,7 @@ export interface InternalDBs {
|
|||||||
syncPlansTbl: LocalForage;
|
syncPlansTbl: LocalForage;
|
||||||
vaultRandomIDMappingTbl: LocalForage;
|
vaultRandomIDMappingTbl: LocalForage;
|
||||||
loggerOutputTbl: LocalForage;
|
loggerOutputTbl: LocalForage;
|
||||||
|
simpleKVForMiscTbl: LocalForage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -216,6 +218,10 @@ export const prepareDBs = async (
|
|||||||
name: DEFAULT_DB_NAME,
|
name: DEFAULT_DB_NAME,
|
||||||
storeName: DEFAULT_TBL_LOGGER_OUTPUT,
|
storeName: DEFAULT_TBL_LOGGER_OUTPUT,
|
||||||
}),
|
}),
|
||||||
|
simpleKVForMiscTbl: localforage.createInstance({
|
||||||
|
name: DEFAULT_DB_NAME,
|
||||||
|
storeName: DEFAULT_TBL_SIMPLE_KV_FOR_MISC,
|
||||||
|
}),
|
||||||
} as InternalDBs;
|
} as InternalDBs;
|
||||||
|
|
||||||
// try to get vaultRandomID firstly
|
// try to get vaultRandomID firstly
|
||||||
@@ -324,7 +330,7 @@ export const clearDeleteRenameHistoryOfKeyAndVault = async (
|
|||||||
|
|
||||||
export const insertDeleteRecordByVault = async (
|
export const insertDeleteRecordByVault = async (
|
||||||
db: InternalDBs,
|
db: InternalDBs,
|
||||||
fileOrFolder: TAbstractFile,
|
fileOrFolder: TAbstractFile | string,
|
||||||
vaultRandomID: string
|
vaultRandomID: string
|
||||||
) => {
|
) => {
|
||||||
// log.info(fileOrFolder);
|
// log.info(fileOrFolder);
|
||||||
@@ -341,6 +347,7 @@ export const insertDeleteRecordByVault = async (
|
|||||||
renameTo: "",
|
renameTo: "",
|
||||||
vaultRandomID: vaultRandomID,
|
vaultRandomID: vaultRandomID,
|
||||||
};
|
};
|
||||||
|
await db.fileHistoryTbl.setItem(`${vaultRandomID}\t${k.key}`, k);
|
||||||
} else if (fileOrFolder instanceof TFolder) {
|
} else if (fileOrFolder instanceof TFolder) {
|
||||||
// key should endswith "/"
|
// key should endswith "/"
|
||||||
const key = fileOrFolder.path.endsWith("/")
|
const key = fileOrFolder.path.endsWith("/")
|
||||||
@@ -359,8 +366,57 @@ export const insertDeleteRecordByVault = async (
|
|||||||
renameTo: "",
|
renameTo: "",
|
||||||
vaultRandomID: vaultRandomID,
|
vaultRandomID: vaultRandomID,
|
||||||
};
|
};
|
||||||
|
await db.fileHistoryTbl.setItem(`${vaultRandomID}\t${k.key}`, k);
|
||||||
|
} else if (typeof fileOrFolder === "string") {
|
||||||
|
// always the deletions in .obsidian folder
|
||||||
|
// so annoying that the path doesn't exists
|
||||||
|
// and we have to guess whether the path is folder or file
|
||||||
|
k = {
|
||||||
|
key: fileOrFolder,
|
||||||
|
ctime: 0,
|
||||||
|
mtime: 0,
|
||||||
|
size: 0,
|
||||||
|
actionWhen: Date.now(),
|
||||||
|
actionType: "delete",
|
||||||
|
keyType: "file",
|
||||||
|
renameTo: "",
|
||||||
|
vaultRandomID: vaultRandomID,
|
||||||
|
};
|
||||||
|
await db.fileHistoryTbl.setItem(`${vaultRandomID}\t${k.key}`, k);
|
||||||
|
for (const ext of [
|
||||||
|
"json",
|
||||||
|
"js",
|
||||||
|
"mjs",
|
||||||
|
"ts",
|
||||||
|
"md",
|
||||||
|
"txt",
|
||||||
|
"css",
|
||||||
|
"png",
|
||||||
|
"gif",
|
||||||
|
"jpg",
|
||||||
|
"jpeg",
|
||||||
|
"gitignore",
|
||||||
|
"gitkeep",
|
||||||
|
]) {
|
||||||
|
if (fileOrFolder.endsWith(`.${ext}`)) {
|
||||||
|
// stop here, no more need to insert the folder record later
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// also add a deletion record as folder if not ending with special exts
|
||||||
|
k = {
|
||||||
|
key: `${fileOrFolder}/`,
|
||||||
|
ctime: 0,
|
||||||
|
mtime: 0,
|
||||||
|
size: 0,
|
||||||
|
actionWhen: Date.now(),
|
||||||
|
actionType: "delete",
|
||||||
|
keyType: "folder",
|
||||||
|
renameTo: "",
|
||||||
|
vaultRandomID: vaultRandomID,
|
||||||
|
};
|
||||||
|
await db.fileHistoryTbl.setItem(`${vaultRandomID}\t${k.key}`, k);
|
||||||
}
|
}
|
||||||
await db.fileHistoryTbl.setItem(`${vaultRandomID}\t${k.key}`, k);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -680,3 +736,23 @@ export const clearExpiredLoggerOutputRecords = async (db: InternalDBs) => {
|
|||||||
});
|
});
|
||||||
await Promise.all(ps);
|
await Promise.all(ps);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const upsertLastSuccessSyncByVault = async (
|
||||||
|
db: InternalDBs,
|
||||||
|
vaultRandomID: string,
|
||||||
|
millis: number
|
||||||
|
) => {
|
||||||
|
await db.simpleKVForMiscTbl.setItem(
|
||||||
|
`${vaultRandomID}-lastSuccessSyncMillis`,
|
||||||
|
millis
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getLastSuccessSyncByVault = async (
|
||||||
|
db: InternalDBs,
|
||||||
|
vaultRandomID: string
|
||||||
|
) => {
|
||||||
|
return (await db.simpleKVForMiscTbl.getItem(
|
||||||
|
`${vaultRandomID}-lastSuccessSyncMillis`
|
||||||
|
)) as number;
|
||||||
|
};
|
||||||
|
|||||||
+121
@@ -6,6 +6,9 @@ import {
|
|||||||
addIcon,
|
addIcon,
|
||||||
setIcon,
|
setIcon,
|
||||||
FileSystemAdapter,
|
FileSystemAdapter,
|
||||||
|
Platform,
|
||||||
|
TFile,
|
||||||
|
TFolder,
|
||||||
} from "obsidian";
|
} from "obsidian";
|
||||||
import cloneDeep from "lodash/cloneDeep";
|
import cloneDeep from "lodash/cloneDeep";
|
||||||
import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide";
|
import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide";
|
||||||
@@ -31,6 +34,8 @@ import {
|
|||||||
insertLoggerOutputByVault,
|
insertLoggerOutputByVault,
|
||||||
clearExpiredLoggerOutputRecords,
|
clearExpiredLoggerOutputRecords,
|
||||||
clearExpiredSyncPlanRecords,
|
clearExpiredSyncPlanRecords,
|
||||||
|
upsertLastSuccessSyncByVault,
|
||||||
|
getLastSuccessSyncByVault,
|
||||||
} from "./localdb";
|
} from "./localdb";
|
||||||
import { RemoteClient } from "./remote";
|
import { RemoteClient } from "./remote";
|
||||||
import {
|
import {
|
||||||
@@ -86,6 +91,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
|
|||||||
logToDB: false,
|
logToDB: false,
|
||||||
skipSizeLargerThan: -1,
|
skipSizeLargerThan: -1,
|
||||||
ignorePaths: [],
|
ignorePaths: [],
|
||||||
|
enableStatusBarInfo: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
interface OAuth2Info {
|
interface OAuth2Info {
|
||||||
@@ -126,6 +132,7 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
settings: RemotelySavePluginSettings;
|
settings: RemotelySavePluginSettings;
|
||||||
db: InternalDBs;
|
db: InternalDBs;
|
||||||
syncStatus: SyncStatusType;
|
syncStatus: SyncStatusType;
|
||||||
|
statusBarElement: HTMLSpanElement;
|
||||||
oauth2Info: OAuth2Info;
|
oauth2Info: OAuth2Info;
|
||||||
currLogLevel: string;
|
currLogLevel: string;
|
||||||
currSyncMsg?: string;
|
currSyncMsg?: string;
|
||||||
@@ -357,11 +364,22 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
this.syncStatus = "finish";
|
this.syncStatus = "finish";
|
||||||
this.syncStatus = "idle";
|
this.syncStatus = "idle";
|
||||||
|
|
||||||
|
const lastSuccessSyncMillis = Date.now();
|
||||||
|
await upsertLastSuccessSyncByVault(
|
||||||
|
this.db,
|
||||||
|
this.vaultRandomID,
|
||||||
|
lastSuccessSyncMillis
|
||||||
|
);
|
||||||
|
|
||||||
if (this.syncRibbon !== undefined) {
|
if (this.syncRibbon !== undefined) {
|
||||||
setIcon(this.syncRibbon, iconNameSyncWait);
|
setIcon(this.syncRibbon, iconNameSyncWait);
|
||||||
this.syncRibbon.setAttribute("aria-label", originLabel);
|
this.syncRibbon.setAttribute("aria-label", originLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.statusBarElement !== undefined) {
|
||||||
|
this.updateLastSuccessSyncMsg(lastSuccessSyncMillis);
|
||||||
|
}
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
`${
|
`${
|
||||||
this.manifest.id
|
this.manifest.id
|
||||||
@@ -480,6 +498,31 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function getMethods(obj: any) {
|
||||||
|
var result = [];
|
||||||
|
for (var id in obj) {
|
||||||
|
try {
|
||||||
|
if (typeof obj[id] == "function") {
|
||||||
|
result.push(id + ": " + obj[id].toString());
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
result.push(id + ": inaccessible");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.join("\n");
|
||||||
|
}
|
||||||
|
this.registerEvent(
|
||||||
|
this.app.vault.on("raw" as any, async (fileOrFolder) => {
|
||||||
|
// special track on .obsidian folder
|
||||||
|
const name = `${fileOrFolder}`;
|
||||||
|
if (name.startsWith(this.app.vault.configDir)) {
|
||||||
|
if (!(await this.app.vault.adapter.exists(name))) {
|
||||||
|
await insertDeleteRecordByVault(this.db, name, this.vaultRandomID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
this.registerObsidianProtocolHandler(COMMAND_URI, async (inputParams) => {
|
this.registerObsidianProtocolHandler(COMMAND_URI, async (inputParams) => {
|
||||||
const parsed = importQrCodeUri(inputParams, this.app.vault.getName());
|
const parsed = importQrCodeUri(inputParams, this.app.vault.getName());
|
||||||
if (parsed.status === "error") {
|
if (parsed.status === "error") {
|
||||||
@@ -673,6 +716,25 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
async () => this.syncRun("manual")
|
async () => this.syncRun("manual")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Create Status Bar Item (not supported on mobile)
|
||||||
|
if (!Platform.isMobileApp && this.settings.enableStatusBarInfo === true) {
|
||||||
|
const statusBarItem = this.addStatusBarItem();
|
||||||
|
this.statusBarElement = statusBarItem.createEl("span");
|
||||||
|
this.statusBarElement.setAttribute("aria-label-position", "top");
|
||||||
|
|
||||||
|
this.updateLastSuccessSyncMsg(
|
||||||
|
await getLastSuccessSyncByVault(this.db, this.vaultRandomID)
|
||||||
|
);
|
||||||
|
// update statusbar text every 30 seconds
|
||||||
|
this.registerInterval(
|
||||||
|
window.setInterval(async () => {
|
||||||
|
this.updateLastSuccessSyncMsg(
|
||||||
|
await getLastSuccessSyncByVault(this.db, this.vaultRandomID)
|
||||||
|
);
|
||||||
|
}, 1000 * 30)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.addCommand({
|
this.addCommand({
|
||||||
id: "start-sync",
|
id: "start-sync",
|
||||||
name: t("command_startsync"),
|
name: t("command_startsync"),
|
||||||
@@ -798,6 +860,9 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
if (this.settings.ignorePaths === undefined) {
|
if (this.settings.ignorePaths === undefined) {
|
||||||
this.settings.ignorePaths = [];
|
this.settings.ignorePaths = [];
|
||||||
}
|
}
|
||||||
|
if (this.settings.enableStatusBarInfo === undefined) {
|
||||||
|
this.settings.enableStatusBarInfo = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkIfPresetRulesFollowed() {
|
async checkIfPresetRulesFollowed() {
|
||||||
@@ -970,6 +1035,62 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
this.currSyncMsg = msg;
|
this.currSyncMsg = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateLastSuccessSyncMsg(lastSuccessSyncMillis?: number) {
|
||||||
|
if (this.statusBarElement === undefined) return;
|
||||||
|
|
||||||
|
const t = (x: TransItemType, vars?: any) => {
|
||||||
|
return this.i18n.t(x, vars);
|
||||||
|
};
|
||||||
|
|
||||||
|
let lastSyncMsg = t("statusbar_lastsync_never");
|
||||||
|
let lastSyncLabelMsg = t("statusbar_lastsync_never_label");
|
||||||
|
|
||||||
|
if (lastSuccessSyncMillis !== undefined && lastSuccessSyncMillis > 0) {
|
||||||
|
const deltaTime = Date.now() - lastSuccessSyncMillis;
|
||||||
|
|
||||||
|
// create human readable time
|
||||||
|
const years = Math.floor(deltaTime / 31556952000);
|
||||||
|
const months = Math.floor(deltaTime / 2629746000);
|
||||||
|
const weeks = Math.floor(deltaTime / 604800000);
|
||||||
|
const days = Math.floor(deltaTime / 86400000);
|
||||||
|
const hours = Math.floor(deltaTime / 3600000);
|
||||||
|
const minutes = Math.floor(deltaTime / 60000);
|
||||||
|
let timeText = "";
|
||||||
|
|
||||||
|
if (years > 0) {
|
||||||
|
timeText = t("statusbar_time_years", { time: years });
|
||||||
|
} else if (months > 0) {
|
||||||
|
timeText = t("statusbar_time_months", { time: months });
|
||||||
|
} else if (weeks > 0) {
|
||||||
|
timeText = t("statusbar_time_weeks", { time: weeks });
|
||||||
|
} else if (days > 0) {
|
||||||
|
timeText = t("statusbar_time_days", { time: days });
|
||||||
|
} else if (hours > 0) {
|
||||||
|
timeText = t("statusbar_time_hours", { time: hours });
|
||||||
|
} else if (minutes > 0) {
|
||||||
|
timeText = t("statusbar_time_minutes", { time: minutes });
|
||||||
|
} else {
|
||||||
|
timeText = t("statusbar_time_lessminute");
|
||||||
|
}
|
||||||
|
|
||||||
|
let dateText = new Date(lastSuccessSyncMillis).toLocaleTimeString(
|
||||||
|
navigator.language,
|
||||||
|
{
|
||||||
|
weekday: "long",
|
||||||
|
year: "numeric",
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
lastSyncMsg = t("statusbar_lastsync", { time: timeText });
|
||||||
|
lastSyncLabelMsg = t("statusbar_lastsync_label", { date: dateText });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.statusBarElement.setText(lastSyncMsg);
|
||||||
|
this.statusBarElement.setAttribute("aria-label", lastSyncLabelMsg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Because data.json contains sensitive information,
|
* Because data.json contains sensitive information,
|
||||||
* We usually want to ignore it in the version control.
|
* We usually want to ignore it in the version control.
|
||||||
|
|||||||
+28
@@ -427,3 +427,31 @@ export const statFix = async (vault: Vault, path: string) => {
|
|||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isFolderToSkip = (x: string, more: string[] | undefined) => {
|
||||||
|
let specialFolders = [
|
||||||
|
".git",
|
||||||
|
".github",
|
||||||
|
".gitlab",
|
||||||
|
".svn",
|
||||||
|
"node_modules",
|
||||||
|
".DS_Store",
|
||||||
|
"__MACOSX ",
|
||||||
|
"Icon\r", // https://superuser.com/questions/298785/icon-file-on-os-x-desktop
|
||||||
|
"desktop.ini",
|
||||||
|
"Desktop.ini",
|
||||||
|
"thumbs.db",
|
||||||
|
"Thumbs.db",
|
||||||
|
].concat(more !== undefined ? more : []);
|
||||||
|
for (const iterator of specialFolders) {
|
||||||
|
if (
|
||||||
|
x === iterator ||
|
||||||
|
x === `${iterator}/` ||
|
||||||
|
x.endsWith(`/${iterator}`) ||
|
||||||
|
x.endsWith(`/${iterator}/`)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|||||||
+3
-25
@@ -2,7 +2,7 @@ import { Vault, Stat, ListedFiles } from "obsidian";
|
|||||||
import { Queue } from "@fyears/tsqueue";
|
import { Queue } from "@fyears/tsqueue";
|
||||||
import chunk from "lodash/chunk";
|
import chunk from "lodash/chunk";
|
||||||
import flatten from "lodash/flatten";
|
import flatten from "lodash/flatten";
|
||||||
import { statFix } from "./misc";
|
import { statFix, isFolderToSkip } from "./misc";
|
||||||
|
|
||||||
export interface ObsConfigDirFileType {
|
export interface ObsConfigDirFileType {
|
||||||
key: string;
|
key: string;
|
||||||
@@ -12,28 +12,6 @@ export interface ObsConfigDirFileType {
|
|||||||
type: "folder" | "file";
|
type: "folder" | "file";
|
||||||
}
|
}
|
||||||
|
|
||||||
const isFolderToSkip = (x: string) => {
|
|
||||||
let specialFolders = [
|
|
||||||
".git",
|
|
||||||
".github",
|
|
||||||
".gitlab",
|
|
||||||
".svn",
|
|
||||||
"node_modules",
|
|
||||||
".DS_Store",
|
|
||||||
];
|
|
||||||
for (const iterator of specialFolders) {
|
|
||||||
if (
|
|
||||||
x === iterator ||
|
|
||||||
x === `${iterator}/` ||
|
|
||||||
x.endsWith(`/${iterator}`) ||
|
|
||||||
x.endsWith(`/${iterator}/`)
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const isPluginDirItself = (x: string, pluginId: string) => {
|
const isPluginDirItself = (x: string, pluginId: string) => {
|
||||||
return (
|
return (
|
||||||
x === pluginId ||
|
x === pluginId ||
|
||||||
@@ -106,7 +84,7 @@ export const listFilesInObsFolder = async (
|
|||||||
const isInsideSelfPlugin = isPluginDirItself(iter.itself.key, pluginId);
|
const isInsideSelfPlugin = isPluginDirItself(iter.itself.key, pluginId);
|
||||||
if (iter.children !== undefined) {
|
if (iter.children !== undefined) {
|
||||||
for (const iter2 of iter.children.folders) {
|
for (const iter2 of iter.children.folders) {
|
||||||
if (isFolderToSkip(iter2)) {
|
if (isFolderToSkip(iter2, ["workspace", "workspace.json"])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isInsideSelfPlugin && !isLikelyPluginSubFiles(iter2)) {
|
if (isInsideSelfPlugin && !isLikelyPluginSubFiles(iter2)) {
|
||||||
@@ -116,7 +94,7 @@ export const listFilesInObsFolder = async (
|
|||||||
q.push(iter2);
|
q.push(iter2);
|
||||||
}
|
}
|
||||||
for (const iter2 of iter.children.files) {
|
for (const iter2 of iter.children.files) {
|
||||||
if (isFolderToSkip(iter2)) {
|
if (isFolderToSkip(iter2, ["workspace", "workspace.json"])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (isInsideSelfPlugin && !isLikelyPluginSubFiles(iter2)) {
|
if (isInsideSelfPlugin && !isLikelyPluginSubFiles(iter2)) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import {
|
|||||||
clearAllLoggerOutputRecords,
|
clearAllLoggerOutputRecords,
|
||||||
insertLoggerOutputByVault,
|
insertLoggerOutputByVault,
|
||||||
clearExpiredLoggerOutputRecords,
|
clearExpiredLoggerOutputRecords,
|
||||||
|
upsertLastSuccessSyncByVault,
|
||||||
} from "./localdb";
|
} from "./localdb";
|
||||||
import type RemotelySavePlugin from "./main"; // unavoidable
|
import type RemotelySavePlugin from "./main"; // unavoidable
|
||||||
import { RemoteClient } from "./remote";
|
import { RemoteClient } from "./remote";
|
||||||
@@ -1596,6 +1597,39 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// custom status bar items is not supported on mobile
|
||||||
|
if (!Platform.isMobileApp) {
|
||||||
|
new Setting(basicDiv)
|
||||||
|
.setName(t("settings_enablestatusbar_info"))
|
||||||
|
.setDesc(t("settings_enablestatusbar_info_desc"))
|
||||||
|
.addToggle((toggle) => {
|
||||||
|
toggle
|
||||||
|
.setValue(this.plugin.settings.enableStatusBarInfo)
|
||||||
|
.onChange(async (val) => {
|
||||||
|
this.plugin.settings.enableStatusBarInfo = val;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
new Notice(t("settings_enablestatusbar_reloadrequired_notice"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
new Setting(basicDiv)
|
||||||
|
.setName(t("settings_resetstatusbar_time"))
|
||||||
|
.setDesc(t("settings_resetstatusbar_time_desc"))
|
||||||
|
.addButton((button) => {
|
||||||
|
button.setButtonText(t("settings_resetstatusbar_button"));
|
||||||
|
button.onClick(async () => {
|
||||||
|
// reset last sync time
|
||||||
|
await upsertLastSuccessSyncByVault(
|
||||||
|
this.plugin.db,
|
||||||
|
this.plugin.vaultRandomID,
|
||||||
|
-1
|
||||||
|
);
|
||||||
|
this.plugin.updateLastSuccessSyncMsg(-1);
|
||||||
|
new Notice(t("settings_resetstatusbar_notice"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
new Setting(basicDiv)
|
new Setting(basicDiv)
|
||||||
.setName(t("settings_ignorepaths"))
|
.setName(t("settings_ignorepaths"))
|
||||||
.setDesc(t("settings_ignorepaths_desc"))
|
.setDesc(t("settings_ignorepaths_desc"))
|
||||||
@@ -1609,6 +1643,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
});
|
});
|
||||||
textArea.inputEl.rows = 10;
|
textArea.inputEl.rows = 10;
|
||||||
|
textArea.inputEl.cols = 30;
|
||||||
|
|
||||||
textArea.inputEl.addClass("ignorepaths-textarea");
|
textArea.inputEl.addClass("ignorepaths-textarea");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import {
|
|||||||
atWhichLevel,
|
atWhichLevel,
|
||||||
unixTimeToStr,
|
unixTimeToStr,
|
||||||
statFix,
|
statFix,
|
||||||
|
isFolderToSkip,
|
||||||
} from "./misc";
|
} from "./misc";
|
||||||
import { RemoteClient } from "./remote";
|
import { RemoteClient } from "./remote";
|
||||||
import {
|
import {
|
||||||
@@ -307,6 +308,10 @@ const isSkipItem = (
|
|||||||
if (syncConfigDir && isInsideObsFolder(key, configDir)) {
|
if (syncConfigDir && isInsideObsFolder(key, configDir)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (isFolderToSkip(key, [])) {
|
||||||
|
// some special dirs and files are always skipped
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
isHiddenPath(key, true, false) ||
|
isHiddenPath(key, true, false) ||
|
||||||
(!syncUnderscoreItems && isHiddenPath(key, false, true)) ||
|
(!syncUnderscoreItems && isHiddenPath(key, false, true)) ||
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
|
|||||||
password: "password",
|
password: "password",
|
||||||
serviceType: "s3",
|
serviceType: "s3",
|
||||||
currLogLevel: "info",
|
currLogLevel: "info",
|
||||||
|
ignorePaths: ["somefoldertoignore"],
|
||||||
|
enableStatusBarInfo: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("Config Persist tests", () => {
|
describe("Config Persist tests", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user