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