1
0
Fork 0

Add typing to TransitEncrypt.ts

This commit is contained in:
Kitteh 2021-05-08 03:36:26 +01:00
parent d34518650b
commit 8a33dfd36f
3 changed files with 20 additions and 14 deletions

2
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,2 @@
{
}

View file

@ -14,7 +14,7 @@ import { SetLanguagePage } from "./pages/SetLanguage";
import { SetVaultURLPage } from "./pages/SetVaultURL"; import { SetVaultURLPage } from "./pages/SetVaultURL";
import { TOTPViewPage } from "./pages/TOTP/TOTPView"; import { TOTPViewPage } from "./pages/TOTP/TOTPView";
import { TransitDecryptPage } from "./pages/Transit/TransitDecrypt"; import { TransitDecryptPage } from "./pages/Transit/TransitDecrypt";
import { TransitEncryptPage } from "./pages/Transit/TransitEncrypt.js"; import { TransitEncryptPage } from "./pages/Transit/TransitEncrypt";
import { TransitViewPage } from "./pages/Transit/TransitView"; import { TransitViewPage } from "./pages/Transit/TransitView";
import { TransitViewSecretPage } from "./pages/Transit/TransitViewSecret"; import { TransitViewSecretPage } from "./pages/Transit/TransitViewSecret";
import { UnsealPage } from "./pages/Unseal"; import { UnsealPage } from "./pages/Unseal";

View file

@ -3,7 +3,7 @@ import { Margin } from "../../elements/Margin";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils"; import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "../../htmlUtils";
import { pageState } from "../../globalPageState.ts"; import { pageState } from "../../globalPageState";
import { transitEncrypt } from "../../api/transitEncrypt"; import { transitEncrypt } from "../../api/transitEncrypt";
import UIkit from 'uikit/dist/js/uikit.min.js'; import UIkit from 'uikit/dist/js/uikit.min.js';
import i18next from "i18next"; import i18next from "i18next";
@ -13,10 +13,15 @@ export class TransitEncryptPage extends Page {
constructor() { constructor() {
super(); super();
} }
goBack() {
goBack(): void {
changePage("TRANSIT_VIEW_SECRET"); changePage("TRANSIT_VIEW_SECRET");
} }
async render() {
transitEncryptForm: HTMLFormElement;
async render(): Promise<void> {
setTitleElement(pageState); setTitleElement(pageState);
setPageContent(makeElement({ setPageContent(makeElement({
tag: "div" tag: "div"
@ -65,7 +70,7 @@ export class TransitEncryptPage extends Page {
} }
}) })
] ]
}); }) as HTMLFormElement;
setPageContent(this.transitEncryptForm); setPageContent(this.transitEncryptForm);
this.transitEncryptForm.addEventListener("submit", function (e) { this.transitEncryptForm.addEventListener("submit", function (e) {
@ -74,25 +79,24 @@ export class TransitEncryptPage extends Page {
}.bind(this)); }.bind(this));
} }
transitEncryptFormHandler() { transitEncryptFormHandler(): void {
let formData = new FormData(this.transitEncryptForm); const formData = new FormData(this.transitEncryptForm);
let encodedData = const encodedData =
formData.get("base64Checkbox") == "on" ? formData.get("plaintext") : btoa(formData.get("plaintext")); formData.get("base64Checkbox") as string == "on" ? formData.get("plaintext") as string : btoa(formData.get("plaintext") as string);
transitEncrypt(pageState.currentBaseMount, pageState.currentSecret, encodedData).then(res => { transitEncrypt(pageState.currentBaseMount, pageState.currentSecret, encodedData).then(res => {
console.log(res); const modal = CopyableModal(i18next.t("transit_encrypt_encryption_result_modal_title"), res.ciphertext);
let modal = CopyableModal(i18next.t("transit_encrypt_encryption_result_modal_title"), res.ciphertext); document.body.querySelector("#pageContent").appendChild(modal);
pageContent.appendChild(modal);
UIkit.modal(modal).show(); UIkit.modal(modal).show();
}).catch(e => { }).catch(e => {
setErrorText(`API Error: ${e.message}`); setErrorText(`API Error: ${e.message}`);
}); });
} }
get titleSuffix() { get titleSuffix(): string {
return i18next.t("transit_encrypt_suffix"); return i18next.t("transit_encrypt_suffix");
} }
get name() { get name(): string {
return i18next.t("transit_encrypt_title"); return i18next.t("transit_encrypt_title");
} }
} }