This commit is contained in:
fyears 2024-04-27 23:10:36 +08:00
parent 5340e38eac
commit 61a3fab219
17 changed files with 528 additions and 22 deletions

View File

@ -108,6 +108,13 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a
- Password-based end-to-end encryption is also supported. But please be aware that **the vault name itself is not encrypted**.
- If you want to sync the files across multiple devices, **your vault name should be the same** while using default settings.
### Webdis
- Tutorials:
- [Webdis](./docs/remote_services/webdis/README.md)
- Mostly experimental.
- You have to setup and protect your web server by yourself.
## Scheduled Auto Sync
- You can configure auto syncing every N minutes in settings.

View File

@ -0,0 +1,35 @@
# Webdis
## Links
- Webdis: <https://github.com/nicolasff/webdis>
- Redis®: <https://redis.io/>
## Explanation and Background
I like the Redis® software very much, and would like to experiment using it as a "file storage". It seems to be nature by using path as the key and the content as the value (Sort of..., see below).
However, Redis® works by using TCP connections, and browser js cannot establish raw TCP connections. We need a HTTP gateway, to provide the HTTP api. Wedis seems to be the most famous open source one.
And of course, this method should work for Redis® alternatives: Valkey, Redict, KeyDB, Dragonfly, Garnet, ...
## Disclaimer
This app is NOT an official Redis® Ltd / Redis® OSS / Webdis product. Redis is a registered trademark of Redis Ltd.
**Never expose your Redis® or Webdis to public without security protection!!!** You are response for protecting your server.
## Usage
1. Install Redis®.
2. Install Webdis.
3. In `webdis.json`, configure the ACL for using password and username, and / or ip filters. **Never expose your Redis® or Webdis to public without security protection!!!**.
4. Install and configure reverse proxy, firewall, https, etc. (You have to configure HTTPS correctly if you want to use it on iOS)
5. In Remotely Save settings, enter your server address, username, password, and adjust the "base dir". Check connection.
6. Sync!
7. Serveral keys and values will be generated in your Redis® database:
```
rs:fs:v1:${encodeURIComponent(vaultName+'/'+folderStructure+'/'+fileName)}:meta # you can HGETALL it
rs:fs:v1:${encodeURIComponent(vaultName+'/'+folderStructure+'/'+fileName)}:content # you can GET it
```

View File

