DocSpace-client/packages/asc-web-common/desktop/index.js

130 lines
2.9 KiB
JavaScript
Raw Normal View History

import toastr from "@appserver/components/toast/toastr";
2020-11-13 16:05:49 +00:00
import isEmpty from "lodash/isEmpty";
2020-11-23 14:28:24 +00:00
import omit from "lodash/omit";
2020-12-04 09:59:48 +00:00
export const desktopConstants = Object.freeze({
domain: window.location.origin,
provider: "onlyoffice",
cryptoEngineId: "{FFF0E1EB-13DB-4678-B67D-FF0A41DBBCEF}",
2020-12-04 09:59:48 +00:00
});
2020-11-13 16:05:49 +00:00
2020-12-28 07:40:50 +00:00
export function regDesktop(
user,
isEncryption,
keys,
setEncryptionKeys,
isEditor,
getEncryptionAccess,
t
2020-12-28 07:40:50 +00:00
) {
2020-11-13 16:05:49 +00:00
const data = {
displayName: user.displayName,
email: user.email,
2020-12-04 09:59:48 +00:00
domain: desktopConstants.domain,
provider: desktopConstants.provider,
2020-11-13 16:05:49 +00:00
userId: user.id,
2020-11-10 14:37:44 +00:00
};
console.log("regDesktop", data);
2020-11-18 17:22:52 +00:00
let extendedData;
2020-11-16 14:42:29 +00:00
2020-11-13 16:05:49 +00:00
if (isEncryption) {
2020-11-16 14:42:29 +00:00
extendedData = {
...data,
2020-11-13 16:05:49 +00:00
encryptionKeys: {
cryptoEngineId: desktopConstants.cryptoEngineId,
2020-11-13 16:05:49 +00:00
},
2020-11-16 14:42:29 +00:00
};
2020-11-13 16:05:49 +00:00
2020-11-16 09:34:18 +00:00
if (!isEmpty(keys)) {
2020-11-23 14:28:24 +00:00
const filteredKeys = omit(keys, ["userId"]);
2020-11-16 14:42:29 +00:00
extendedData = {
...extendedData,
2020-11-23 14:28:24 +00:00
encryptionKeys: { ...extendedData.encryptionKeys, ...filteredKeys },
2020-11-16 14:42:29 +00:00
};
2020-11-13 18:45:28 +00:00
}
2020-11-18 17:22:52 +00:00
} else {
extendedData = { ...data };
2020-11-13 16:05:49 +00:00
}
2020-11-16 14:42:29 +00:00
window.AscDesktopEditor.execCommand(
"portal:login",
JSON.stringify(extendedData)
);
2020-11-13 16:05:49 +00:00
2020-11-19 15:30:29 +00:00
if (isEncryption) {
window.cloudCryptoCommand = (type, params, callback) => {
switch (type) {
case "encryptionKeys": {
setEncryptionKeys(params);
break;
}
case "relogin": {
toastr.info(t("Common:EncryptionKeysReload"));
2020-11-19 15:30:29 +00:00
//relogin();
break;
}
case "getsharingkeys":
if (!isEditor || typeof getEncryptionAccess !== "function") {
callback({});
return;
}
getEncryptionAccess(callback);
2020-11-19 15:30:29 +00:00
break;
default:
break;
}
};
}
2020-11-18 17:22:52 +00:00
2020-11-10 14:37:44 +00:00
window.onSystemMessage = (e) => {
let message = e.opMessage;
switch (e.type) {
case "operation":
if (!message) {
switch (e.opType) {
case 0:
message = t("Common:EncryptionFilePreparing");
2020-11-10 14:37:44 +00:00
break;
case 1:
message = t("Common:EncryptingFile");
2020-11-10 14:37:44 +00:00
break;
default:
message = t("Common:LoadingProcessing");
2020-11-10 14:37:44 +00:00
}
}
2020-11-13 18:45:28 +00:00
toastr.info(message);
break;
2020-11-05 11:13:06 +00:00
default:
2020-11-10 14:37:44 +00:00
break;
2020-11-05 11:13:06 +00:00
}
};
2020-11-12 08:50:21 +00:00
}
2020-11-03 06:52:05 +00:00
2020-11-12 08:50:21 +00:00
export function relogin() {
2020-11-13 18:45:28 +00:00
setTimeout(() => {
const data = {
2020-12-04 09:59:48 +00:00
domain: desktopConstants.domain,
2020-11-13 18:45:28 +00:00
onsuccess: "reload",
};
2020-11-12 08:50:21 +00:00
window.AscDesktopEditor.execCommand("portal:logout", JSON.stringify(data));
}, 1000);
}
2020-11-05 11:13:06 +00:00
2020-11-12 08:50:21 +00:00
export function checkPwd() {
const data = {
2020-12-04 09:59:48 +00:00
domain: desktopConstants.domain,
2020-11-12 08:50:21 +00:00
emailInput: "login",
pwdInput: "password",
};
2020-11-13 18:45:28 +00:00
window.AscDesktopEditor.execCommand("portal:checkpwd", JSON.stringify(data));
2020-11-12 08:50:21 +00:00
}
2020-11-03 06:52:05 +00:00
2020-11-12 08:50:21 +00:00
export function logout() {
const data = {
2020-12-04 09:59:48 +00:00
domain: desktopConstants.domain,
2020-11-12 08:50:21 +00:00
};
2020-11-13 18:45:28 +00:00
window.AscDesktopEditor.execCommand("portal:logout", JSON.stringify(data));
2020-11-03 06:52:05 +00:00
}