ignore paths by regexgit add .

This commit is contained in:
fyears 2024-01-04 00:26:02 +08:00
parent 9e4d3826fd
commit 6a651b844f
5 changed files with 67 additions and 9 deletions

View File

@ -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. - **[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!
- **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.**

View File

@ -85,7 +85,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
lang: "auto", lang: "auto",
logToDB: false, logToDB: false,
skipSizeLargerThan: -1, skipSizeLargerThan: -1,
ignorePaths: [".obsidian/workspace.json", ".obsidian/workspace-mobile.json", ".obsidian/community-plugins.json"], ignorePaths: [],
}; };
interface OAuth2Info { interface OAuth2Info {
@ -795,6 +795,9 @@ export default class RemotelySavePlugin extends Plugin {
if (this.settings.s3.forcePathStyle === undefined) { if (this.settings.s3.forcePathStyle === undefined) {
this.settings.s3.forcePathStyle = false; this.settings.s3.forcePathStyle = false;
} }
if (this.settings.ignorePaths === undefined) {
this.settings.ignorePaths = [];
}
} }
async checkIfPresetRulesFollowed() { async checkIfPresetRulesFollowed() {

View File

@ -1599,13 +1599,18 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
new Setting(basicDiv) new Setting(basicDiv)
.setName(t("settings_ignorepaths")) .setName(t("settings_ignorepaths"))
.setDesc(t("settings_ignorepaths_desc")) .setDesc(t("settings_ignorepaths_desc"))
.setClass("ignorepaths-settings")
.addTextArea((textArea) => { .addTextArea((textArea) => {
textArea textArea
.setValue(`${this.plugin.settings.ignorePaths.join("\n")}`) .setValue(`${this.plugin.settings.ignorePaths.join("\n")}`)
.onChange(async (value) => { .onChange(async (value) => {
this.plugin.settings.ignorePaths = value.split("\n"); this.plugin.settings.ignorePaths = value.trim().split("\n");
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}); });
textArea.inputEl.rows = 10;
textArea.inputEl.addClass("ignorepaths-textarea");
}); });
////////////////////////////////////////////////// //////////////////////////////////////////////////

View File

@ -7,6 +7,7 @@ import {
} from "obsidian"; } from "obsidian";
import AggregateError from "aggregate-error"; import AggregateError from "aggregate-error";
import PQueue from "p-queue"; import PQueue from "p-queue";
import XRegExp from "xregexp";
import type { import type {
RemoteItem, RemoteItem,
SyncTriggerSourceType, SyncTriggerSourceType,
@ -296,8 +297,12 @@ const isSkipItem = (
configDir: string, configDir: string,
ignorePaths: string[] ignorePaths: string[]
) => { ) => {
if (ignorePaths.includes(key)) { if (ignorePaths !== undefined && ignorePaths.length > 0) {
return true; for (const r of ignorePaths) {
if (XRegExp(r, "A").test(key)) {
return true;
}
}
} }
if (syncConfigDir && isInsideObsFolder(key, configDir)) { if (syncConfigDir && isInsideObsFolder(key, configDir)) {
return false; return false;
@ -327,7 +332,15 @@ const ensembleMixedStates = async (
for (const r of remoteStates) { for (const r of remoteStates) {
const key = r.key; const key = r.key;
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { if (
isSkipItem(
key,
syncConfigDir,
syncUnderscoreItems,
configDir,
ignorePaths
)
) {
continue; continue;
} }
results[key] = r; results[key] = r;
@ -366,7 +379,15 @@ const ensembleMixedStates = async (
throw Error(`unexpected ${entry}`); throw Error(`unexpected ${entry}`);
} }
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { if (
isSkipItem(
key,
syncConfigDir,
syncUnderscoreItems,
configDir,
ignorePaths
)
) {
continue; continue;
} }
@ -400,7 +421,15 @@ const ensembleMixedStates = async (
password === "" ? undefined : getSizeFromOrigToEnc(entry.size), password === "" ? undefined : getSizeFromOrigToEnc(entry.size),
}; };
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { if (
isSkipItem(
key,
syncConfigDir,
syncUnderscoreItems,
configDir,
ignorePaths
)
) {
continue; continue;
} }
@ -426,7 +455,15 @@ const ensembleMixedStates = async (
deltimeRemoteFmt: unixTimeToStr(entry.actionWhen), deltimeRemoteFmt: unixTimeToStr(entry.actionWhen),
} as FileOrFolderMixedState; } as FileOrFolderMixedState;
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { if (
isSkipItem(
key,
syncConfigDir,
syncUnderscoreItems,
configDir,
ignorePaths
)
) {
continue; continue;
} }
@ -454,7 +491,15 @@ const ensembleMixedStates = async (
throw Error(`unexpected ${entry}`); throw Error(`unexpected ${entry}`);
} }
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { if (
isSkipItem(
key,
syncConfigDir,
syncUnderscoreItems,
configDir,
ignorePaths
)
) {
continue; continue;
} }

View File

@ -61,3 +61,7 @@
width: 350px; width: 350px;
height: 350px; height: 350px;
} }
.ignorepaths-textarea {
font-family: monospace;
}