From 6a651b844f4ebaa09541d673260fc3a195f03bb9 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Thu, 4 Jan 2024 00:26:02 +0800 Subject: [PATCH] ignore paths by regexgit add . --- README.md | 1 + src/main.ts | 5 ++++- src/settings.ts | 7 +++++- src/sync.ts | 59 +++++++++++++++++++++++++++++++++++++++++++------ styles.css | 4 ++++ 5 files changed, 67 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1f16074..b1160d8 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ This is yet another unofficial sync plugin for Obsidian. If you like it or find - **[End-to-end encryption](./docs/encryption.md) supported.** Files would be encrypted using openssl format before being sent to the cloud **if** user specify a password. - **Scheduled auto sync supported.** You can also manually trigger the sync using sidebar ribbon, or using the command from the command palette (or even bind the hot key combination to the command then press the hot key combination). - **[Minimal Intrusive](./docs/minimal_intrusive_design.md).** +- **Skip Large files and skip paths by custom regex conditions! - **Fully open source under [Apache-2.0 License](./LICENSE).** - **[Sync Algorithm open](./docs/sync_algorithm_v2.md) for discussion.** diff --git a/src/main.ts b/src/main.ts index 7b60f08..b8ec457 100644 --- a/src/main.ts +++ b/src/main.ts @@ -85,7 +85,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = { lang: "auto", logToDB: false, skipSizeLargerThan: -1, - ignorePaths: [".obsidian/workspace.json", ".obsidian/workspace-mobile.json", ".obsidian/community-plugins.json"], + ignorePaths: [], }; interface OAuth2Info { @@ -795,6 +795,9 @@ export default class RemotelySavePlugin extends Plugin { if (this.settings.s3.forcePathStyle === undefined) { this.settings.s3.forcePathStyle = false; } + if (this.settings.ignorePaths === undefined) { + this.settings.ignorePaths = []; + } } async checkIfPresetRulesFollowed() { diff --git a/src/settings.ts b/src/settings.ts index 8047eb4..13c8ed4 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1599,13 +1599,18 @@ export class RemotelySaveSettingTab extends PluginSettingTab { new Setting(basicDiv) .setName(t("settings_ignorepaths")) .setDesc(t("settings_ignorepaths_desc")) + .setClass("ignorepaths-settings") + .addTextArea((textArea) => { textArea .setValue(`${this.plugin.settings.ignorePaths.join("\n")}`) .onChange(async (value) => { - this.plugin.settings.ignorePaths = value.split("\n"); + this.plugin.settings.ignorePaths = value.trim().split("\n"); await this.plugin.saveSettings(); }); + textArea.inputEl.rows = 10; + + textArea.inputEl.addClass("ignorepaths-textarea"); }); ////////////////////////////////////////////////// diff --git a/src/sync.ts b/src/sync.ts index f35a9b0..5fdd1d6 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -7,6 +7,7 @@ import { } from "obsidian"; import AggregateError from "aggregate-error"; import PQueue from "p-queue"; +import XRegExp from "xregexp"; import type { RemoteItem, SyncTriggerSourceType, @@ -296,8 +297,12 @@ const isSkipItem = ( configDir: string, ignorePaths: string[] ) => { - if (ignorePaths.includes(key)) { - return true; + if (ignorePaths !== undefined && ignorePaths.length > 0) { + for (const r of ignorePaths) { + if (XRegExp(r, "A").test(key)) { + return true; + } + } } if (syncConfigDir && isInsideObsFolder(key, configDir)) { return false; @@ -327,7 +332,15 @@ const ensembleMixedStates = async ( for (const r of remoteStates) { const key = r.key; - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + if ( + isSkipItem( + key, + syncConfigDir, + syncUnderscoreItems, + configDir, + ignorePaths + ) + ) { continue; } results[key] = r; @@ -366,7 +379,15 @@ const ensembleMixedStates = async ( throw Error(`unexpected ${entry}`); } - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + if ( + isSkipItem( + key, + syncConfigDir, + syncUnderscoreItems, + configDir, + ignorePaths + ) + ) { continue; } @@ -400,7 +421,15 @@ const ensembleMixedStates = async ( password === "" ? undefined : getSizeFromOrigToEnc(entry.size), }; - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + if ( + isSkipItem( + key, + syncConfigDir, + syncUnderscoreItems, + configDir, + ignorePaths + ) + ) { continue; } @@ -426,7 +455,15 @@ const ensembleMixedStates = async ( deltimeRemoteFmt: unixTimeToStr(entry.actionWhen), } as FileOrFolderMixedState; - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + if ( + isSkipItem( + key, + syncConfigDir, + syncUnderscoreItems, + configDir, + ignorePaths + ) + ) { continue; } @@ -454,7 +491,15 @@ const ensembleMixedStates = async ( throw Error(`unexpected ${entry}`); } - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + if ( + isSkipItem( + key, + syncConfigDir, + syncUnderscoreItems, + configDir, + ignorePaths + ) + ) { continue; } diff --git a/styles.css b/styles.css index 75f5978..940a670 100644 --- a/styles.css +++ b/styles.css @@ -61,3 +61,7 @@ width: 350px; height: 350px; } + +.ignorepaths-textarea { + font-family: monospace; +}