From e0a3106d2e7da990e8130512a358230b8aba2d86 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Thu, 15 Apr 2021 15:37:52 +0100 Subject: [PATCH] Reformat code. --- src/pages/KeyValueVersions.js | 82 ++++++++++----------- src/pages/KeyValueView.js | 128 ++++++++++++++++----------------- src/pages/PwGen.js | 74 +++++++++---------- src/pages/TOTPView.js | 4 +- src/pages/TransitViewSecret.js | 15 ++-- src/pages/Unseal.js | 2 +- src/types/Page.js | 2 +- src/utils.js | 26 +++---- 8 files changed, 166 insertions(+), 167 deletions(-) diff --git a/src/pages/KeyValueVersions.js b/src/pages/KeyValueVersions.js index cc179a5..0ec4b08 100644 --- a/src/pages/KeyValueVersions.js +++ b/src/pages/KeyValueVersions.js @@ -4,45 +4,45 @@ import { setPageContent, setTitleElement } from "../pageUtils.js"; import { makeElement } from "../htmlUtils.js"; export class KeyValueVersionsPage extends Page { - constructor() { - super(); - } - goBack() { - changePage(pages.KEY_VALUE_SECRETS); - } - async render() { - setTitleElement(pageState); - - let versionsList = makeElement({ - tag: "ul", - id: "versionsList", - class: ["uk-nav", "uk-nav-default"] - }); - setPageContent(versionsList); - - let metadata = await getSecretMetadata( - pageState.currentBaseMount, - pageState.currentSecretPath, - pageState.currentSecret - ); - - new Map(Object.entries(metadata.versions)).forEach((_, ver) => { - versionsList.appendChild(makeElement({ - tag: "li", - children: makeElement({ - tag: "a", - text: `v${ver}`, - onclick: _ => { - pageState.currentSecretVersion = ver; - changePage(pages.KEY_VALUE_SECRETS); - } - }) - })); - }); - - } + constructor() { + super(); + } + goBack() { + changePage(pages.KEY_VALUE_SECRETS); + } + async render() { + setTitleElement(pageState); - get name() { - return "K/V Versions"; - } - } \ No newline at end of file + let versionsList = makeElement({ + tag: "ul", + id: "versionsList", + class: ["uk-nav", "uk-nav-default"] + }); + setPageContent(versionsList); + + let metadata = await getSecretMetadata( + pageState.currentBaseMount, + pageState.currentSecretPath, + pageState.currentSecret + ); + + new Map(Object.entries(metadata.versions)).forEach((_, ver) => { + versionsList.appendChild(makeElement({ + tag: "li", + children: makeElement({ + tag: "a", + text: `v${ver}`, + onclick: _ => { + pageState.currentSecretVersion = ver; + changePage(pages.KEY_VALUE_SECRETS); + } + }) + })); + }); + + } + + get name() { + return "K/V Versions"; + } +} \ No newline at end of file diff --git a/src/pages/KeyValueView.js b/src/pages/KeyValueView.js index 01285cb..f6d9d82 100644 --- a/src/pages/KeyValueView.js +++ b/src/pages/KeyValueView.js @@ -4,77 +4,77 @@ import { setErrorText, setTitleElement } from "../pageUtils.js"; import { makeElement } from "../htmlUtils.js"; export class KeyValueViewPage extends Page { - constructor() { - super(); + constructor() { + super(); + } + goBack() { + if (pageState.currentSecretPath.length != 0) { + pageState.popCurrentSecretPath(); + changePage(pages.KEY_VALUE_VIEW); + } else { + changePage(pages.HOME); } - goBack() { - if (pageState.currentSecretPath.length != 0) { - pageState.popCurrentSecretPath(); - changePage(pages.KEY_VALUE_VIEW); - } else { - changePage(pages.HOME); - } - } - async render() { - pageState.currentSecret = ""; + } + async render() { + pageState.currentSecret = ""; - setTitleElement(pageState); + setTitleElement(pageState); - let newButton = makeElement({ - tag: "button", - text: "New", - class: ["uk-button", "uk-button-primary", "uk-margin-bottom"], - onclick: () => { - changePage(pages.KEY_VALUE_NEW_SECRET); - } - }); - pageContent.appendChild(newButton); + let newButton = makeElement({ + tag: "button", + text: "New", + class: ["uk-button", "uk-button-primary", "uk-margin-bottom"], + onclick: () => { + changePage(pages.KEY_VALUE_NEW_SECRET); + } + }); + pageContent.appendChild(newButton); - try { - let res = await getSecrets(pageState.currentBaseMount, pageState.currentSecretPath); + try { + let res = await getSecrets(pageState.currentBaseMount, pageState.currentSecretPath); - pageContent.appendChild(makeElement({ - tag: "ul", - class: ["uk-nav", "uk-nav-default"], - children: [ - ...res.map(function (secret) { - return makeElement({ - tag: "li", - children: makeElement({ - tag: "a", - text: secret, - onclick: _ => { - if (secret.endsWith("/")) { - pageState.pushCurrentSecretPath(secret); - changePage(pages.KEY_VALUE_VIEW); - } else { - pageState.currentSecret = secret; - changePage(pages.KEY_VALUE_SECRETS); - } - } - }) - }); - }) - ] - })); - } catch (e) { - if (e == DoesNotExistError) { - // getSecrets also 404's on no keys so dont go all the way back. - if (pageState.currentSecretPath.length != 0) { - return this.goBack(); - } else { - pageContent.appendChild(makeElement({ - tag: "p", - text: "You seem to have no secrets here, would you like to create one?" - })); + pageContent.appendChild(makeElement({ + tag: "ul", + class: ["uk-nav", "uk-nav-default"], + children: [ + ...res.map(function (secret) { + return makeElement({ + tag: "li", + children: makeElement({ + tag: "a", + text: secret, + onclick: _ => { + if (secret.endsWith("/")) { + pageState.pushCurrentSecretPath(secret); + changePage(pages.KEY_VALUE_VIEW); + } else { + pageState.currentSecret = secret; + changePage(pages.KEY_VALUE_SECRETS); + } } - } else { - setErrorText(e.message); - } + }) + }); + }) + ] + })); + } catch (e) { + if (e == DoesNotExistError) { + // getSecrets also 404's on no keys so dont go all the way back. + if (pageState.currentSecretPath.length != 0) { + return this.goBack(); + } else { + pageContent.appendChild(makeElement({ + tag: "p", + text: "You seem to have no secrets here, would you like to create one?" + })); } + } else { + setErrorText(e.message); + } } + } - get name() { - return "K/V View"; - } + get name() { + return "K/V View"; + } } diff --git a/src/pages/PwGen.js b/src/pages/PwGen.js index 9386a54..77ec984 100644 --- a/src/pages/PwGen.js +++ b/src/pages/PwGen.js @@ -5,52 +5,52 @@ import { makeElement } from "../htmlUtils.js"; import { CopyableInputBox } from "../elements/CopyableInputBox.js"; function random() { - const { - crypto, - Uint32Array - } = window; + const { + crypto, + Uint32Array + } = window; - if (typeof (crypto === null || crypto === void 0 ? void 0 : crypto.getRandomValues) === 'function' && typeof Uint32Array === 'function') { - return window.crypto.getRandomValues(new Uint32Array(1))[0] / 4294967295; - } + if (typeof (crypto === null || crypto === void 0 ? void 0 : crypto.getRandomValues) === 'function' && typeof Uint32Array === 'function') { + return window.crypto.getRandomValues(new Uint32Array(1))[0] / 4294967295; + } - return Math.random(); + return Math.random(); } function genPw(len) { - let pw = ""; - const pwArray = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\]^_{|}~".split(''); - for (let i = 0; i < len; i++) { - pw = pw.concat(pwArray[Math.floor(random() * pwArray.length)]); - } - return pw; + let pw = ""; + const pwArray = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\]^_{|}~".split(''); + for (let i = 0; i < len; i++) { + pw = pw.concat(pwArray[Math.floor(random() * pwArray.length)]); + } + return pw; } export class PwGenPage extends Page { - constructor() { - super(); - } - async render() { - let inputBox = CopyableInputBox(genPw(24)); - setPageContent(makeElement({ - tag: "div", - children: [ - inputBox, - makeElement({ - tag: "button", - text: "Gen New Password", - class: ["uk-button", "uk-button-primary", "uk-margin-bottom"], - onclick: () => { - inputBox.setText(genPw(24)); - } - }) - ] - })); - } + constructor() { + super(); + } + async render() { + let inputBox = CopyableInputBox(genPw(24)); + setPageContent(makeElement({ + tag: "div", + children: [ + inputBox, + makeElement({ + tag: "button", + text: "Gen New Password", + class: ["uk-button", "uk-button-primary", "uk-margin-bottom"], + onclick: () => { + inputBox.setText(genPw(24)); + } + }) + ] + })); + } - get name() { - return "Password Generator"; - } + get name() { + return "Password Generator"; + } } \ No newline at end of file diff --git a/src/pages/TOTPView.js b/src/pages/TOTPView.js index cf38899..6d3cdb7 100644 --- a/src/pages/TOTPView.js +++ b/src/pages/TOTPView.js @@ -25,8 +25,8 @@ export class TOTPViewPage extends Page { id: "loadingText", text: "Loading TOTP Codes..", }), - makeElement({tag: "br"}), - makeElement({tag: "br"}), + makeElement({ tag: "br" }), + makeElement({ tag: "br" }), totpList ] })); diff --git a/src/pages/TransitViewSecret.js b/src/pages/TransitViewSecret.js index 9b84301..d725ba4 100644 --- a/src/pages/TransitViewSecret.js +++ b/src/pages/TransitViewSecret.js @@ -7,14 +7,14 @@ export class TransitViewSecretPage extends Page { super(); } - makeTile(title, description, icon = "code", onclick = _ => {}) { + makeTile(title, description, icon = "code", onclick = _ => { }) { return makeElement({ - tag: "div", - class: ["uk-tile", "uk-tile-default", "uk-tile-primary", "uk-padding-small"], + tag: "a", + class: "uk-link-heading", + onclick: onclick, children: makeElement({ - tag: "a", - class: "uk-link-heading", - onclick: onclick, + tag: "div", + class: ["uk-tile", "uk-tile-default", "uk-tile-primary", "uk-padding-small"], children: [ makeElement({ tag: "p", @@ -27,7 +27,7 @@ export class TransitViewSecretPage extends Page { "uk-icon": `icon: ${icon}`, "role": "img", "aria-label": `${title} icon` - } + } }) }), makeElement({ @@ -37,7 +37,6 @@ export class TransitViewSecretPage extends Page { }) ] }) - }); } diff --git a/src/pages/Unseal.js b/src/pages/Unseal.js index a63abc0..71031d7 100644 --- a/src/pages/Unseal.js +++ b/src/pages/Unseal.js @@ -34,7 +34,7 @@ export class UnsealPage extends Page { this.unsealProgress = makeElement({ tag: "progress", class: "uk-progress", - attributes: {value: "0", max: "0"} + attributes: { value: "0", max: "0" } }); this.unsealProgressText = makeElement({ tag: "p", diff --git a/src/types/Page.js b/src/types/Page.js index fa3cadf..07bd5b6 100644 --- a/src/types/Page.js +++ b/src/types/Page.js @@ -1,4 +1,4 @@ -import {changePage} from "../pageUtils.js"; +import { changePage } from "../pageUtils.js"; export class Page { constructor() { } diff --git a/src/utils.js b/src/utils.js index 040e76e..6ad541c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,27 +1,27 @@ export function removeDoubleSlash(str) { - return str.replace(/\/\/+/g, "/"); + return str.replace(/\/\/+/g, "/"); } export function getKeyByObjectPropertyValue(map, searchValue) { - for (let key of Object.getOwnPropertyNames(map)) { - if (map[key] === searchValue) - return key; - } + for (let key of Object.getOwnPropertyNames(map)) { + if (map[key] === searchValue) + return key; + } } export function verifyJSONString(str) { - try { - JSON.parse(str); - } catch (e) { - return false; - } - return true; + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; } export function getToken() { - return localStorage.getItem('token'); + return localStorage.getItem('token'); } export function getAPIURL() { - return localStorage.getItem('apiurl'); + return localStorage.getItem('apiurl'); } \ No newline at end of file