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

161 lines
3.6 KiB
JavaScript
Raw Normal View History

import toastr from "@docspace/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";
import { checkIsSSR } from "../utils";
const isSSR = checkIsSSR();
2020-12-04 09:59:48 +00:00
export const desktopConstants = Object.freeze({
domain: !isSSR && 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
) {
if (!isSSR) {
const data = {
displayName: user.displayName,
email: user.email,
domain: desktopConstants.domain,
provider: desktopConstants.provider,
userId: user.id,
};
console.log(
"regDesktop date=",
data,
`isEncryption=${isEncryption} keys=${keys} isEditor=${isEditor}`
);
2020-11-16 14:42:29 +00:00
let extendedData;
2020-11-13 16:05:49 +00:00
if (isEncryption) {
2020-11-16 14:42:29 +00:00
extendedData = {
...data,
encryptionKeys: {
cryptoEngineId: desktopConstants.cryptoEngineId,
},
2020-11-16 14:42:29 +00:00
};
if (!isEmpty(keys)) {
const filteredKeys = omit(keys, ["userId"]);
extendedData = {
...extendedData,
encryptionKeys: { ...extendedData.encryptionKeys, ...filteredKeys },
};
}
} else {
extendedData = { ...data };
2020-11-13 18:45:28 +00:00
}
2020-11-13 16:05:49 +00:00
window.AscDesktopEditor.execCommand(
"portal:login",
JSON.stringify(extendedData)
);
2020-11-13 16:05:49 +00:00
if (isEncryption) {
window.cloudCryptoCommand = (type, params, callback) => {
switch (type) {
case "encryptionKeys": {
setEncryptionKeys(params);
break;
}
case "updateEncryptionKeys": {
setEncryptionKeys(params);
break;
}
case "relogin": {
toastr.info(t("Common:EncryptionKeysReload"));
//relogin();
break;
}
case "getsharingkeys":
if (!isEditor || typeof getEncryptionAccess !== "function") {
callback({});
return;
}
getEncryptionAccess(callback);
break;
default:
break;
2020-11-19 15:30:29 +00:00
}
};
console.log(
"Created window.cloudCryptoCommand",
window.cloudCryptoCommand
);
}
window.onSystemMessage = (e) => {
let message = e.opMessage;
switch (e.type) {
case "operation":
if (!message) {
switch (e.opType) {
case 0:
message = t("Common:EncryptionFilePreparing");
break;
case 1:
message = t("Common:EncryptingFile");
break;
default:
message = t("Common:LoadingProcessing");
}
}
toastr.info(message);
2020-11-19 15:30:29 +00:00
break;
default:
break;
}
};
console.log("Created window.onSystemMessage", window.onSystemMessage);
2020-11-19 15:30:29 +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() {
if (!isSSR)
setTimeout(() => {
const data = {
domain: desktopConstants.domain,
onsuccess: "reload",
};
window.AscDesktopEditor.execCommand(
"portal:logout",
JSON.stringify(data)
);
}, 1000);
2020-11-12 08:50:21 +00:00
}
2020-11-05 11:13:06 +00:00
2020-11-12 08:50:21 +00:00
export function checkPwd() {
if (!isSSR) {
const data = {
domain: desktopConstants.domain,
emailInput: "login",
pwdInput: "password",
};
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() {
if (!isSSR) {
const data = {
domain: desktopConstants.domain,
};
window.AscDesktopEditor.execCommand("portal:logout", JSON.stringify(data));
}
2020-11-03 06:52:05 +00:00
}