diff --git a/src/baseTypes.ts b/src/baseTypes.ts index dd8719a..dae6467 100644 --- a/src/baseTypes.ts +++ b/src/baseTypes.ts @@ -26,13 +26,15 @@ export interface DropboxConfig { } export type WebdavAuthType = "digest" | "basic"; +export type WebdavDepthType = "auto_unknown" | "auto_1" | "auto_infinity" | "manual_1" | "manual_infinity"; export interface WebdavConfig { address: string; username: string; password: string; authType: WebdavAuthType; - manualRecursive: boolean; + manualRecursive: boolean; // deprecated in 0.3.6, use depth + depth?: WebdavDepthType; } export interface OnedriveConfig { diff --git a/src/main.ts b/src/main.ts index 02c1575..244a7a5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -564,6 +564,9 @@ export default class RemotelySavePlugin extends Plugin { if (this.settings.webdav.manualRecursive === undefined) { this.settings.webdav.manualRecursive = false; } + if (this.settings.webdav.depth === undefined) { + this.settings.webdav.depth = "auto_unknown"; + } } async saveSettings() { diff --git a/src/settings.ts b/src/settings.ts index ffccfc1..c58245b 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -11,6 +11,7 @@ import { API_VER_REQURL, SUPPORTED_SERVICES_TYPE, WebdavAuthType, + WebdavDepthType, } from "./baseTypes"; import { exportVaultSyncPlansToFiles } from "./debugMode"; import { exportQrCodeUri } from "./importExport"; @@ -1073,25 +1074,35 @@ export class RemotelySaveSettingTab extends PluginSettingTab { }); new Setting(webdavDiv) - .setName("server supports infinity propfind or not") + .setName("depth header sent to servers") .setDesc( - "The plugin needs to get all files and folders recursively using probfind. If your webdav server only supports depth='1' (such as NGINX), you need to adjust the setting here, then the plugin consumes more network requests, but better than not working." + "Webdav servers should be configured to allow requests with header Depth being '1' or 'infinity'. The plugin needs to know this info. If you are not sure what's this, choose \"auto\"." ) .addDropdown((dropdown) => { - dropdown.addOption("infinity", "supports depth='infinity'"); - dropdown.addOption("1", "only supports depth='1'"); + dropdown.addOption("auto", "auto detect"); + dropdown.addOption("manual_1", "only supports depth='1'"); + dropdown.addOption("manual_infinity", "only supports depth='infinity'"); - type Depth = "1" | "infinity"; + let initVal = "auto"; + const autoOptions: Set = new Set(["auto_unknown", "auto_1", "auto_infinity"]); + if (autoOptions.has(this.plugin.settings.webdav.depth)) { + initVal = "auto"; + } else { + initVal = this.plugin.settings.webdav.depth || "auto"; + } + + type DepthOption = "auto" | "manual_1" | "manual_infinity" dropdown - .setValue( - this.plugin.settings.webdav.manualRecursive === false - ? "infinity" - : "1" - ) - .onChange(async (val: Depth) => { - if (val === "1") { + .setValue( initVal) + .onChange(async (val: DepthOption) => { + if (val === "auto") { + this.plugin.settings.webdav.depth = "auto_unknown"; + this.plugin.settings.webdav.manualRecursive = false; + } else if (val === "manual_1") { + this.plugin.settings.webdav.depth = "manual_1"; this.plugin.settings.webdav.manualRecursive = true; - } else if (val === "infinity") { + } else if (val === "manual_infinity") { + this.plugin.settings.webdav.depth = "manual_infinity"; this.plugin.settings.webdav.manualRecursive = false; } await this.plugin.saveSettings();