diff --git a/src/baseTypes.ts b/src/baseTypes.ts index 7d540d1..318f750 100644 --- a/src/baseTypes.ts +++ b/src/baseTypes.ts @@ -86,6 +86,7 @@ export interface RemotelySavePluginSettings { lang?: LangTypeAndAuto; logToDB?: boolean; skipSizeLargerThan?: number; + ignorePaths?: string[]; /** * @deprecated diff --git a/src/langs b/src/langs index 42eab5d..0b961f4 160000 --- a/src/langs +++ b/src/langs @@ -1 +1 @@ -Subproject commit 42eab5d544961f4c7830c63ba9559375437340c0 +Subproject commit 0b961f4865d11e3c78d74776b8d0eb2d642aa505 diff --git a/src/main.ts b/src/main.ts index bc9de28..7b60f08 100644 --- a/src/main.ts +++ b/src/main.ts @@ -85,6 +85,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = { lang: "auto", logToDB: false, skipSizeLargerThan: -1, + ignorePaths: [".obsidian/workspace.json", ".obsidian/workspace-mobile.json", ".obsidian/community-plugins.json"], }; interface OAuth2Info { @@ -296,6 +297,7 @@ export default class RemotelySavePlugin extends Plugin { this.app.vault.configDir, this.settings.syncUnderscoreItems, this.settings.skipSizeLargerThan, + this.settings.ignorePaths, this.settings.password ); log.info(plan.mixedStates); // for debugging diff --git a/src/settings.ts b/src/settings.ts index e851c9e..8047eb4 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1596,6 +1596,18 @@ export class RemotelySaveSettingTab extends PluginSettingTab { }); }); + new Setting(basicDiv) + .setName(t("settings_ignorepaths")) + .setDesc(t("settings_ignorepaths_desc")) + .addTextArea((textArea) => { + textArea + .setValue(`${this.plugin.settings.ignorePaths.join("\n")}`) + .onChange(async (value) => { + this.plugin.settings.ignorePaths = value.split("\n"); + await this.plugin.saveSettings(); + }); + }); + ////////////////////////////////////////////////// // below for advanced settings ////////////////////////////////////////////////// diff --git a/src/sync.ts b/src/sync.ts index 61e6fca..f00b200 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -293,8 +293,12 @@ const isSkipItem = ( key: string, syncConfigDir: boolean, syncUnderscoreItems: boolean, - configDir: string + configDir: string, + ignorePaths: string[] ) => { + if (ignorePaths.includes(key)) { + return true; + } if (syncConfigDir && isInsideObsFolder(key, configDir)) { return false; } @@ -315,6 +319,7 @@ const ensembleMixedStates = async ( syncConfigDir: boolean, configDir: string, syncUnderscoreItems: boolean, + ignorePaths: string[], password: string ) => { const results = {} as Record; @@ -322,7 +327,7 @@ const ensembleMixedStates = async ( for (const r of remoteStates) { const key = r.key; - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) { + if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { continue; } results[key] = r; @@ -361,7 +366,7 @@ const ensembleMixedStates = async ( throw Error(`unexpected ${entry}`); } - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) { + if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { continue; } @@ -395,6 +400,10 @@ const ensembleMixedStates = async ( password === "" ? undefined : getSizeFromOrigToEnc(entry.size), }; + if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { + continue; + } + if (results.hasOwnProperty(key)) { results[key].key = r.key; results[key].existLocal = r.existLocal; @@ -417,7 +426,7 @@ const ensembleMixedStates = async ( deltimeRemoteFmt: unixTimeToStr(entry.actionWhen), } as FileOrFolderMixedState; - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) { + if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { continue; } @@ -445,7 +454,7 @@ const ensembleMixedStates = async ( throw Error(`unexpected ${entry}`); } - if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir)) { + if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) { continue; } @@ -967,6 +976,7 @@ export const getSyncPlan = async ( configDir: string, syncUnderscoreItems: boolean, skipSizeLargerThan: number, + ignorePaths: string[], password: string = "" ) => { const mixedStates = await ensembleMixedStates( @@ -978,8 +988,10 @@ export const getSyncPlan = async ( syncConfigDir, configDir, syncUnderscoreItems, + ignorePaths, password ); + console.table(mixedStates) const sortedKeys = Object.keys(mixedStates).sort( (k1, k2) => k2.length - k1.length