Use async more.
This commit is contained in:
parent
b3470be6f1
commit
c29dbfd766
|
@ -28,6 +28,12 @@
|
||||||
"argsIgnorePattern": "^_"
|
"argsIgnorePattern": "^_"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"@typescript-eslint/no-misused-promises": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"checksVoidReturn": false
|
||||||
|
}
|
||||||
|
],
|
||||||
"@typescript-eslint/require-await": ["off"],
|
"@typescript-eslint/require-await": ["off"],
|
||||||
"@typescript-eslint/no-empty-function": ["off"],
|
"@typescript-eslint/no-empty-function": ["off"],
|
||||||
"@typescript-eslint/ban-ts-comment": ["off"],
|
"@typescript-eslint/ban-ts-comment": ["off"],
|
||||||
|
|
|
@ -53,9 +53,9 @@ export class KeyValueNewPage extends Page {
|
||||||
}) as HTMLFormElement;
|
}) as HTMLFormElement;
|
||||||
setPageContent(this.addKVNewForm);
|
setPageContent(this.addKVNewForm);
|
||||||
|
|
||||||
this.addKVNewForm.addEventListener("submit", (e: Event) => {
|
this.addKVNewForm.addEventListener("submit", async (e: Event) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void this.newKVSecretHandleForm();
|
await this.newKVSecretHandleForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,37 +132,42 @@ export class LoginPage extends Page {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
tokenLoginForm.addEventListener("submit", function (e) {
|
tokenLoginForm.addEventListener("submit", async function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const formData = new FormData(tokenLoginForm);
|
const formData = new FormData(tokenLoginForm);
|
||||||
const token = formData.get("token");
|
const token = formData.get("token");
|
||||||
pageState.token = token as string;
|
pageState.token = token as string;
|
||||||
lookupSelf()
|
|
||||||
.then((_) => {
|
try {
|
||||||
void changePage("HOME");
|
await lookupSelf();
|
||||||
})
|
await changePage("HOME");
|
||||||
.catch((e: Error) => {
|
} catch (e: unknown) {
|
||||||
|
const error = e as Error;
|
||||||
document.getElementById("tokenInput").classList.add("uk-form-danger");
|
document.getElementById("tokenInput").classList.add("uk-form-danger");
|
||||||
if (e.message == "permission denied") {
|
if (error.message == "permission denied") {
|
||||||
setErrorText(i18next.t("token_login_error"));
|
setErrorText(i18next.t("token_login_error"));
|
||||||
} else {
|
} else {
|
||||||
setErrorText(e.message);
|
setErrorText(error.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
usernameLoginForm.addEventListener("submit", async function (e) {
|
||||||
usernameLoginForm.addEventListener("submit", function (e) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const formData = new FormData(usernameLoginForm);
|
const formData = new FormData(usernameLoginForm);
|
||||||
usernameLogin(formData.get("username") as string, formData.get("password") as string)
|
|
||||||
.then((res) => {
|
try {
|
||||||
|
const res = await usernameLogin(
|
||||||
|
formData.get("username") as string,
|
||||||
|
formData.get("password") as string,
|
||||||
|
);
|
||||||
pageState.token = res;
|
pageState.token = res;
|
||||||
void changePage("HOME");
|
await changePage("HOME");
|
||||||
})
|
} catch (e: unknown) {
|
||||||
.catch((e: Error) => {
|
const error = e as Error;
|
||||||
document.getElementById("usernameInput").classList.add("uk-form-danger");
|
document.getElementById("usernameInput").classList.add("uk-form-danger");
|
||||||
document.getElementById("passwordInput").classList.add("uk-form-danger");
|
document.getElementById("passwordInput").classList.add("uk-form-danger");
|
||||||
setErrorText(e.message);
|
setErrorText(error.message);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,17 +52,17 @@ export class SetLanguagePage extends Page {
|
||||||
],
|
],
|
||||||
}) as HTMLFormElement;
|
}) as HTMLFormElement;
|
||||||
setPageContent(setLanguageForm);
|
setPageContent(setLanguageForm);
|
||||||
setLanguageForm.addEventListener("submit", function (e) {
|
setLanguageForm.addEventListener("submit", async function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const formData = new FormData(setLanguageForm);
|
const formData = new FormData(setLanguageForm);
|
||||||
|
|
||||||
const language = formData.get("language") as string;
|
const language = formData.get("language") as string;
|
||||||
pageState.language = language;
|
pageState.language = language;
|
||||||
console.log(pageState.language);
|
|
||||||
void i18next.changeLanguage(language).then((t) => {
|
const t = await i18next.changeLanguage(language);
|
||||||
pageState.pageDirection = t("language_direction");
|
pageState.pageDirection = t("language_direction");
|
||||||
reloadNavBar();
|
reloadNavBar();
|
||||||
void changePage("HOME");
|
await changePage("HOME");
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -43,11 +43,11 @@ export class SetVaultURLPage extends Page {
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
document.getElementById("setVaultURLForm").addEventListener("submit", function (e) {
|
document.getElementById("setVaultURLForm").addEventListener("submit", async function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const formData = new FormData(document.querySelector("#setVaultURLForm"));
|
const formData = new FormData(document.querySelector("#setVaultURLForm"));
|
||||||
pageState.apiURL = formData.get("vaultURL") as string;
|
pageState.apiURL = formData.get("vaultURL") as string;
|
||||||
void changePage("HOME");
|
await changePage("HOME");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -86,22 +86,25 @@ export class NewTOTPPage extends Page {
|
||||||
}) as HTMLFormElement;
|
}) as HTMLFormElement;
|
||||||
setPageContent(totpForm);
|
setPageContent(totpForm);
|
||||||
|
|
||||||
totpForm.addEventListener("submit", function (e) {
|
totpForm.addEventListener("submit", async function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const formData = new FormData(totpForm);
|
const formData = new FormData(totpForm);
|
||||||
|
|
||||||
const parms = {
|
const parms = {
|
||||||
url: formData.get("uri") as string,
|
url: formData.get("uri") as string,
|
||||||
key: removeDashSpaces(formData.get("key") as string).toUpperCase(),
|
key: removeDashSpaces(formData.get("key") as string).toUpperCase(),
|
||||||
name: formData.get("name") as string,
|
name: formData.get("name") as string,
|
||||||
generate: false,
|
generate: false,
|
||||||
};
|
};
|
||||||
addNewTOTP(pageState.currentBaseMount, parms)
|
|
||||||
.then((_) => {
|
try {
|
||||||
void changePage("TOTP");
|
await addNewTOTP(pageState.currentBaseMount, parms);
|
||||||
})
|
await changePage("TOTP");
|
||||||
.catch((e: Error) => {
|
} catch (e: unknown) {
|
||||||
setErrorText(`API Error: ${e.message}`);
|
const error = e as Error;
|
||||||
});
|
setErrorText(`API Error: ${error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@ export class TOTPViewPage extends Page {
|
||||||
try {
|
try {
|
||||||
const res = await getTOTPKeys(pageState.currentBaseMount);
|
const res = await getTOTPKeys(pageState.currentBaseMount);
|
||||||
for (const totpKeyName of res) {
|
for (const totpKeyName of res) {
|
||||||
console.log(totpKeyName);
|
|
||||||
const totpListElement = this.makeTOTPListElement(totpKeyName);
|
const totpListElement = this.makeTOTPListElement(totpKeyName);
|
||||||
totpList.appendChild(totpListElement);
|
totpList.appendChild(totpListElement);
|
||||||
this.totpListElements[totpKeyName] = totpListElement;
|
this.totpListElements[totpKeyName] = totpListElement;
|
||||||
|
|
|
@ -75,9 +75,9 @@ export class TransitDecryptPage extends Page {
|
||||||
],
|
],
|
||||||
}) as HTMLFormElement;
|
}) as HTMLFormElement;
|
||||||
setPageContent(this.transitDecryptForm);
|
setPageContent(this.transitDecryptForm);
|
||||||
this.transitDecryptForm.addEventListener("submit", (e: Event) => {
|
this.transitDecryptForm.addEventListener("submit", async (e: Event) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void this.transitDecryptFormHandler();
|
await this.transitDecryptFormHandler();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,9 +76,9 @@ export class TransitEncryptPage extends Page {
|
||||||
}) as HTMLFormElement;
|
}) as HTMLFormElement;
|
||||||
setPageContent(this.transitEncryptForm);
|
setPageContent(this.transitEncryptForm);
|
||||||
|
|
||||||
this.transitEncryptForm.addEventListener("submit", (e: Event) => {
|
this.transitEncryptForm.addEventListener("submit", async (e: Event) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void this.transitEncryptFormHandler();
|
await this.transitEncryptFormHandler();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,9 +84,9 @@ export class TransitRewrapPage extends Page {
|
||||||
}) as HTMLFormElement;
|
}) as HTMLFormElement;
|
||||||
setPageContent(this.transitRewrapForm);
|
setPageContent(this.transitRewrapForm);
|
||||||
|
|
||||||
this.transitRewrapForm.addEventListener("submit", (e: Event) => {
|
this.transitRewrapForm.addEventListener("submit", async (e: Event) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void this.transitRewrapFormHandler();
|
await this.transitRewrapFormHandler();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ export class UnsealPage extends Page {
|
||||||
|
|
||||||
async doRefresh(): Promise<void> {
|
async doRefresh(): Promise<void> {
|
||||||
const status = await getSealStatus();
|
const status = await getSealStatus();
|
||||||
this.updateSealProgress(status);
|
await this.updateSealProgress(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
|
@ -84,7 +84,7 @@ export class UnsealPage extends Page {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
this.switchInputMode(this.mode);
|
this.switchInputMode(this.mode);
|
||||||
this.updateSealProgress(await getSealStatus());
|
await this.updateSealProgress(await getSealStatus());
|
||||||
this.makeRefresher();
|
this.makeRefresher();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,13 +150,13 @@ export class UnsealPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
async makeQRInput(): Promise<void> {
|
async makeQRInput(): Promise<void> {
|
||||||
this.qrScanner = await QRScanner((code: string) => {
|
this.qrScanner = await QRScanner(async (code: string) => {
|
||||||
this.submitKey(code);
|
await this.submitKey(code);
|
||||||
});
|
});
|
||||||
this.unsealInputContent.appendChild(this.qrScanner);
|
this.unsealInputContent.appendChild(this.qrScanner);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSealProgress(data: SealStatusType): void {
|
async updateSealProgress(data: SealStatusType): Promise<void> {
|
||||||
const progress = data.progress;
|
const progress = data.progress;
|
||||||
const keysNeeded = data.t;
|
const keysNeeded = data.t;
|
||||||
const text = this.unsealProgressText;
|
const text = this.unsealProgressText;
|
||||||
|
@ -169,26 +169,24 @@ export class UnsealPage extends Page {
|
||||||
progressBar.max = keysNeeded;
|
progressBar.max = keysNeeded;
|
||||||
if (!data.sealed) {
|
if (!data.sealed) {
|
||||||
progressBar.value = keysNeeded;
|
progressBar.value = keysNeeded;
|
||||||
void changePage("HOME");
|
await changePage("HOME");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
submitKey(key: string): void {
|
async submitKey(key: string): Promise<void> {
|
||||||
submitUnsealKey(key)
|
try {
|
||||||
.then((_) => {
|
await submitUnsealKey(key);
|
||||||
void getSealStatus().then((data) => {
|
await this.updateSealProgress(await getSealStatus());
|
||||||
void this.updateSealProgress(data);
|
} catch (e: unknown) {
|
||||||
});
|
const error = e as Error;
|
||||||
})
|
setErrorText(error.message);
|
||||||
.catch((e: Error) => {
|
}
|
||||||
setErrorText(e.message);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeySubmit(): void {
|
async handleKeySubmit(): Promise<void> {
|
||||||
const formData = new FormData(this.unsealKeyForm);
|
const formData = new FormData(this.unsealKeyForm);
|
||||||
|
|
||||||
this.submitKey(formData.get("key") as string);
|
await this.submitKey(formData.get("key") as string);
|
||||||
}
|
}
|
||||||
get name(): string {
|
get name(): string {
|
||||||
return i18next.t("unseal_vault_text");
|
return i18next.t("unseal_vault_text");
|
||||||
|
|
Loading…
Reference in a new issue