add allow list mode
This commit is contained in:
parent
e9b9cd97ac
commit
b2dea5a351
@ -134,13 +134,44 @@ const isSkipItemByName = (
|
||||
syncBookmarks: boolean,
|
||||
syncUnderscoreItems: boolean,
|
||||
configDir: string,
|
||||
ignorePaths: string[]
|
||||
ignorePaths: string[],
|
||||
onlyAllowPaths: string[]
|
||||
) => {
|
||||
if (key === undefined) {
|
||||
throw Error(`isSkipItemByName meets undefinded key!`);
|
||||
}
|
||||
|
||||
let enableAllowMode = false;
|
||||
let isInAllowList = false;
|
||||
if (onlyAllowPaths !== undefined && onlyAllowPaths.length > 0) {
|
||||
for (const r of onlyAllowPaths) {
|
||||
if (r.trim() === "") {
|
||||
// ignore empty lines
|
||||
continue;
|
||||
}
|
||||
enableAllowMode = true; // we really want to check the allow list
|
||||
|
||||
if (XRegExp(r, "A").test(key)) {
|
||||
isInAllowList = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// we want to determine "is skippable or not".
|
||||
// if the key meets the allow list,
|
||||
// it may or may not be skippable,
|
||||
// and is deferred to next checking steps
|
||||
// if the key doesn't meet the allow list,
|
||||
// it must be skippable.
|
||||
if (enableAllowMode && !isInAllowList) {
|
||||
return true; // must be skippable
|
||||
}
|
||||
|
||||
if (ignorePaths !== undefined && ignorePaths.length > 0) {
|
||||
for (const r of ignorePaths) {
|
||||
if (r.trim() === "") {
|
||||
// ignore empty lines
|
||||
continue;
|
||||
}
|
||||
if (XRegExp(r, "A").test(key)) {
|
||||
return true;
|
||||
}
|
||||
@ -179,6 +210,7 @@ const ensembleMixedEnties = async (
|
||||
configDir: string,
|
||||
syncUnderscoreItems: boolean,
|
||||
ignorePaths: string[],
|
||||
onlyAllowPaths: string[],
|
||||
fsEncrypt: FakeFsEncrypt,
|
||||
serviceType: SUPPORTED_SERVICES_TYPE,
|
||||
|
||||
@ -206,7 +238,8 @@ const ensembleMixedEnties = async (
|
||||
syncBookmarks,
|
||||
syncUnderscoreItems,
|
||||
configDir,
|
||||
ignorePaths
|
||||
ignorePaths,
|
||||
onlyAllowPaths
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
@ -246,7 +279,8 @@ const ensembleMixedEnties = async (
|
||||
syncBookmarks,
|
||||
syncUnderscoreItems,
|
||||
configDir,
|
||||
ignorePaths
|
||||
ignorePaths,
|
||||
onlyAllowPaths
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
@ -282,7 +316,8 @@ const ensembleMixedEnties = async (
|
||||
syncBookmarks,
|
||||
syncUnderscoreItems,
|
||||
configDir,
|
||||
ignorePaths
|
||||
ignorePaths,
|
||||
onlyAllowPaths
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
@ -1752,6 +1787,7 @@ export async function syncer(
|
||||
configDir,
|
||||
settings.syncUnderscoreItems ?? false,
|
||||
settings.ignorePaths ?? [],
|
||||
settings.onlyAllowPaths ?? [],
|
||||
fsEncrypt,
|
||||
settings.serviceType,
|
||||
profiler
|
||||
|
||||
@ -173,6 +173,7 @@ export interface RemotelySavePluginSettings {
|
||||
agreeToUseSyncV3?: boolean;
|
||||
skipSizeLargerThan?: number;
|
||||
ignorePaths?: string[];
|
||||
onlyAllowPaths?: string[];
|
||||
enableStatusBarInfo?: boolean;
|
||||
deleteToWhere?: "system" | "obsidian";
|
||||
conflictAction?: ConflictActionType;
|
||||
|
||||
@ -149,7 +149,9 @@
|
||||
"settings_skiplargefiles_desc": "Skip files with sizes larger than the threshold. Here 1 MB = 10^6 bytes.",
|
||||
"settings_skiplargefiles_notset": "(not set)",
|
||||
"settings_ignorepaths": "Regex Of Paths To Ignore",
|
||||
"settings_ignorepaths_desc": "Regex of paths of folders or files to ignore. One regex per line. The path is relative to the vault root without leading slash.",
|
||||
"settings_ignorepaths_desc": "Regex of paths of folders or files to ignore. One regex per line. The path is relative to the vault root without leading slash. Non-empty allow paths and non-empty ignore paths are effective together.",
|
||||
"settings_onlyallowpaths": "Regex Of Paths To Allow",
|
||||
"settings_onlyallowpaths_desc": "Regex of paths of folders or files to allow to sync. One regex per line. The path is relative to the vault root without leading slash. If this setting is not empty, all paths you want to sync including config dirs must be explicitly set here. Non-empty allow paths and non-empty ignore paths are effective together.",
|
||||
"settings_enablestatusbar_info": "Show Last Successful Sync In Status Bar",
|
||||
"settings_enablestatusbar_info_desc": "Show the time of the last successful sync in the status bar.",
|
||||
"settings_enablestatusbar_reloadrequired_notice": "Reload the plugin for the changes to take effect.",
|
||||
|
||||
@ -148,7 +148,9 @@
|
||||
"settings_skiplargefiles_desc": "跳过大于某一个阈值的文件。这里 1 MB = 10^6 bytes。",
|
||||
"settings_skiplargefiles_notset": "(不设置)",
|
||||
"settings_ignorepaths": "忽略的文件或文件夹的正则表达式",
|
||||
"settings_ignorepaths_desc": "忽略的文件或文件夹的正则表达式。每行一条。路径是相对于库(Vault)根目录的,没有前置 / 符号。",
|
||||
"settings_ignorepaths_desc": "忽略的文件或文件夹的正则表达式。每行一条。路径是相对于库(Vault)根目录的,没有前置 / 符号。非空的忽略列表和非空的允许列表会一起生效。",
|
||||
"settings_onlyallowpaths": "允许同步的文件或文件夹的正则表达式",
|
||||
"settings_onlyallowpaths_desc": "允许同步的文件或文件夹的正则表达式。每行一条。路径是相对于库(Vault)根目录的,没有前置 / 符号。如果这个设置非空,那么所有您想同步的路径(包括隐藏的设置文件夹)都要明确地列出到这里。非空的忽略列表和非空的允许列表会一起生效。",
|
||||
"settings_enablestatusbar_info": "在状态栏显示上一次成功的同步",
|
||||
"settings_enablestatusbar_info_desc": "在状态栏显示上一次成功的同步的时间。",
|
||||
"settings_enablestatusbar_reloadrequired_notice": "需要重新载入此插件才生效。",
|
||||
|
||||
@ -147,7 +147,9 @@
|
||||
"settings_skiplargefiles_desc": "跳過大於某一個閾值的檔案。這裡 1 MB = 10^6 bytes。",
|
||||
"settings_skiplargefiles_notset": "(不設定)",
|
||||
"settings_ignorepaths": "忽略的檔案或資料夾的正則表示式",
|
||||
"settings_ignorepaths_desc": "忽略的檔案或資料夾的正則表示式。每行一條。路徑是相對於庫(Vault)根目錄的,沒有前置 / 符號。",
|
||||
"settings_ignorepaths_desc": "忽略的檔案或資料夾的正則表示式。每行一條。路徑是相對於庫(Vault)根目錄的,沒有前置 / 符號。非空的忽略列表和非空的允許列表會一起生效。",
|
||||
"settings_onlyallowpaths": "允許同步的檔案或資料夾的正則表示式",
|
||||
"settings_onlyallowpaths_desc": "允許同步的檔案或資料夾的正則表示式。每行一條。路徑是相對於庫(Vault)根目錄的,沒有前置 / 符號。如果這個設定非空,那麼所有您想同步的路徑(包括隱藏的設定資料夾)都要明確地列出到這裡。非空的忽略列表和非空的允許列表會一起生效。",
|
||||
"settings_enablestatusbar_info": "在狀態列顯示上一次成功的同步",
|
||||
"settings_enablestatusbar_info_desc": "在狀態列顯示上一次成功的同步的時間。",
|
||||
"settings_enablestatusbar_reloadrequired_notice": "需要重新載入此外掛才生效。",
|
||||
|
||||
@ -141,6 +141,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
|
||||
logToDB: false,
|
||||
skipSizeLargerThan: -1,
|
||||
ignorePaths: [],
|
||||
onlyAllowPaths: [],
|
||||
enableStatusBarInfo: true,
|
||||
deleteToWhere: "system",
|
||||
agreeToUseSyncV3: false,
|
||||
@ -1409,6 +1410,9 @@ export default class RemotelySavePlugin extends Plugin {
|
||||
if (this.settings.ignorePaths === undefined) {
|
||||
this.settings.ignorePaths = [];
|
||||
}
|
||||
if (this.settings.onlyAllowPaths === undefined) {
|
||||
this.settings.onlyAllowPaths = [];
|
||||
}
|
||||
if (this.settings.enableStatusBarInfo === undefined) {
|
||||
this.settings.enableStatusBarInfo = true;
|
||||
}
|
||||
|
||||
@ -2247,6 +2247,27 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
||||
textArea.inputEl.addClass("ignorepaths-textarea");
|
||||
});
|
||||
|
||||
new Setting(basicDiv)
|
||||
.setName(t("settings_onlyallowpaths"))
|
||||
.setDesc(t("settings_onlyallowpaths_desc"))
|
||||
.setClass("onlyallowpaths-settings")
|
||||
|
||||
.addTextArea((textArea) => {
|
||||
textArea
|
||||
.setValue(`${(this.plugin.settings.onlyAllowPaths ?? []).join("\n")}`)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.onlyAllowPaths = value
|
||||
.trim()
|
||||
.split("\n")
|
||||
.filter((x) => x.trim() !== "");
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
textArea.inputEl.rows = 10;
|
||||
textArea.inputEl.cols = 30;
|
||||
|
||||
textArea.inputEl.addClass("onlyallowpaths-textarea");
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// below for advanced settings
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
@ -214,6 +214,10 @@
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.onlyallowpaths-textarea {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.logtohttpserver-warning {
|
||||
color: red;
|
||||
font-weight: bolder;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user