add yandex disk pro

This commit is contained in:
fyears
2024-06-11 00:01:36 +08:00
parent 5186dcb967
commit 2e09686675
25 changed files with 1638 additions and 44 deletions
+8 -3
View File
@@ -8,6 +8,7 @@ import type {
GoogleDriveConfig,
PCloudConfig,
ProConfig,
YandexDiskConfig,
} from "../pro/src/baseTypesPro";
import type { LangTypeAndAuto } from "./i18n";
@@ -21,7 +22,8 @@ export type SUPPORTED_SERVICES_TYPE =
| "webdis"
| "googledrive"
| "box"
| "pcloud";
| "pcloud"
| "yandexdisk";
export type SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR =
| "webdav"
@@ -30,7 +32,8 @@ export type SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR =
| "webdis"
| "googledrive"
| "box"
| "pcloud";
| "pcloud"
| "yandexdisk";
export interface S3Config {
s3Endpoint: string;
@@ -127,7 +130,8 @@ export type QRExportType =
| "webdis"
| "googledrive"
| "box"
| "pcloud";
| "pcloud"
| "yandexdisk";
export interface ProfilerConfig {
enablePrinting?: boolean;
@@ -143,6 +147,7 @@ export interface RemotelySavePluginSettings {
googledrive: GoogleDriveConfig;
box: BoxConfig;
pcloud: PCloudConfig;
yandexdisk: YandexDiskConfig;
password: string;
serviceType: SUPPORTED_SERVICES_TYPE;
currLogLevel?: string;
+7
View File
@@ -1,6 +1,7 @@
import { FakeFsBox } from "../pro/src/fsBox";
import { FakeFsGoogleDrive } from "../pro/src/fsGoogleDrive";
import { FakeFsPCloud } from "../pro/src/fsPCloud";
import { FakeFsYandexDisk } from "../pro/src/fsYandexDisk";
import type { RemotelySavePluginSettings } from "./baseTypes";
import type { FakeFs } from "./fsAll";
import { FakeFsDropbox } from "./fsDropbox";
@@ -58,6 +59,12 @@ export function getClient(
vaultName,
saveUpdatedConfigFunc
);
case "yandexdisk":
return new FakeFsYandexDisk(
settings.yandexdisk,
vaultName,
saveUpdatedConfigFunc
);
default:
throw Error(`cannot init client for serviceType=${settings.serviceType}`);
}
+3
View File
@@ -27,6 +27,7 @@ export const exportQrCodeUri = async (
delete settings2.googledrive;
delete settings2.box;
delete settings2.pcloud;
delete settings2.yandexdisk;
delete settings2.pro;
} else if (exportFields === "s3") {
settings2 = { s3: cloneDeep(settings.s3) };
@@ -44,6 +45,8 @@ export const exportQrCodeUri = async (
settings2 = { box: cloneDeep(settings.box) };
} else if (exportFields === "pcloud") {
settings2 = { pcloud: cloneDeep(settings.pcloud) };
} else if (exportFields === "yandexdisk") {
settings2 = { yandexdisk: cloneDeep(settings.yandexdisk) };
}
delete settings2.vaultRandomID;
+83
View File
@@ -27,6 +27,7 @@ import {
COMMAND_CALLBACK_BOX,
COMMAND_CALLBACK_PCLOUD,
COMMAND_CALLBACK_PRO,
COMMAND_CALLBACK_YANDEXDISK,
} from "../pro/src/baseTypesPro";
import {
DEFAULT_BOX_CONFIG,
@@ -42,6 +43,11 @@ import {
sendAuthReq as sendAuthReqPCloud,
setConfigBySuccessfullAuthInplace as setConfigBySuccessfullAuthInplacePCloud,
} from "../pro/src/fsPCloud";
import {
DEFAULT_YANDEXDISK_CONFIG,
sendAuthReq as sendAuthReqYandexDisk,
setConfigBySuccessfullAuthInplace as setConfigBySuccessfullAuthInplaceYandexDisk,
} from "../pro/src/fsYandexDisk";
import type {
RemotelySavePluginSettings,
SyncTriggerSourceType,
@@ -99,6 +105,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
googledrive: DEFAULT_GOOGLEDRIVE_CONFIG,
box: DEFAULT_BOX_CONFIG,
pcloud: DEFAULT_PCLOUD_CONFIG,
yandexdisk: DEFAULT_YANDEXDISK_CONFIG,
password: "",
serviceType: "s3",
currLogLevel: "info",
@@ -914,6 +921,62 @@ export default class RemotelySavePlugin extends Plugin {
}
);
this.registerObsidianProtocolHandler(
COMMAND_CALLBACK_YANDEXDISK,
async (inputParams) => {
if (this.oauth2Info.helperModal !== undefined) {
const k = this.oauth2Info.helperModal.contentEl;
k.empty();
t("protocol_yandexdisk_connecting")
.split("\n")
.forEach((val) => {
k.createEl("p", {
text: val,
});
});
}
console.debug(inputParams);
const authRes = await sendAuthReqYandexDisk(
inputParams.code,
async (e: any) => {
new Notice(t("protocol_yandexdisk_connect_fail"));
new Notice(`${e}`);
throw e;
}
);
console.debug(authRes);
const self = this;
await setConfigBySuccessfullAuthInplaceYandexDisk(
this.settings.yandexdisk!,
authRes,
() => self.saveSettings()
);
this.oauth2Info.verifier = ""; // reset it
this.oauth2Info.helperModal?.close(); // close it
this.oauth2Info.helperModal = undefined;
this.oauth2Info.authDiv?.toggleClass(
"yandexdisk-auth-button-hide",
this.settings.yandexdisk?.refreshToken !== ""
);
this.oauth2Info.authDiv = undefined;
this.oauth2Info.revokeAuthSetting?.setDesc(
t("protocol_yandexdisk_connect_succ_revoke")
);
this.oauth2Info.revokeAuthSetting = undefined;
this.oauth2Info.revokeDiv?.toggleClass(
"yandexdisk-revoke-auth-button-hide",
this.settings.yandexdisk?.refreshToken === ""
);
this.oauth2Info.revokeDiv = undefined;
}
);
this.syncRibbon = this.addRibbonIcon(
iconNameSyncWait,
`${this.manifest.name}`,
@@ -1208,6 +1271,10 @@ export default class RemotelySavePlugin extends Plugin {
this.settings.pcloud = DEFAULT_PCLOUD_CONFIG;
}
if (this.settings.yandexdisk === undefined) {
this.settings.yandexdisk = DEFAULT_YANDEXDISK_CONFIG;
}
await this.saveSettings();
}
@@ -1306,6 +1373,16 @@ export default class RemotelySavePlugin extends Plugin {
needSave = true;
}
let yandexDiskExpired = false;
if (
this.settings.yandexdisk.refreshToken !== "" &&
current >= this.settings!.yandexdisk!.credentialsShouldBeDeletedAtTimeMs!
) {
yandexDiskExpired = true;
this.settings.yandexdisk = cloneDeep(DEFAULT_YANDEXDISK_CONFIG);
needSave = true;
}
if (this.settings.pro === undefined) {
this.settings.pro = cloneDeep(DEFAULT_PRO_CONFIG);
}
@@ -1346,6 +1423,12 @@ export default class RemotelySavePlugin extends Plugin {
6000
);
}
if (yandexDiskExpired) {
new Notice(
`${this.manifest.name}: You haven't manually auth Yandex Disk for many days, you need to re-auth it again.`,
6000
);
}
}
async getVaultRandomIDFromOldConfigFile() {
+39 -2
View File
@@ -25,6 +25,7 @@ import { generateBoxSettingsPart } from "../pro/src/settingsBox";
import { generateGoogleDriveSettingsPart } from "../pro/src/settingsGoogleDrive";
import { generatePCloudSettingsPart } from "../pro/src/settingsPCloud";
import { generateProSettingsPart } from "../pro/src/settingsPro";
import { generateYandexDiskSettingsPart } from "../pro/src/settingsYandexDisk";
import { API_VER_ENSURE_REQURL_OK, VALID_REQURL } from "./baseTypesObs";
import { messyConfigToNormal } from "./configPersist";
import {
@@ -1820,7 +1821,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
);
//////////////////////////////////////////////////
// below for box
// below for pcloud
//////////////////////////////////////////////////
const { pCloudDiv, pCloudAllowedToUsedDiv, pCloudNotShowUpHintSetting } =
@@ -1828,6 +1829,22 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
this.plugin.saveSettings()
);
//////////////////////////////////////////////////
// below for yandexdisk
//////////////////////////////////////////////////
const {
yandexDiskDiv,
yandexDiskAllowedToUsedDiv,
yandexDiskNotShowUpHintSetting,
} = generateYandexDiskSettingsPart(
containerEl,
t,
this.app,
this.plugin,
() => this.plugin.saveSettings()
);
//////////////////////////////////////////////////
// below for general chooser (part 2/2)
//////////////////////////////////////////////////
@@ -1849,6 +1866,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
);
dropdown.addOption("box", t("settings_chooseservice_box"));
dropdown.addOption("pcloud", t("settings_chooseservice_pcloud"));
dropdown.addOption(
"yandexdisk",
t("settings_chooseservice_yandexdisk")
);
dropdown
.setValue(this.plugin.settings.serviceType)
@@ -1886,6 +1907,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
"pcloud-hide",
this.plugin.settings.serviceType !== "pcloud"
);
yandexDiskDiv.toggleClass(
"yandexdisk-hide",
this.plugin.settings.serviceType !== "yandexdisk"
);
await this.plugin.saveSettings();
});
});
@@ -2460,6 +2485,16 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
button.onClick(async () => {
new ExportSettingsQrCodeModal(this.app, this.plugin, "pcloud").open();
});
})
.addButton(async (button) => {
button.setButtonText(t("settings_export_yandexdisk_button"));
button.onClick(async () => {
new ExportSettingsQrCodeModal(
this.app,
this.plugin,
"yandexdisk"
).open();
});
});
let importSettingVal = "";
@@ -2530,7 +2565,9 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
boxAllowedToUsedDiv,
boxNotShowUpHintSetting,
pCloudAllowedToUsedDiv,
pCloudNotShowUpHintSetting
pCloudNotShowUpHintSetting,
yandexDiskAllowedToUsedDiv,
yandexDiskNotShowUpHintSetting
);
//////////////////////////////////////////////////