DocSpace-buildtools/web/ASC.Web.Common/src/desktop/index.js

150 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-11-10 14:37:44 +00:00
import { toastr } from "asc-web-common";
2020-11-12 08:50:21 +00:00
import {
setEncryptionKeys as setKeys,
2020-11-12 16:03:54 +00:00
//getEncryptionAccess,
2020-11-12 08:50:21 +00:00
} from "../store/auth/actions";
2020-11-13 16:05:49 +00:00
import assign from "lodash/assign";
import isEmpty from "lodash/isEmpty";
//import { store } from "asc-web-common";
2020-11-12 16:03:54 +00:00
// const { isDesktopClient, isEncryptionSupport } = store.auth.selectors;
2020-11-13 16:05:49 +00:00
//const state = store.getState();
2020-11-10 14:37:44 +00:00
2020-11-05 11:13:06 +00:00
const domain = window.location.origin;
const provider = "AppServer";
2020-11-11 12:47:37 +00:00
const guid = "{FFF0E1EB-13DB-4678-B67D-FF0A41DBBCEF}";
2020-11-12 16:03:54 +00:00
const desktop = window["AscDesktopEditor"] !== undefined;
const encryption =
(desktop &&
typeof window.AscDesktopEditor.cloudCryptoCommand === "function") ||
false;
2020-11-13 16:05:49 +00:00
const encryptionKeyPair = {
privateKeyEnc: "1",
publicKey: "2",
};
2020-11-10 14:37:44 +00:00
2020-11-13 16:05:49 +00:00
export function regDesktop(user, isEncryption) {
if (!desktop) return;
const data = {
displayName: user.displayName,
email: user.email,
domain,
provider,
userId: user.id,
2020-11-10 14:37:44 +00:00
};
2020-11-13 16:05:49 +00:00
if (isEncryption) {
assign(data, {
encryptionKeys: {
cryptoEngineId: guid,
},
});
if (!isEmpty(encryptionKeyPair)) {
assign(data, {
encryptionKeys: {
cryptoEngineId: guid,
privateKeyEnc: encryptionKeyPair.privateKeyEnc,
publicKey: encryptionKeyPair.publicKey,
},
});
} else assign(data, {});
}
console.log("regdesktop");
window.AscDesktopEditor.execCommand("portal:login", JSON.stringify(data));
2020-11-10 14:37:44 +00:00
window.onSystemMessage = (e) => {
2020-11-13 16:05:49 +00:00
console.log("onSystemMessage: ", e);
2020-11-10 14:37:44 +00:00
let message = e.opMessage;
switch (e.type) {
case "operation":
if (!message) {
switch (e.opType) {
case 0:
message = "Preparing file for encryption";
break;
case 1:
message = "Encrypting file";
break;
default:
message = "Loading...";
}
}
return toastr.info(message);
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 16:03:54 +00:00
2020-11-13 16:05:49 +00:00
if (isEncryption) {
window.cloudCryptoCommand = (type, params, callback) => {
console.log("cloudCryptoCommand", params);
switch (type) {
case "encryptionKeys":
setEncryptionKeys(params);
break;
case "relogin":
relogin();
break;
case "getsharingkeys":
break;
default:
break;
}
};
2020-11-03 06:52:05 +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() {
toastr.info("Encryption keys must be re-entered");
const data = {
domain,
onsuccess: "reload",
};
const execCommand = setTimeout(() => {
window.AscDesktopEditor.execCommand("portal:logout", JSON.stringify(data));
}, 1000);
return execCommand;
}
2020-11-05 11:13:06 +00:00
2020-11-12 08:50:21 +00:00
export function setEncryptionKeys(encryptionKeys) {
2020-11-12 16:03:54 +00:00
console.log("encryptionKeys: ", encryptionKeys);
2020-11-12 08:50:21 +00:00
if (!encryptionKeys.publicKey || !encryptionKeys.privateKeyEnc) {
return toastr.info("Empty encryption keys");
2020-11-03 06:52:05 +00:00
}
2020-11-12 08:50:21 +00:00
const data = {
publicKey: encryptionKeys.publicKey,
privateKeyEnc: encryptionKeys.privateKeyEnc,
};
return setKeys(data);
}
2020-11-03 06:52:05 +00:00
2020-11-12 08:50:21 +00:00
export function checkPwd() {
const data = {
domain,
emailInput: "login",
pwdInput: "password",
};
const execCommand = window.AscDesktopEditor.execCommand(
"portal:checkpwd",
JSON.stringify(data)
);
2020-11-03 06:52:05 +00:00
2020-11-12 08:50:21 +00:00
return execCommand;
}
2020-11-03 06:52:05 +00:00
2020-11-12 08:50:21 +00:00
export function logout() {
const data = {
domain,
};
const execCommand = window.AscDesktopEditor.execCommand(
"portal:logout",
JSON.stringify(data)
);
return execCommand;
2020-11-03 06:52:05 +00:00
}