add koofr

This commit is contained in:
fyears
2024-06-15 23:06:41 +08:00
parent 689376adfe
commit a64b859e46
24 changed files with 11263 additions and 6 deletions
+9 -3
View File
@@ -6,6 +6,7 @@
import type {
BoxConfig,
GoogleDriveConfig,
KoofrConfig,
PCloudConfig,
ProConfig,
YandexDiskConfig,
@@ -23,7 +24,8 @@ export type SUPPORTED_SERVICES_TYPE =
| "googledrive"
| "box"
| "pcloud"
| "yandexdisk";
| "yandexdisk"
| "koofr";
export type SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR =
| "webdav"
@@ -33,7 +35,8 @@ export type SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR =
| "googledrive"
| "box"
| "pcloud"
| "yandexdisk";
| "yandexdisk"
| "koofr";
export interface S3Config {
s3Endpoint: string;
@@ -131,7 +134,8 @@ export type QRExportType =
| "googledrive"
| "box"
| "pcloud"
| "yandexdisk";
| "yandexdisk"
| "koofr";
export interface ProfilerConfig {
enablePrinting?: boolean;
@@ -148,6 +152,8 @@ export interface RemotelySavePluginSettings {
box: BoxConfig;
pcloud: PCloudConfig;
yandexdisk: YandexDiskConfig;
koofr: KoofrConfig;
password: string;
serviceType: SUPPORTED_SERVICES_TYPE;
currLogLevel?: string;
+3
View File
@@ -1,5 +1,6 @@
import { FakeFsBox } from "../pro/src/fsBox";
import { FakeFsGoogleDrive } from "../pro/src/fsGoogleDrive";
import { FakeFsKoofr } from "../pro/src/fsKoofr";
import { FakeFsPCloud } from "../pro/src/fsPCloud";
import { FakeFsYandexDisk } from "../pro/src/fsYandexDisk";
import type { RemotelySavePluginSettings } from "./baseTypes";
@@ -65,6 +66,8 @@ export function getClient(
vaultName,
saveUpdatedConfigFunc
);
case "koofr":
return new FakeFsKoofr(settings.koofr, vaultName, saveUpdatedConfigFunc);
default:
throw Error(`cannot init client for serviceType=${settings.serviceType}`);
}
+3
View File
@@ -28,6 +28,7 @@ export const exportQrCodeUri = async (
delete settings2.box;
delete settings2.pcloud;
delete settings2.yandexdisk;
delete settings2.koofr;
delete settings2.pro;
} else if (exportFields === "s3") {
settings2 = { s3: cloneDeep(settings.s3) };
@@ -47,6 +48,8 @@ export const exportQrCodeUri = async (
settings2 = { pcloud: cloneDeep(settings.pcloud) };
} else if (exportFields === "yandexdisk") {
settings2 = { yandexdisk: cloneDeep(settings.yandexdisk) };
} else if (exportFields === "koofr") {
settings2 = { koofr: cloneDeep(settings.koofr) };
}
delete settings2.vaultRandomID;
+85
View File
@@ -25,6 +25,7 @@ import {
} from "../pro/src/account";
import {
COMMAND_CALLBACK_BOX,
COMMAND_CALLBACK_KOOFR,
COMMAND_CALLBACK_PCLOUD,
COMMAND_CALLBACK_PRO,
COMMAND_CALLBACK_YANDEXDISK,
@@ -36,6 +37,11 @@ import {
setConfigBySuccessfullAuthInplace as setConfigBySuccessfullAuthInplaceBox,
} from "../pro/src/fsBox";
import { DEFAULT_GOOGLEDRIVE_CONFIG } from "../pro/src/fsGoogleDrive";
import {
DEFAULT_KOOFR_CONFIG,
sendAuthReq as sendAuthReqKoofr,
setConfigBySuccessfullAuthInplace as setConfigBySuccessfullAuthInplaceKoofr,
} from "../pro/src/fsKoofr";
import {
type AuthAllowFirstRes as AuthAllowFirstResPCloud,
DEFAULT_PCLOUD_CONFIG,
@@ -106,6 +112,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
box: DEFAULT_BOX_CONFIG,
pcloud: DEFAULT_PCLOUD_CONFIG,
yandexdisk: DEFAULT_YANDEXDISK_CONFIG,
koofr: DEFAULT_KOOFR_CONFIG,
password: "",
serviceType: "s3",
currLogLevel: "info",
@@ -977,6 +984,64 @@ export default class RemotelySavePlugin extends Plugin {
}
);
this.registerObsidianProtocolHandler(
COMMAND_CALLBACK_KOOFR,
async (inputParams) => {
if (this.oauth2Info.helperModal !== undefined) {
const k = this.oauth2Info.helperModal.contentEl;
k.empty();
t("protocol_koofr_connecting")
.split("\n")
.forEach((val) => {
k.createEl("p", {
text: val,
});
});
}
console.debug(inputParams);
const authRes = await sendAuthReqKoofr(
this.settings.koofr.api,
inputParams.code,
async (e: any) => {
new Notice(t("protocol_koofr_connect_fail"));
new Notice(`${e}`);
throw e;
},
true
);
console.debug(authRes);
const self = this;
await setConfigBySuccessfullAuthInplaceKoofr(
this.settings.koofr!,
authRes!,
() => self.saveSettings()
);
this.oauth2Info.verifier = ""; // reset it
this.oauth2Info.helperModal?.close(); // close it
this.oauth2Info.helperModal = undefined;
this.oauth2Info.authDiv?.toggleClass(
"koofr-auth-button-hide",
this.settings.koofr?.refreshToken !== ""
);
this.oauth2Info.authDiv = undefined;
this.oauth2Info.revokeAuthSetting?.setDesc(
t("protocol_koofr_connect_succ_revoke")
);
this.oauth2Info.revokeAuthSetting = undefined;
this.oauth2Info.revokeDiv?.toggleClass(
"koofr-revoke-auth-button-hide",
this.settings.koofr?.refreshToken === ""
);
this.oauth2Info.revokeDiv = undefined;
}
);
this.syncRibbon = this.addRibbonIcon(
iconNameSyncWait,
`${this.manifest.name}`,
@@ -1275,6 +1340,10 @@ export default class RemotelySavePlugin extends Plugin {
this.settings.yandexdisk = DEFAULT_YANDEXDISK_CONFIG;
}
if (this.settings.koofr === undefined) {
this.settings.koofr = DEFAULT_KOOFR_CONFIG;
}
await this.saveSettings();
}
@@ -1383,6 +1452,16 @@ export default class RemotelySavePlugin extends Plugin {
needSave = true;
}
let koofrExpired = false;
if (
this.settings.koofr.refreshToken !== "" &&
current >= this.settings!.koofr!.credentialsShouldBeDeletedAtTimeMs!
) {
koofrExpired = true;
this.settings.koofr = cloneDeep(DEFAULT_KOOFR_CONFIG);
needSave = true;
}
if (this.settings.pro === undefined) {
this.settings.pro = cloneDeep(DEFAULT_PRO_CONFIG);
}
@@ -1429,6 +1508,12 @@ export default class RemotelySavePlugin extends Plugin {
6000
);
}
if (koofrExpired) {
new Notice(
`${this.manifest.name}: You haven't manually auth koofr for many days, you need to re-auth it again.`,
6000
);
}
}
async getVaultRandomIDFromOldConfigFile() {
+24 -1
View File
@@ -23,6 +23,7 @@ import type {
import cloneDeep from "lodash/cloneDeep";
import { generateBoxSettingsPart } from "../pro/src/settingsBox";
import { generateGoogleDriveSettingsPart } from "../pro/src/settingsGoogleDrive";
import { generateKoofrSettingsPart } from "../pro/src/settingsKoofr";
import { generatePCloudSettingsPart } from "../pro/src/settingsPCloud";
import { generateProSettingsPart } from "../pro/src/settingsPro";
import { generateYandexDiskSettingsPart } from "../pro/src/settingsYandexDisk";
@@ -1862,6 +1863,15 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
() => this.plugin.saveSettings()
);
//////////////////////////////////////////////////
// below for koofr
//////////////////////////////////////////////////
const { koofrDiv, koofrAllowedToUsedDiv, koofrNotShowUpHintSetting } =
generateKoofrSettingsPart(containerEl, t, this.app, this.plugin, () =>
this.plugin.saveSettings()
);
//////////////////////////////////////////////////
// below for general chooser (part 2/2)
//////////////////////////////////////////////////
@@ -1887,6 +1897,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
"yandexdisk",
t("settings_chooseservice_yandexdisk")
);
dropdown.addOption("koofr", t("settings_chooseservice_koofr"));
dropdown
.setValue(this.plugin.settings.serviceType)
@@ -1928,6 +1939,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
"yandexdisk-hide",
this.plugin.settings.serviceType !== "yandexdisk"
);
koofrDiv.toggleClass(
"koofr-hide",
this.plugin.settings.serviceType !== "koofr"
);
await this.plugin.saveSettings();
});
});
@@ -2507,6 +2522,12 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
"yandexdisk"
).open();
});
})
.addButton(async (button) => {
button.setButtonText(t("settings_export_koofr_button"));
button.onClick(async () => {
new ExportSettingsQrCodeModal(this.app, this.plugin, "koofr").open();
});
});
let importSettingVal = "";
@@ -2579,7 +2600,9 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
pCloudAllowedToUsedDiv,
pCloudNotShowUpHintSetting,
yandexDiskAllowedToUsedDiv,
yandexDiskNotShowUpHintSetting
yandexDiskNotShowUpHintSetting,
koofrAllowedToUsedDiv,
koofrNotShowUpHintSetting
);
//////////////////////////////////////////////////