Reformat code.
This commit is contained in:
parent
9fc0f9347b
commit
e0a3106d2e
|
@ -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);
|
||||
}
|
||||
})
|
||||
}));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
get name() {
|
||||
return "K/V Versions";
|
||||
}
|
||||
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);
|
||||
}
|
||||
})
|
||||
}));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
get name() {
|
||||
return "K/V Versions";
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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
|
||||
]
|
||||
}));
|
||||
|
|
|
@ -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",
|
||||
|
@ -37,7 +37,6 @@ export class TransitViewSecretPage extends Page {
|
|||
})
|
||||
]
|
||||
})
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {changePage} from "../pageUtils.js";
|
||||
import { changePage } from "../pageUtils.js";
|
||||
|
||||
export class Page {
|
||||
constructor() { }
|
||||
|
|
26
src/utils.js
26
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');
|
||||
}
|
Loading…
Reference in a new issue