2021-05-03 09:25:42 +01:00
|
|
|
import { CopyableModal } from "../../elements/CopyableModal.js";
|
|
|
|
import { Margin } from "../../elements/Margin.js";
|
2021-04-17 10:45:42 +01:00
|
|
|
import { Page } from "../../types/Page.js";
|
2021-05-03 09:25:42 +01:00
|
|
|
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js";
|
2021-04-17 10:45:42 +01:00
|
|
|
import { makeElement } from "../../htmlUtils.js";
|
2021-05-07 11:07:03 +01:00
|
|
|
import { pageState } from "../../globalPageState.js";
|
2021-05-07 11:53:26 +01:00
|
|
|
import { transitDecrypt } from "../../api/transitDecrypt";
|
2021-04-17 10:39:07 +01:00
|
|
|
import UIkit from 'uikit/dist/js/uikit.min.js';
|
2021-04-29 11:03:24 +01:00
|
|
|
import i18next from "i18next";
|
2021-04-17 10:39:07 +01:00
|
|
|
|
|
|
|
export class TransitDecryptPage extends Page {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
goBack() {
|
2021-04-17 11:24:43 +01:00
|
|
|
changePage("TRANSIT_VIEW_SECRET");
|
2021-04-17 10:39:07 +01:00
|
|
|
}
|
|
|
|
async render() {
|
|
|
|
setTitleElement(pageState);
|
|
|
|
setPageContent(makeElement({
|
|
|
|
tag: "div"
|
|
|
|
}));
|
|
|
|
this.transitDecryptForm = makeElement({
|
|
|
|
tag: "form",
|
|
|
|
children: [
|
|
|
|
Margin(makeElement({
|
|
|
|
tag: "textarea",
|
|
|
|
class: ["uk-textarea", "uk-form-width-medium"],
|
|
|
|
attributes: {
|
2021-04-29 11:03:24 +01:00
|
|
|
placeholder: i18next.t("transit_decrypt_input_placeholder"),
|
2021-04-17 10:39:07 +01:00
|
|
|
name: "ciphertext",
|
|
|
|
}
|
|
|
|
})),
|
2021-04-17 12:53:55 +01:00
|
|
|
Margin([
|
|
|
|
makeElement({
|
|
|
|
tag: "div",
|
|
|
|
class: "uk-form-label",
|
2021-04-29 11:03:24 +01:00
|
|
|
text: i18next.t("transit_decrypt_decode_checkbox"),
|
2021-04-17 12:53:55 +01:00
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "div",
|
|
|
|
class: ["uk-form-controls", "uk-form-controls-text"],
|
|
|
|
children: makeElement({
|
|
|
|
tag: "input",
|
2021-04-30 19:35:34 +01:00
|
|
|
class: "uk-checkbox",
|
2021-04-17 12:53:55 +01:00
|
|
|
attributes: {
|
|
|
|
type: "checkbox",
|
|
|
|
name: "decodeBase64Checkbox",
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
]),
|
2021-04-17 10:39:07 +01:00
|
|
|
makeElement({
|
|
|
|
tag: "p",
|
|
|
|
id: "errorText",
|
|
|
|
class: "uk-text-danger"
|
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "button",
|
|
|
|
class: ["uk-button", "uk-button-primary"],
|
2021-04-29 11:03:24 +01:00
|
|
|
text: i18next.t("transit_decrypt_decrypt_btn"),
|
2021-04-17 10:39:07 +01:00
|
|
|
attributes: {
|
|
|
|
type: "submit",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
|
|
|
setPageContent(this.transitDecryptForm);
|
|
|
|
this.transitDecryptForm.addEventListener("submit", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.transitEncryptFormHandler();
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
transitEncryptFormHandler() {
|
|
|
|
let formData = new FormData(this.transitDecryptForm);
|
|
|
|
|
|
|
|
transitDecrypt(pageState.currentBaseMount, pageState.currentSecret, formData.get("ciphertext")).then(res => {
|
2021-04-17 12:53:55 +01:00
|
|
|
let plaintext = res.plaintext;
|
|
|
|
if (formData.get("decodeBase64Checkbox") == "on") {
|
|
|
|
plaintext = atob(plaintext);
|
|
|
|
}
|
2021-04-29 11:03:24 +01:00
|
|
|
let modal = CopyableModal(i18next.t("transit_decrypt_decryption_result_modal_title"), plaintext);
|
2021-04-17 10:39:07 +01:00
|
|
|
pageContent.appendChild(modal);
|
|
|
|
UIkit.modal(modal).show();
|
|
|
|
}).catch(e => {
|
|
|
|
setErrorText(`API Error: ${e.message}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-20 20:32:57 +01:00
|
|
|
get titleSuffix() {
|
2021-04-29 11:03:24 +01:00
|
|
|
return i18next.t("transit_decrypt_suffix");
|
2021-04-17 11:06:34 +01:00
|
|
|
}
|
|
|
|
|
2021-04-17 10:39:07 +01:00
|
|
|
get name() {
|
2021-04-29 11:03:24 +01:00
|
|
|
return i18next.t("transit_decrypt_title");
|
2021-04-17 10:39:07 +01:00
|
|
|
}
|
|
|
|
}
|