This commit is contained in:
fyears
2024-06-09 22:37:55 +08:00
parent 12e45a7f38
commit 24b839227a
20 changed files with 1323 additions and 50 deletions
+8 -3
View File
@@ -6,6 +6,7 @@
import type {
BoxConfig,
GoogleDriveConfig,
PCloudConfig,
ProConfig,
} from "../pro/src/baseTypesPro";
import type { LangTypeAndAuto } from "./i18n";
@@ -19,7 +20,8 @@ export type SUPPORTED_SERVICES_TYPE =
| "onedrive"
| "webdis"
| "googledrive"
| "box";
| "box"
| "pcloud";
export type SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR =
| "webdav"
@@ -27,7 +29,8 @@ export type SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR =
| "onedrive"
| "webdis"
| "googledrive"
| "box";
| "box"
| "pcloud";
export interface S3Config {
s3Endpoint: string;
@@ -123,7 +126,8 @@ export type QRExportType =
| "webdav"
| "webdis"
| "googledrive"
| "box";
| "box"
| "pcloud";
export interface ProfilerConfig {
enablePrinting?: boolean;
@@ -138,6 +142,7 @@ export interface RemotelySavePluginSettings {
webdis: WebdisConfig;
googledrive: GoogleDriveConfig;
box: BoxConfig;
pcloud: PCloudConfig;
password: string;
serviceType: SUPPORTED_SERVICES_TYPE;
currLogLevel?: string;
+7
View File
@@ -1,5 +1,6 @@
import { FakeFsBox } from "../pro/src/fsBox";
import { FakeFsGoogleDrive } from "../pro/src/fsGoogleDrive";
import { FakeFsPCloud } from "../pro/src/fsPCloud";
import type { RemotelySavePluginSettings } from "./baseTypes";
import type { FakeFs } from "./fsAll";
import { FakeFsDropbox } from "./fsDropbox";
@@ -51,6 +52,12 @@ export function getClient(
);
case "box":
return new FakeFsBox(settings.box, vaultName, saveUpdatedConfigFunc);
case "pcloud":
return new FakeFsPCloud(
settings.pcloud,
vaultName,
saveUpdatedConfigFunc
);
default:
throw Error(`cannot init client for serviceType=${settings.serviceType}`);
}
+3
View File
@@ -26,6 +26,7 @@ export const exportQrCodeUri = async (
delete settings2.webdis;
delete settings2.googledrive;
delete settings2.box;
delete settings2.pcloud;
delete settings2.pro;
} else if (exportFields === "s3") {
settings2 = { s3: cloneDeep(settings.s3) };
@@ -41,6 +42,8 @@ export const exportQrCodeUri = async (
settings2 = { googledrive: cloneDeep(settings.googledrive) };
} else if (exportFields === "box") {
settings2 = { box: cloneDeep(settings.box) };
} else if (exportFields === "pcloud") {
settings2 = { pcloud: cloneDeep(settings.pcloud) };
}
delete settings2.vaultRandomID;
+122 -28
View File
@@ -1,4 +1,7 @@
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
import AggregateError from "aggregate-error";
import cloneDeep from "lodash/cloneDeep";
import throttle from "lodash/throttle";
import { FileText, RefreshCcw, RotateCcw, createElement } from "lucide";
import {
Events,
@@ -20,6 +23,25 @@ import {
sendAuthReq as sendAuthReqPro,
setConfigBySuccessfullAuthInplace as setConfigBySuccessfullAuthInplacePro,
} from "../pro/src/account";
import {
COMMAND_CALLBACK_BOX,
COMMAND_CALLBACK_PCLOUD,
COMMAND_CALLBACK_PRO,
} from "../pro/src/baseTypesPro";
import {
DEFAULT_BOX_CONFIG,
FakeFsBox,
sendAuthReq as sendAuthReqBox,
setConfigBySuccessfullAuthInplace as setConfigBySuccessfullAuthInplaceBox,
} from "../pro/src/fsBox";
import { DEFAULT_GOOGLEDRIVE_CONFIG } from "../pro/src/fsGoogleDrive";
import {
type AuthAllowFirstRes as AuthAllowFirstResPCloud,
DEFAULT_PCLOUD_CONFIG,
generateAuthUrl as generateAuthUrlPCloud,
sendAuthReq as sendAuthReqPCloud,
setConfigBySuccessfullAuthInplace as setConfigBySuccessfullAuthInplacePCloud,
} from "../pro/src/fsPCloud";
import type {
RemotelySavePluginSettings,
SyncTriggerSourceType,
@@ -32,11 +54,15 @@ import {
} from "./baseTypes";
import { API_VER_ENSURE_REQURL_OK } from "./baseTypesObs";
import { messyConfigToNormal, normalConfigToMessy } from "./configPersist";
import { exportVaultSyncPlansToFiles } from "./debugMode";
import {
DEFAULT_DROPBOX_CONFIG,
sendAuthReq as sendAuthReqDropbox,
setConfigBySuccessfullAuthInplace as setConfigBySuccessfullAuthInplaceDropbox,
} from "./fsDropbox";
import { FakeFsEncrypt } from "./fsEncrypt";
import { getClient } from "./fsGetter";
import { FakeFsLocal } from "./fsLocal";
import {
type AccessCodeResponseSuccessfulType,
DEFAULT_ONEDRIVE_CONFIG,
@@ -45,6 +71,7 @@ import {
} from "./fsOnedrive";
import { DEFAULT_S3_CONFIG } from "./fsS3";
import { DEFAULT_WEBDAV_CONFIG } from "./fsWebdav";
import { DEFAULT_WEBDIS_CONFIG } from "./fsWebdis";
import { I18n } from "./i18n";
import type { LangTypeAndAuto, TransItemType } from "./i18n";
import { importQrCodeUri } from "./importExport";
@@ -57,31 +84,11 @@ import {
upsertLastSuccessSyncTimeByVault,
upsertPluginVersionByVault,
} from "./localdb";
import { RemotelySaveSettingTab } from "./settings";
import { SyncAlgoV3Modal } from "./syncAlgoV3Notice";
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
import AggregateError from "aggregate-error";
import throttle from "lodash/throttle";
import {
COMMAND_CALLBACK_BOX,
COMMAND_CALLBACK_PRO,
} from "../pro/src/baseTypesPro";
import {
DEFAULT_BOX_CONFIG,
FakeFsBox,
sendAuthReq as sendAuthReqBox,
setConfigBySuccessfullAuthInplace as setConfigBySuccessfullAuthInplaceBox,
} from "../pro/src/fsBox";
import { DEFAULT_GOOGLEDRIVE_CONFIG } from "../pro/src/fsGoogleDrive";
import { exportVaultSyncPlansToFiles } from "./debugMode";
import { FakeFsEncrypt } from "./fsEncrypt";
import { getClient } from "./fsGetter";
import { FakeFsLocal } from "./fsLocal";
import { DEFAULT_WEBDIS_CONFIG } from "./fsWebdis";
import { changeMobileStatusBar } from "./misc";
import { DEFAULT_PROFILER_CONFIG, type Profiler } from "./profiler";
import { RemotelySaveSettingTab } from "./settings";
import { syncer } from "./sync";
import { SyncAlgoV3Modal } from "./syncAlgoV3Notice";
const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
s3: DEFAULT_S3_CONFIG,
@@ -91,6 +98,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
webdis: DEFAULT_WEBDIS_CONFIG,
googledrive: DEFAULT_GOOGLEDRIVE_CONFIG,
box: DEFAULT_BOX_CONFIG,
pcloud: DEFAULT_PCLOUD_CONFIG,
password: "",
serviceType: "s3",
currLogLevel: "info",
@@ -848,6 +856,64 @@ export default class RemotelySavePlugin extends Plugin {
}
);
this.registerObsidianProtocolHandler(
COMMAND_CALLBACK_PCLOUD,
async (inputParams) => {
if (this.oauth2Info.helperModal !== undefined) {
const k = this.oauth2Info.helperModal.contentEl;
k.empty();
t("protocol_pcloud_connecting")
.split("\n")
.forEach((val) => {
k.createEl("p", {
text: val,
});
});
}
console.debug(inputParams);
const authRes = await sendAuthReqPCloud(
inputParams.hostname,
inputParams.code,
async (e: any) => {
new Notice(t("protocol_pcloud_connect_fail"));
new Notice(`${e}`);
throw e;
}
);
console.debug(authRes);
const self = this;
await setConfigBySuccessfullAuthInplacePCloud(
this.settings.pcloud!,
inputParams as unknown as AuthAllowFirstResPCloud,
authRes,
() => self.saveSettings()
);
this.oauth2Info.verifier = ""; // reset it
this.oauth2Info.helperModal?.close(); // close it
this.oauth2Info.helperModal = undefined;
this.oauth2Info.authDiv?.toggleClass(
"pcloud-auth-button-hide",
this.settings.pcloud?.accessToken !== ""
);
this.oauth2Info.authDiv = undefined;
this.oauth2Info.revokeAuthSetting?.setDesc(
t("protocol_pcloud_connect_succ_revoke")
);
this.oauth2Info.revokeAuthSetting = undefined;
this.oauth2Info.revokeDiv?.toggleClass(
"pcloud-revoke-auth-button-hide",
this.settings.pcloud?.accessToken === ""
);
this.oauth2Info.revokeDiv = undefined;
}
);
this.syncRibbon = this.addRibbonIcon(
iconNameSyncWait,
`${this.manifest.name}`,
@@ -1138,6 +1204,10 @@ export default class RemotelySavePlugin extends Plugin {
this.settings.box = DEFAULT_BOX_CONFIG;
}
if (this.settings.pcloud === undefined) {
this.settings.pcloud = DEFAULT_PCLOUD_CONFIG;
}
await this.saveSettings();
}
@@ -1226,6 +1296,16 @@ export default class RemotelySavePlugin extends Plugin {
needSave = true;
}
let pCloudExpired = false;
if (
this.settings.pcloud.accessToken !== "" &&
current >= this.settings!.pcloud!.credentialsShouldBeDeletedAtTimeMs!
) {
pCloudExpired = true;
this.settings.pcloud = cloneDeep(DEFAULT_PCLOUD_CONFIG);
needSave = true;
}
if (this.settings.pro === undefined) {
this.settings.pro = cloneDeep(DEFAULT_PRO_CONFIG);
}
@@ -1236,19 +1316,33 @@ export default class RemotelySavePlugin extends Plugin {
}
// send notice
if (dropboxExpired && onedriveExpired) {
if (dropboxExpired) {
new Notice(
`${this.manifest.name}: You haven't manually auth Dropbox and OneDrive for a while, you need to re-auth them again.`,
`${this.manifest.name}: You haven't manually auth Dropbox for many days, you need to re-auth it again.`,
6000
);
} else if (dropboxExpired) {
}
if (onedriveExpired) {
new Notice(
`${this.manifest.name}: You haven't manually auth Dropbox for a while, you need to re-auth it again.`,
`${this.manifest.name}: You haven't manually auth OneDrive for many days, you need to re-auth it again.`,
6000
);
} else if (onedriveExpired) {
}
if (googleDriveExpired) {
new Notice(
`${this.manifest.name}: You haven't manually auth OneDrive for a while, you need to re-auth it again.`,
`${this.manifest.name}: You haven't manually auth Google Drive for many days, you need to re-auth it again.`,
6000
);
}
if (boxExpired) {
new Notice(
`${this.manifest.name}: You haven't manually auth Box for many days, you need to re-auth it again.`,
6000
);
}
if (pCloudExpired) {
new Notice(
`${this.manifest.name}: You haven't manually auth pCloud for many days, you need to re-auth it again.`,
6000
);
}
+26 -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 { generatePCloudSettingsPart } from "../pro/src/settingsPCloud";
import { generateProSettingsPart } from "../pro/src/settingsPro";
import { API_VER_ENSURE_REQURL_OK, VALID_REQURL } from "./baseTypesObs";
import { messyConfigToNormal } from "./configPersist";
@@ -1818,6 +1819,15 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
this.plugin.saveSettings()
);
//////////////////////////////////////////////////
// below for box
//////////////////////////////////////////////////
const { pCloudDiv, pCloudAllowedToUsedDiv, pCloudNotShowUpHintSetting } =
generatePCloudSettingsPart(containerEl, t, this.app, this.plugin, () =>
this.plugin.saveSettings()
);
//////////////////////////////////////////////////
// below for general chooser (part 2/2)
//////////////////////////////////////////////////
@@ -1838,6 +1848,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
t("settings_chooseservice_googledrive")
);
dropdown.addOption("box", t("settings_chooseservice_box"));
dropdown.addOption("pcloud", t("settings_chooseservice_pcloud"));
dropdown
.setValue(this.plugin.settings.serviceType)
@@ -1871,6 +1882,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
"box-hide",
this.plugin.settings.serviceType !== "box"
);
pCloudDiv.toggleClass(
"pcloud-hide",
this.plugin.settings.serviceType !== "pcloud"
);
await this.plugin.saveSettings();
});
});
@@ -2439,6 +2454,12 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
button.onClick(async () => {
new ExportSettingsQrCodeModal(this.app, this.plugin, "box").open();
});
})
.addButton(async (button) => {
button.setButtonText(t("settings_export_pcloud_button"));
button.onClick(async () => {
new ExportSettingsQrCodeModal(this.app, this.plugin, "pcloud").open();
});
});
let importSettingVal = "";
@@ -2505,7 +2526,11 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
this.plugin,
() => this.plugin.saveSettings(),
googleDriveAllowedToUsedDiv,
googleDriveNotShowUpHintSetting
googleDriveNotShowUpHintSetting,
boxAllowedToUsedDiv,
boxNotShowUpHintSetting,
pCloudAllowedToUsedDiv,
pCloudNotShowUpHintSetting
);
//////////////////////////////////////////////////