@ -3,17 +3,22 @@
* To avoid circular dependency.
*/
import { Platform, requireApiVersion } from "obsidian";
import type { LangType, LangTypeAndAuto } from "./i18n";
export const DEFAULT_CONTENT_TYPE = "application/octet-stream";
export type SUPPORTED_SERVICES_TYPE = "s3" | "webdav" | "dropbox" | "onedrive";
export type SUPPORTED_SERVICES_TYPE =
| "s3"
| "webdav"
| "dropbox"
| "onedrive"
| "webdis";
export type SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR =
| "webdav"
| "dropbox"
| "onedrive";
| "onedrive"
| "webdis";
export interface S3Config {
s3Endpoint: string;
@ -86,6 +91,13 @@ export interface OnedriveConfig {
remoteBaseDir?: string;
}
export interface WebdisConfig {
address: string;
username?: string;
password?: string;
remoteBaseDir?: string;
}
export type SyncDirectionType =
| "bidirectional"
| "incremental_pull_only"
@ -100,6 +112,7 @@ export interface RemotelySavePluginSettings {
webdav: WebdavConfig;
dropbox: DropboxConfig;
onedrive: OnedriveConfig;
webdis: WebdisConfig;
password: string;
serviceType: SUPPORTED_SERVICES_TYPE;
currLogLevel?: string;
@ -261,15 +274,6 @@ export interface FileOrFolderMixedState {
deltimeRemoteFmt?: string;
}
export const API_VER_STAT_FOLDER = "0.13.27";
export const API_VER_REQURL = "0.13.26"; // desktop ver 0.13.26, iOS ver 1.1.1
export const API_VER_REQURL_ANDROID = "0.14.6"; // Android ver 1.2.1
export const API_VER_ENSURE_REQURL_OK = "1.0.0"; // always bypass CORS here
export const VALID_REQURL =
(!Platform.isAndroidApp && requireApiVersion(API_VER_REQURL)) ||
(Platform.isAndroidApp && requireApiVersion(API_VER_REQURL_ANDROID));
export const DEFAULT_DEBUG_FOLDER = "_debug_remotely_save/";
export const DEFAULT_SYNC_PLANS_HISTORY_FILE_PREFIX =
"sync_plans_hist_exported_on_";

14
src/baseTypesObs.ts Normal file
View File

@ -0,0 +1,14 @@
/**
* Every utils requiring Obsidian is placed here.
*/
import { Platform, requireApiVersion } from "obsidian";
export const API_VER_STAT_FOLDER = "0.13.27";
export const API_VER_REQURL = "0.13.26"; // desktop ver 0.13.26, iOS ver 1.1.1
export const API_VER_REQURL_ANDROID = "0.14.6"; // Android ver 1.2.1
export const API_VER_ENSURE_REQURL_OK = "1.0.0"; // always bypass CORS here
export const VALID_REQURL =
(!Platform.isAndroidApp && requireApiVersion(API_VER_REQURL)) ||
(Platform.isAndroidApp && requireApiVersion(API_VER_REQURL_ANDROID));

View File

@ -4,6 +4,7 @@ import { FakeFsDropbox } from "./fsDropbox";
import { FakeFsOnedrive } from "./fsOnedrive";
import { FakeFsS3 } from "./fsS3";
import { FakeFsWebdav } from "./fsWebdav";
import { FakeFsWebdis } from "./fsWebdis";
/**
* To avoid circular dependency, we need a new file here.
@ -38,6 +39,13 @@ export function getClient(
saveUpdatedConfigFunc
);
break;
case "webdis":
return new FakeFsWebdis(
settings.webdis,
vaultName,
saveUpdatedConfigFunc
);
break;
default:
throw Error(`cannot init client for serviceType=${settings.serviceType}`);
break;

View File

@ -14,8 +14,8 @@ import {
Entity,
OAUTH2_FORCE_EXPIRE_MILLISECONDS,
OnedriveConfig,
VALID_REQURL,
} from "./baseTypes";
import { VALID_REQURL } from "./baseTypesObs";
import { FakeFs } from "./fsAll";
import { bufferToArrayBuffer } from "./misc";

View File

@ -25,7 +25,8 @@ import { Platform, requestUrl, RequestUrlParam } from "obsidian";
import { Readable } from "stream";
import * as path from "path";
import AggregateError from "aggregate-error";
import { DEFAULT_CONTENT_TYPE, S3Config, VALID_REQURL } from "./baseTypes";
import { DEFAULT_CONTENT_TYPE, S3Config } from "./baseTypes";
import { VALID_REQURL } from "./baseTypesObs";
import { bufferToArrayBuffer, getFolderLevels } from "./misc";
import PQueue from "p-queue";

View File

@ -7,7 +7,8 @@ import flatten from "lodash/flatten";
import { Platform, requestUrl } from "obsidian";
import { FakeFs } from "./fsAll";
import { bufferToArrayBuffer } from "./misc";
import { Entity, VALID_REQURL, WebdavConfig } from "./baseTypes";
import { Entity, WebdavConfig } from "./baseTypes";
import { VALID_REQURL } from "./baseTypesObs";
import type {
FileStat,
WebDAVClient,

238
src/fsWebdis.ts Normal file
View File

@ -0,0 +1,238 @@
import { cloneDeep, isEqual } from "lodash";
import { DEFAULT_CONTENT_TYPE, Entity, WebdisConfig } from "./baseTypes";
import { FakeFs } from "./fsAll";
export const DEFAULT_WEBDIS_CONFIG: WebdisConfig = {
address: "",
username: "",
password: "",
remoteBaseDir: "",
};
const getWebdisPath = (fileOrFolderPath: string, remoteBaseDir: string) => {
let key = fileOrFolderPath;
if (fileOrFolderPath === "/" || fileOrFolderPath === "") {
// special
key = `${remoteBaseDir}`;
} else if (fileOrFolderPath.startsWith("/")) {
console.warn(
`why the path ${fileOrFolderPath} starts with '/'? but we just go on.`
);
key = `${remoteBaseDir}${fileOrFolderPath}`;
} else {
key = `${remoteBaseDir}/${fileOrFolderPath}`;
}
return `rs:fs:v1:${encodeURIComponent(key)}`; // we should encode them!!!!
};
export const getOrigPath = (fullKey: string, remoteBaseDir: string) => {
const fullKeyDecoded = decodeURIComponent(fullKey);
const prefix = `rs:fs:v1:${remoteBaseDir}/`;
// console.debug(`prefix=${prefix}`);
const suffix1 = ":meta";
const suffix2 = ":content";
if (!fullKeyDecoded.startsWith(prefix)) {
throw Error(`you should not call getOrigEntity on ${fullKey}`);
}
let realKey = fullKeyDecoded.slice(prefix.length);
// console.debug(`realKey=${realKey}`);
if (realKey.endsWith(suffix1)) {
realKey = realKey.slice(0, -suffix1.length);
// console.debug(`realKey=${realKey}`);
} else if (realKey.endsWith(suffix2)) {
realKey = realKey.slice(0, -suffix2.length);
// console.debug(`realKey=${realKey}`);
}
// console.debug(`fullKey=${fullKey}, realKey=${realKey}`);
return realKey;
};
export class FakeFsWebdis extends FakeFs {
kind: "webdis";
webdisConfig: WebdisConfig;
remoteBaseDir: string;
saveUpdatedConfigFunc: () => Promise<any>;
constructor(
webdisConfig: WebdisConfig,
vaultName: string,
saveUpdatedConfigFunc: () => Promise<any>
) {
super();
this.kind = "webdis";
this.webdisConfig = webdisConfig;
this.remoteBaseDir = this.webdisConfig.remoteBaseDir || vaultName || "";
this.saveUpdatedConfigFunc = saveUpdatedConfigFunc;
}
async _fetchCommand(
method: "GET" | "POST" | "PUT",
urlPath: string,
content?: ArrayBuffer
) {
const address = this.webdisConfig.address;
if (!address.startsWith(`https://`) && !address.startsWith(`http://`)) {
throw Error(
`your webdis server address should start with https:// or http://`
);
}
if (address.endsWith("/")) {
throw Error(`your webdis server should not ends with /`);
}
if (content !== undefined && method !== "PUT") {
throw Error(`you can only "POST" ArrayBuffer, not using other methods`);
}
const fullUrl = `${address}/${urlPath}`;
// console.debug(`fullUrl=${fullUrl}`)
const username = this.webdisConfig.username ?? "";
const password = this.webdisConfig.password ?? "";
if (username !== "" && password !== "") {
return await fetch(fullUrl, {
method: method,
headers: {
Authorization: "Basic " + btoa(username + ":" + password),
},
body: content,
});
} else if (username === "" && password === "") {
return await fetch(fullUrl, {
method: method,
body: content,
});
} else {
throw Error(
`your username and password should both be empty or not empty!`
);
}
}
async walk(): Promise<Entity[]> {
let cursor = "0";
const res: Entity[] = [];
do {
const command = `SCAN/${cursor}/MATCH/rs:fs:v1:*:meta/COUNT/1000`;
const rsp = (await (await this._fetchCommand("GET", command)).json())[
"SCAN"
];
// console.debug(rsp);
cursor = rsp[0];
for (const fullKeyWithMeta of rsp[1]) {
const realKey = getOrigPath(fullKeyWithMeta, this.remoteBaseDir);
res.push(await this.stat(realKey));
}
} while (cursor !== "0");
// console.debug(`walk res:`);
// console.debug(res);
return res;
}
async stat(key: string): Promise<Entity> {
const fullKey = getWebdisPath(key, this.remoteBaseDir);
return await this._statFromRaw(fullKey);
}
async _statFromRaw(key: string): Promise<Entity> {
// console.debug(`_statFromRaw on ${key}`);
const command = `HGETALL/${key}:meta`;
const rsp = (await (await this._fetchCommand("GET", command)).json())[
"HGETALL"
];
// console.debug(`rsp: ${JSON.stringify(rsp, null, 2)}`);
if (isEqual(rsp, {})) {
// empty!
throw Error(`key ${key} doesn't exist!`);
}
const realKey = getOrigPath(key, this.remoteBaseDir);
return {
key: realKey,
keyRaw: realKey,
mtimeCli: parseInt(rsp["mtime"]),
mtimeSvr: parseInt(rsp["mtime"]),
size: parseInt(rsp["size"]),
sizeRaw: parseInt(rsp["size"]),
};
}
async mkdir(key: string, mtime?: number, ctime?: number): Promise<Entity> {
let command = `HSET/${getWebdisPath(key, this.remoteBaseDir)}:meta/size/0`;
if (mtime !== undefined && mtime !== 0) {
command = `${command}/mtime/${mtime}`;
}
if (ctime !== undefined && ctime !== 0) {
command = `${command}/ctime/${ctime}`;
}
const rsp = (await (await this._fetchCommand("GET", command)).json())[
"HSET"
];
return await this.stat(key);
}
async writeFile(
key: string,
content: ArrayBuffer,
mtime: number,
ctime: number
): Promise<Entity> {
const fullKey = getWebdisPath(key, this.remoteBaseDir);
// meta
let command1 = `HSET/${fullKey}:meta/size/${content.byteLength}`;
if (mtime !== undefined && mtime !== 0) {
command1 = `${command1}/mtime/${mtime}`;
}
if (ctime !== undefined && ctime !== 0) {
command1 = `${command1}/ctime/${ctime}`;
}
const rsp1 = (await (await this._fetchCommand("GET", command1)).json())[
"HSET"
];
// content
const command2 = `SET/${fullKey}:content`;
const rsp2 = (
await (await this._fetchCommand("PUT", command2, content)).json()
)["SET"];
// fetch meta
return await this.stat(key);
}
async readFile(key: string): Promise<ArrayBuffer> {
const fullKey = getWebdisPath(key, this.remoteBaseDir);
const command = `GET/${fullKey}:content?type=${DEFAULT_CONTENT_TYPE}`;
const rsp = await (await this._fetchCommand("GET", command)).arrayBuffer();
return rsp;
}
async rm(key: string): Promise<void> {
const fullKey = getWebdisPath(key, this.remoteBaseDir);
const command = `DEL/${fullKey}:meta/${fullKey}:content`;
const rsp = (await (await this._fetchCommand("PUT", command)).json())[
"DEL"
];
}
async checkConnect(callbackFunc?: any): Promise<boolean> {
try {
const k = await (
await this._fetchCommand("GET", "PING/helloworld")
).json();
return isEqual(k, { PING: "helloworld" });
} catch (err: any) {
console.error(err);
callbackFunc?.(err);
return false;
}
}
async getUserDisplayName(): Promise<string> {
return this.webdisConfig.username || "<no usernme>";
}
async revokeAuth(): Promise<any> {
throw new Error("Method not implemented.");
}
}

View File

@ -240,12 +240,25 @@
"settings_webdav_connect_succ": "Great! The webdav server can be accessed.",
"settings_webdav_connect_fail": "The webdav server cannot be reached (possible to be any of address/username/password/authtype errors).",
"settings_webdav_connect_fail_withcors": "The webdav server cannot be reached (possible to be any of address/username/password/authtype/CORS errors).",
"settings_webdis": "Remote For Webdis",
"settings_webdis_disclaimer1": "Disclaimer: This app is NOT an official Redis® Ltd / Redis® OSS / Webdis product. Redis is a registered trademark of Redis Ltd.",
"settings_webdis_disclaimer2": "Disclaimer: The information is stored locally. Other malicious/harmful/faulty plugins may read the info. If you see any unintentional access to your Webdis server, please immediately change the username and password.",
"settings_webdis_folder": "We will store the value with keys prefixed by :{{remoteBaseDir}} on your server.",
"settings_webdis_addr": "Server Address",
"settings_webdis_addr_desc": "Server address.",
"settings_webdis_user": "Username",
"settings_webdis_user_desc": "Username. Attention: the username and other info are saved locally.",
"settings_webdis_password": "Password",
"settings_webdis_password_desc": "Password. Attention: the password and other info are saved locally.",
"settings_webdis_connect_succ": "Great! The Webdis server can be accessed.",
"settings_webdis_connect_fail": "The Webdis server cannot be reached (possible to be any of address/username/password errors).",
"settings_chooseservice": "Choose A Remote Service",
"settings_chooseservice_desc": "Start here. What service are you connecting to? S3, Dropbox, Webdav, or OneDrive for personal?",
"settings_chooseservice_desc": "Start here. What service are you connecting to? S3, Dropbox, Webdav, OneDrive for personal, or Webdis?",
"settings_chooseservice_s3": "S3 or compatible",
"settings_chooseservice_dropbox": "Dropbox",
"settings_chooseservice_webdav": "Webdav",
"settings_chooseservice_onedrive": "OneDrive for personal",
"settings_chooseservice_webdis": "Webdis (HTTP for Redis®)",
"settings_adv": "Advanced Settings",
"settings_concurrency": "Concurrency",
"settings_concurrency_desc": "How many files do you want to download or upload in parallel at most? By default it's set to 5. If you meet any problems such as rate limit, you can reduce the concurrency to a lower value.",

View File

@ -239,12 +239,25 @@
"settings_webdav_connect_succ": "很好!可以连接上 Webdav 服务器。",
"settings_webdav_connect_fail": "无法连接上 Webdav 服务器。(可能是地址/账号/密码/鉴权类型等错误。)",
"settings_webdav_connect_fail_withcors": "无法连接上 Webdav 服务器。(可能是地址/账号/密码/鉴权类型/CORS 等错误。)",
"settings_webdis": "Webdis 设置",
"settings_webdis_disclaimer1": "声明:此插件不是 Redis® Ltd 或 Redis® 软件或 Wedis 的官方产品。Redis 是 Redis Ltd 的注册商标。",
"settings_webdis_disclaimer2": "声明:您所输入的信息存储于本地。其它有害的或者出错的插件,是有可能读取到这些信息的。如果您发现了 Webdis 服务器有不符合预期的访问,请立刻修改用户名和密码。",
"settings_webdis_folder": "我们会在您的服务器上创建带有此前缀的 key 并在里面同步::{{remoteBaseDir}}。",
"settings_webdis_addr": "服务器地址",
"settings_webdis_addr_desc": "服务器地址",
"settings_webdis_user": "用户名",
"settings_webdis_user_desc": "用户名。注意:用户名和其它信息都会保存在本地。",
"settings_webdis_password": "密码",
"settings_webdis_password_desc": "密码。注意:密码和其它信息都会保存在本地。",
"settings_webdis_connect_succ": "很好!可以连接上 Webdis 服务器。",
"settings_webdis_connect_fail": "无法连接上 Webdis 服务器。(可能是地址/账号/密码/鉴权类型等错误。)",
"settings_chooseservice": "选择远程服务",
"settings_chooseservice_desc": "从这里开始设置。您想连接到哪一个服务S3、Dropbox、Webdav、OneDrive个人版",
"settings_chooseservice_desc": "从这里开始设置。您想连接到哪一个服务S3、Dropbox、Webdav、OneDrive个人版、Webdis",
"settings_chooseservice_s3": "S3 或兼容 S3 的服务",
"settings_chooseservice_dropbox": "Dropbox",
"settings_chooseservice_webdav": "Webdav",
"settings_chooseservice_onedrive": "OneDrive个人版",
"settings_chooseservice_webdis": "Webdis (an HTTP interface for Redis)",
"settings_adv": "进阶设置",
"settings_concurrency": "并行度",
"settings_concurrency_desc": "您希望同时最多有多少个文件被上传和下载?默认值是 5。如果您遇到了一些问题如访问频率限制您可以减少并行度。",

View File

@ -238,12 +238,25 @@
"settings_webdav_connect_succ": "很好!可以連線上 Webdav 伺服器。",
"settings_webdav_connect_fail": "無法連線上 Webdav 伺服器。(可能是地址/賬號/密碼/鑑權型別等錯誤。)",
"settings_webdav_connect_fail_withcors": "無法連線上 Webdav 伺服器。(可能是地址/賬號/密碼/鑑權型別/CORS 等錯誤。)",
"settings_webdis": "Webdis 設置",
"settings_webdis_disclaimer1": "聲明:此插件不是 Redis® Ltd 或 Redis® 軟件或 Wedis 的官方產品。Redis 是 Redis Ltd 的註冊商標。",
"settings_webdis_disclaimer2": "聲明:您所輸入的信息存儲於本地。其它有害的或者出錯的插件,是有可能讀取到這些信息的。如果您發現了 Webdis 服務器有不符合預期的訪問,請立刻修改用戶名和密碼。",
"settings_webdis_folder": "我們會在您的服務器上創建帶有此前綴的 key 並在裡面同步::{{remoteBaseDir}}。",
"settings_webdis_addr": "服務器地址",
"settings_webdis_addr_desc": "服務器地址",
"settings_webdis_user": "用戶名",
"settings_webdis_user_desc": "用戶名。注意:用戶名和其它信息都會保存在本地。",
"settings_webdis_password": "密碼",
"settings_webdis_password_desc": "密碼。注意:密碼和其它信息都會保存在本地。",
"settings_webdis_connect_succ": "很好!可以連接上 Webdis 服務器。",
"settings_webdis_connect_fail": "無法連接上 Webdis 服務器。(可能是地址/賬號/密碼/鑑權類型等錯誤。)",
"settings_chooseservice": "選擇遠端服務",
"settings_chooseservice_desc": "從這裡開始設定。您想連線到哪一個服務S3、Dropbox、Webdav、OneDrive個人版",
"settings_chooseservice_desc": "從這裡開始設定。您想連線到哪一個服務S3、Dropbox、Webdav、OneDrive個人版、Webdis",
"settings_chooseservice_s3": "S3 或相容 S3 的服務",
"settings_chooseservice_dropbox": "Dropbox",
"settings_chooseservice_webdav": "Webdav",
"settings_chooseservice_onedrive": "OneDrive個人版",
"settings_chooseservice_webdis": "Webdis (an HTTP interface for Redis®)",
"settings_adv": "進階設定",
"settings_concurrency": "並行度",
"settings_concurrency_desc": "您希望同時最多有多少個檔案被上傳和下載?預設值是 5。如果您遇到了一些問題如訪問頻率限制您可以減少並行度。",

View File

@ -21,8 +21,8 @@ import {
COMMAND_CALLBACK_ONEDRIVE,
COMMAND_CALLBACK_DROPBOX,
COMMAND_URI,
API_VER_ENSURE_REQURL_OK,
} from "./baseTypes";
import { API_VER_ENSURE_REQURL_OK } from "./baseTypesObs";
import { importQrCodeUri } from "./importExport";
import {
prepareDBs,
@ -61,12 +61,14 @@ import { FakeFsEncrypt } from "./fsEncrypt";
import { syncer } from "./sync";
import { getClient } from "./fsGetter";
import throttle from "lodash/throttle";
import { DEFAULT_WEBDIS_CONFIG } from "./fsWebdis";
const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
s3: DEFAULT_S3_CONFIG,
webdav: DEFAULT_WEBDAV_CONFIG,
dropbox: DEFAULT_DROPBOX_CONFIG,
onedrive: DEFAULT_ONEDRIVE_CONFIG,
webdis: DEFAULT_WEBDIS_CONFIG,
password: "",
serviceType: "s3",
currLogLevel: "info",

View File

@ -11,20 +11,23 @@ import {
import type { TextComponent } from "obsidian";
import { createElement, Eye, EyeOff } from "lucide";
import {
API_VER_ENSURE_REQURL_OK,
API_VER_REQURL,
ConflictActionType,
DEFAULT_DEBUG_FOLDER,
EmptyFolderCleanType,
SUPPORTED_SERVICES_TYPE,
SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR,
SyncDirectionType,
VALID_REQURL,
WebdavAuthType,
WebdavDepthType,
CipherMethodType,
QRExportType,
} from "./baseTypes";
import {
API_VER_ENSURE_REQURL_OK,
API_VER_REQURL,
VALID_REQURL,
} from "./baseTypesObs";
import {
exportVaultProfilerResultsToFiles,
exportVaultSyncPlansToFiles,
@ -1655,6 +1658,132 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
});
});
//////////////////////////////////////////////////
// below for webdis
//////////////////////////////////////////////////
const webdisDiv = containerEl.createEl("div", { cls: "webdis-hide" });
webdisDiv.toggleClass(
"webdis-hide",
this.plugin.settings.serviceType !== "webdis"
);
webdisDiv.createEl("h2", { text: t("settings_webdis") });
const webdisLongDescDiv = webdisDiv.createEl("div", {
cls: "settings-long-desc",
});
for (const c of [
t("settings_webdis_disclaimer1"),
t("settings_webdis_disclaimer2"),
]) {
webdisLongDescDiv.createEl("p", {
text: c,
cls: "webdis-disclaimer",
});
}
webdisLongDescDiv.createEl("p", {
text: t("settings_webdis_folder", {
remoteBaseDir:
this.plugin.settings.webdis.remoteBaseDir || this.app.vault.getName(),
}),
});
new Setting(webdisDiv)
.setName(t("settings_webdis_addr"))
.setDesc(t("settings_webdis_addr_desc"))
.addText((text) =>
text
.setPlaceholder("https://")
.setValue(this.plugin.settings.webdis.address)
.onChange(async (value) => {
this.plugin.settings.webdis.address = value.trim();
// normally saved
await this.plugin.saveSettings();
})
);
new Setting(webdisDiv)
.setName(t("settings_webdis_user"))
.setDesc(t("settings_webdis_user_desc"))
.addText((text) => {
wrapTextWithPasswordHide(text);
text
.setPlaceholder("")
.setValue(this.plugin.settings.webdis.username ?? "")
.onChange(async (value) => {
this.plugin.settings.webdis.username = (value ?? "").trim();
await this.plugin.saveSettings();
});
});
new Setting(webdisDiv)
.setName(t("settings_webdis_password"))
.setDesc(t("settings_webdis_password_desc"))
.addText((text) => {
wrapTextWithPasswordHide(text);
text
.setPlaceholder("")
.setValue(this.plugin.settings.webdis.password ?? "")
.onChange(async (value) => {
this.plugin.settings.webdis.password = (value ?? "").trim();
await this.plugin.saveSettings();
});
});
let newWebdisRemoteBaseDir =
this.plugin.settings.webdis.remoteBaseDir || "";
new Setting(webdisDiv)
.setName(t("settings_remotebasedir"))
.setDesc(t("settings_remotebasedir_desc"))
.addText((text) =>
text
.setPlaceholder(this.app.vault.getName())
.setValue(newWebdisRemoteBaseDir)
.onChange((value) => {
newWebdisRemoteBaseDir = value.trim();
})
)
.addButton((button) => {
button.setButtonText(t("confirm"));
button.onClick(() => {
new ChangeRemoteBaseDirModal(
this.app,
this.plugin,
newWebdisRemoteBaseDir,
"webdis"
).open();
});
});
new Setting(webdisDiv)
.setName(t("settings_checkonnectivity"))
.setDesc(t("settings_checkonnectivity_desc"))
.addButton(async (button) => {
button.setButtonText(t("settings_checkonnectivity_button"));
button.onClick(async () => {
new Notice(t("settings_checkonnectivity_checking"));
const self = this;
const client = getClient(
this.plugin.settings,
this.app.vault.getName(),
() => this.plugin.saveSettings()
);
const errors = { msg: "" };
const res = await client.checkConnect((err: any) => {
errors.msg = `${err}`;
});
if (res) {
new Notice(t("settings_webdis_connect_succ"));
} else {
new Notice(t("settings_webdis_connect_fail"));
new Notice(errors.msg);
}
});
});
//////////////////////////////////////////////////
// below for general chooser (part 2/2)
//////////////////////////////////////////////////
@ -1669,6 +1798,8 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
dropdown.addOption("dropbox", t("settings_chooseservice_dropbox"));
dropdown.addOption("webdav", t("settings_chooseservice_webdav"));
dropdown.addOption("onedrive", t("settings_chooseservice_onedrive"));
dropdown.addOption("webdis", t("settings_chooseservice_webdis"));
dropdown
.setValue(this.plugin.settings.serviceType)
.onChange(async (val) => {
@ -1689,6 +1820,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
"webdav-hide",
this.plugin.settings.serviceType !== "webdav"
);
webdisDiv.toggleClass(
"webdis-hide",
this.plugin.settings.serviceType !== "webdis"
);
await this.plugin.saveSettings();
});
});

View File

@ -61,6 +61,13 @@
display: none;
}
.webdis-disclaimer {
font-weight: bold;
}
.webdis-hide {
display: none;
}
.qrcode-img {
width: 350px;
height: 350px;

View File

@ -16,6 +16,9 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
onedrive: {
username: "test 🍎 emoji",
} as any,
webdis: {
address: "addr",
} as any,
password: "password",
serviceType: "s3",
currLogLevel: "info",

12
tests/fsWebdis.test.ts Normal file
View File

@ -0,0 +1,12 @@
import { strict as assert } from "assert";
import { getOrigPath } from "../src/fsWebdis";
describe("Webdis operations tests", () => {
it("should get orig keys correctly", () => {
const input = "rs:fs:v1:库名字/something dev.md:meta";
const output = getOrigPath(input, "库名字");
const expected = "something dev.md";
assert.equal(output, expected);
});
});