This commit is contained in:
fyears
2024-06-09 13:37:55 +08:00
parent 1e4d729eb7
commit d5c2f726f9
24 changed files with 1702 additions and 76 deletions
+12 -4
View File
@@ -3,7 +3,11 @@
* To avoid circular dependency.
*/
import type { GoogleDriveConfig, ProConfig } from "../pro/src/baseTypesPro";
import type {
BoxConfig,
GoogleDriveConfig,
ProConfig,
} from "../pro/src/baseTypesPro";
import type { LangTypeAndAuto } from "./i18n";
export const DEFAULT_CONTENT_TYPE = "application/octet-stream";
@@ -14,14 +18,16 @@ export type SUPPORTED_SERVICES_TYPE =
| "dropbox"
| "onedrive"
| "webdis"
| "googledrive";
| "googledrive"
| "box";
export type SUPPORTED_SERVICES_TYPE_WITH_REMOTE_BASE_DIR =
| "webdav"
| "dropbox"
| "onedrive"
| "webdis"
| "googledrive";
| "googledrive"
| "box";
export interface S3Config {
s3Endpoint: string;
@@ -116,7 +122,8 @@ export type QRExportType =
| "onedrive"
| "webdav"
| "webdis"
| "googledrive";
| "googledrive"
| "box";
export interface ProfilerConfig {
enablePrinting?: boolean;
@@ -130,6 +137,7 @@ export interface RemotelySavePluginSettings {
onedrive: OnedriveConfig;
webdis: WebdisConfig;
googledrive: GoogleDriveConfig;
box: BoxConfig;
password: string;
serviceType: SUPPORTED_SERVICES_TYPE;
currLogLevel?: string;
+3
View File
@@ -1,3 +1,4 @@
import { FakeFsBox } from "../pro/src/fsBox";
import { FakeFsGoogleDrive } from "../pro/src/fsGoogleDrive";
import type { RemotelySavePluginSettings } from "./baseTypes";
import type { FakeFs } from "./fsAll";
@@ -48,6 +49,8 @@ export function getClient(
vaultName,
saveUpdatedConfigFunc
);
case "box":
return new FakeFsBox(settings.box, vaultName, saveUpdatedConfigFunc);
default:
throw Error(`cannot init client for serviceType=${settings.serviceType}`);
}
+3
View File
@@ -25,6 +25,7 @@ export const exportQrCodeUri = async (
delete settings2.webdav;
delete settings2.webdis;
delete settings2.googledrive;
delete settings2.box;
delete settings2.pro;
} else if (exportFields === "s3") {
settings2 = { s3: cloneDeep(settings.s3) };
@@ -38,6 +39,8 @@ export const exportQrCodeUri = async (
settings2 = { webdis: cloneDeep(settings.webdis) };
} else if (exportFields === "googledrive") {
settings2 = { googledrive: cloneDeep(settings.googledrive) };
} else if (exportFields === "box") {
settings2 = { box: cloneDeep(settings.box) };
}
delete settings2.vaultRandomID;
+91 -1
View File
@@ -63,7 +63,16 @@ import { SyncAlgoV3Modal } from "./syncAlgoV3Notice";
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
import AggregateError from "aggregate-error";
import throttle from "lodash/throttle";
import { COMMAND_CALLBACK_PRO } from "../pro/src/baseTypesPro";
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";
@@ -81,6 +90,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
onedrive: DEFAULT_ONEDRIVE_CONFIG,
webdis: DEFAULT_WEBDIS_CONFIG,
googledrive: DEFAULT_GOOGLEDRIVE_CONFIG,
box: DEFAULT_BOX_CONFIG,
password: "",
serviceType: "s3",
currLogLevel: "info",
@@ -782,6 +792,62 @@ export default class RemotelySavePlugin extends Plugin {
}
);
this.registerObsidianProtocolHandler(
COMMAND_CALLBACK_BOX,
async (inputParams) => {
if (this.oauth2Info.helperModal !== undefined) {
const k = this.oauth2Info.helperModal.contentEl;
k.empty();
t("protocol_box_connecting")
.split("\n")
.forEach((val) => {
k.createEl("p", {
text: val,
});
});
}
console.debug(inputParams);
const authRes = await sendAuthReqBox(
inputParams.code,
async (e: any) => {
new Notice(t("protocol_box_connect_fail"));
new Notice(`${e}`);
throw e;
}
);
console.debug(authRes);
const self = this;
await setConfigBySuccessfullAuthInplaceBox(
this.settings.box!,
authRes,
() => self.saveSettings()
);
this.oauth2Info.verifier = ""; // reset it
this.oauth2Info.helperModal?.close(); // close it
this.oauth2Info.helperModal = undefined;
this.oauth2Info.authDiv?.toggleClass(
"box-auth-button-hide",
this.settings.box?.refreshToken !== ""
);
this.oauth2Info.authDiv = undefined;
this.oauth2Info.revokeAuthSetting?.setDesc(
t("protocol_box_connect_succ_revoke")
);
this.oauth2Info.revokeAuthSetting = undefined;
this.oauth2Info.revokeDiv?.toggleClass(
"box-revoke-auth-button-hide",
this.settings.box?.refreshToken === ""
);
this.oauth2Info.revokeDiv = undefined;
}
);
this.syncRibbon = this.addRibbonIcon(
iconNameSyncWait,
`${this.manifest.name}`,
@@ -1068,6 +1134,10 @@ export default class RemotelySavePlugin extends Plugin {
this.settings.googledrive = DEFAULT_GOOGLEDRIVE_CONFIG;
}
if (this.settings.box === undefined) {
this.settings.box = DEFAULT_BOX_CONFIG;
}
await this.saveSettings();
}
@@ -1136,6 +1206,26 @@ export default class RemotelySavePlugin extends Plugin {
needSave = true;
}
let googleDriveExpired = false;
if (
this.settings.googledrive.refreshToken !== "" &&
current >= this.settings!.googledrive!.credentialsShouldBeDeletedAtTimeMs!
) {
googleDriveExpired = true;
this.settings.googledrive = cloneDeep(DEFAULT_GOOGLEDRIVE_CONFIG);
needSave = true;
}
let boxExpired = false;
if (
this.settings.box.refreshToken !== "" &&
current >= this.settings!.box!.credentialsShouldBeDeletedAtTimeMs!
) {
boxExpired = true;
this.settings.box = cloneDeep(DEFAULT_BOX_CONFIG);
needSave = true;
}
if (this.settings.pro === undefined) {
this.settings.pro = cloneDeep(DEFAULT_PRO_CONFIG);
}
+11
View File
@@ -716,3 +716,14 @@ export const splitFileSizeToChunkRanges = (
}
return res;
};
export const getSha1 = async (x: ArrayBuffer, stringify: "base64" | "hex") => {
const y = await window.crypto.subtle.digest("SHA-1", x);
if (stringify === "base64") {
return arrayBufferToBase64(y);
} else if (stringify === "hex") {
return arrayBufferToHex(y);
}
throw Error(`not supported stringify option = ${stringify}`);
};
+21
View File
@@ -21,6 +21,7 @@ import type {
} from "./baseTypes";
import cloneDeep from "lodash/cloneDeep";
import { generateBoxSettingsPart } from "../pro/src/settingsBox";
import { generateGoogleDriveSettingsPart } from "../pro/src/settingsGoogleDrive";
import { generateProSettingsPart } from "../pro/src/settingsPro";
import { API_VER_ENSURE_REQURL_OK, VALID_REQURL } from "./baseTypesObs";
@@ -1808,6 +1809,15 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
() => this.plugin.saveSettings()
);
//////////////////////////////////////////////////
// below for box
//////////////////////////////////////////////////
const { boxDiv, boxAllowedToUsedDiv, boxNotShowUpHintSetting } =
generateBoxSettingsPart(containerEl, t, this.app, this.plugin, () =>
this.plugin.saveSettings()
);
//////////////////////////////////////////////////
// below for general chooser (part 2/2)
//////////////////////////////////////////////////
@@ -1827,6 +1837,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
"googledrive",
t("settings_chooseservice_googledrive")
);
dropdown.addOption("box", t("settings_chooseservice_box"));
dropdown
.setValue(this.plugin.settings.serviceType)
@@ -1856,6 +1867,10 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
"googledrive-hide",
this.plugin.settings.serviceType !== "googledrive"
);
boxDiv.toggleClass(
"box-hide",
this.plugin.settings.serviceType !== "box"
);
await this.plugin.saveSettings();
});
});
@@ -2418,6 +2433,12 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
"googledrive"
).open();
});
})
.addButton(async (button) => {
button.setButtonText(t("settings_export_box_button"));
button.onClick(async () => {
new ExportSettingsQrCodeModal(this.app, this.plugin, "box").open();
});
});
let importSettingVal = "";
+1 -6
View File
@@ -1507,12 +1507,7 @@ export async function syncer(
try {
// check pro feature
// if anything goes wrong, it will throw
await checkProRunnableAndFixInplace(
["feature-smart_conflict", "feature-google_drive"],
settings,
pluginVersion,
configSaver
);
await checkProRunnableAndFixInplace(settings, pluginVersion, configSaver);
// try mode?
await notifyFunc?.(triggerSource, step);