From ff31b8b06d0863d07a0235af2601bd3a1c30d503 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 13 Dec 2022 16:35:52 -0500 Subject: [PATCH] server: remove bios and cli The BIOS and CLI functionality were mainly for debugging purposes. If a user has to use those to resolve an issue with the server, that really should be fixed at the source instead. Closes: https://akkoma.dev/FoundKeyGang/FoundKey/issues/283 Changelog: Removed --- gulpfile.js | 4 +- packages/backend/src/server/web/bios.css | 40 --------- packages/backend/src/server/web/bios.js | 87 ------------------- packages/backend/src/server/web/cli.css | 19 ---- packages/backend/src/server/web/cli.js | 55 ------------ packages/backend/src/server/web/index.ts | 12 --- .../backend/src/server/web/views/bios.pug | 20 ----- packages/backend/src/server/web/views/cli.pug | 21 ----- 8 files changed, 2 insertions(+), 256 deletions(-) delete mode 100644 packages/backend/src/server/web/bios.css delete mode 100644 packages/backend/src/server/web/bios.js delete mode 100644 packages/backend/src/server/web/cli.css delete mode 100644 packages/backend/src/server/web/cli.js delete mode 100644 packages/backend/src/server/web/views/bios.pug delete mode 100644 packages/backend/src/server/web/views/cli.pug diff --git a/gulpfile.js b/gulpfile.js index 12ddcaddb..898869b06 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -36,7 +36,7 @@ gulp.task('copy:client:locales', cb => { }); gulp.task('build:backend:script', () => { - return gulp.src(['./packages/backend/src/server/web/boot.js', './packages/backend/src/server/web/bios.js', './packages/backend/src/server/web/cli.js']) + return gulp.src(['./packages/backend/src/server/web/boot.js']) .pipe(replace('LANGS', JSON.stringify(Object.keys(locales)))) .pipe(terser({ toplevel: true @@ -45,7 +45,7 @@ gulp.task('build:backend:script', () => { }); gulp.task('build:backend:style', () => { - return gulp.src(['./packages/backend/src/server/web/style.css', './packages/backend/src/server/web/bios.css', './packages/backend/src/server/web/cli.css']) + return gulp.src(['./packages/backend/src/server/web/style.css']) .pipe(cssnano({ zindex: false })) diff --git a/packages/backend/src/server/web/bios.css b/packages/backend/src/server/web/bios.css deleted file mode 100644 index b0da3ee39..000000000 --- a/packages/backend/src/server/web/bios.css +++ /dev/null @@ -1,40 +0,0 @@ -* { - font-family: Fira code, Fira Mono, Consolas, Menlo, Courier, monospace; -} - -html { - background: #ffb4e1; -} - -main { - background: #dedede; -} -main > .tabs { - padding: 16px; - border-bottom: solid 4px #c3c3c3; -} - -#lsEditor > .adder { - margin: 16px; - padding: 16px; - border: solid 2px #c3c3c3; -} -#lsEditor > .adder > textarea { - display: block; - width: 100%; - min-height: 5em; - box-sizing: border-box; -} -#lsEditor > .record { - padding: 16px; - border-bottom: solid 1px #c3c3c3; -} -#lsEditor > .record > header { - font-weight: bold; -} -#lsEditor > .record > textarea { - display: block; - width: 100%; - min-height: 5em; - box-sizing: border-box; -} diff --git a/packages/backend/src/server/web/bios.js b/packages/backend/src/server/web/bios.js deleted file mode 100644 index d06dee801..000000000 --- a/packages/backend/src/server/web/bios.js +++ /dev/null @@ -1,87 +0,0 @@ -'use strict'; - -window.onload = async () => { - const account = JSON.parse(localStorage.getItem('account')); - const i = account.token; - - const api = (endpoint, data = {}) => { - const promise = new Promise((resolve, reject) => { - // Append a credential - if (i) data.i = i; - - // Send request - fetch(endpoint.indexOf('://') > -1 ? endpoint : `/api/${endpoint}`, { - method: 'POST', - body: JSON.stringify(data), - credentials: 'omit', - cache: 'no-cache' - }).then(async (res) => { - const body = res.status === 204 ? null : await res.json(); - - if (res.status === 200) { - resolve(body); - } else if (res.status === 204) { - resolve(); - } else { - reject(body.error); - } - }).catch(reject); - }); - - return promise; - }; - - const content = document.getElementById('content'); - - document.getElementById('ls').addEventListener('click', () => { - content.innerHTML = ''; - - const lsEditor = document.createElement('div'); - lsEditor.id = 'lsEditor'; - - const adder = document.createElement('div'); - adder.classList.add('adder'); - const addKeyInput = document.createElement('input'); - const addValueTextarea = document.createElement('textarea'); - const addButton = document.createElement('button'); - addButton.textContent = 'add'; - addButton.addEventListener('click', () => { - localStorage.setItem(addKeyInput.value, addValueTextarea.value); - location.reload(); - }); - - adder.appendChild(addKeyInput); - adder.appendChild(addValueTextarea); - adder.appendChild(addButton); - lsEditor.appendChild(adder); - - for (let i = 0; i < localStorage.length; i++) { - const k = localStorage.key(i); - const record = document.createElement('div'); - record.classList.add('record'); - const header = document.createElement('header'); - header.textContent = k; - const textarea = document.createElement('textarea'); - textarea.textContent = localStorage.getItem(k); - const saveButton = document.createElement('button'); - saveButton.textContent = 'save'; - saveButton.addEventListener('click', () => { - localStorage.setItem(k, textarea.value); - location.reload(); - }); - const removeButton = document.createElement('button'); - removeButton.textContent = 'remove'; - removeButton.addEventListener('click', () => { - localStorage.removeItem(k); - location.reload(); - }); - record.appendChild(header); - record.appendChild(textarea); - record.appendChild(saveButton); - record.appendChild(removeButton); - lsEditor.appendChild(record); - } - - content.appendChild(lsEditor); - }); -}; diff --git a/packages/backend/src/server/web/cli.css b/packages/backend/src/server/web/cli.css deleted file mode 100644 index 07cd27830..000000000 --- a/packages/backend/src/server/web/cli.css +++ /dev/null @@ -1,19 +0,0 @@ -* { - font-family: Fira code, Fira Mono, Consolas, Menlo, Courier, monospace; -} - -html { - background: #ffb4e1; -} - -main { - background: #dedede; -} - -#tl > div { - padding: 16px; - border-bottom: solid 1px #c3c3c3; -} -#tl > div > header { - font-weight: bold; -} diff --git a/packages/backend/src/server/web/cli.js b/packages/backend/src/server/web/cli.js deleted file mode 100644 index 3dff1d486..000000000 --- a/packages/backend/src/server/web/cli.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -window.onload = async () => { - const account = JSON.parse(localStorage.getItem('account')); - const i = account.token; - - const api = (endpoint, data = {}) => { - const promise = new Promise((resolve, reject) => { - // Append a credential - if (i) data.i = i; - - // Send request - fetch(endpoint.indexOf('://') > -1 ? endpoint : `/api/${endpoint}`, { - method: 'POST', - body: JSON.stringify(data), - credentials: 'omit', - cache: 'no-cache' - }).then(async (res) => { - const body = res.status === 204 ? null : await res.json(); - - if (res.status === 200) { - resolve(body); - } else if (res.status === 204) { - resolve(); - } else { - reject(body.error); - } - }).catch(reject); - }); - - return promise; - }; - - document.getElementById('submit').addEventListener('click', () => { - api('notes/create', { - text: document.getElementById('text').value - }).then(() => { - location.reload(); - }); - }); - - api('notes/timeline').then(notes => { - const tl = document.getElementById('tl'); - for (const note of notes) { - const el = document.createElement('div'); - const name = document.createElement('header'); - name.textContent = `${note.user.name} @${note.user.username}`; - const text = document.createElement('div'); - text.textContent = `${note.text}`; - el.appendChild(name); - el.appendChild(text); - tl.appendChild(el); - } - }); -}; diff --git a/packages/backend/src/server/web/index.ts b/packages/backend/src/server/web/index.ts index e97b14d8d..1c33fde10 100644 --- a/packages/backend/src/server/web/index.ts +++ b/packages/backend/src/server/web/index.ts @@ -485,18 +485,6 @@ router.get('/_info_card_', async ctx => { }); }); -router.get('/bios', async ctx => { - await ctx.render('bios', { - version: config.version, - }); -}); - -router.get('/cli', async ctx => { - await ctx.render('cli', { - version: config.version, - }); -}); - const override = (source: string, target: string, depth = 0) => [, ...target.split('/').filter(x => x), ...source.split('/').filter(x => x).splice(depth)].join('/'); diff --git a/packages/backend/src/server/web/views/bios.pug b/packages/backend/src/server/web/views/bios.pug deleted file mode 100644 index 2abc80ce9..000000000 --- a/packages/backend/src/server/web/views/bios.pug +++ /dev/null @@ -1,20 +0,0 @@ -doctype html - -html - - head - meta(charset='utf-8') - meta(name='application-name' content='FoundKey') - title FoundKey Repair Tool - style - include ../bios.css - script - include ../bios.js - - body - header - h1 FoundKey Repair Tool #{version} - main - div.tabs - button#ls edit local storage - div#content diff --git a/packages/backend/src/server/web/views/cli.pug b/packages/backend/src/server/web/views/cli.pug deleted file mode 100644 index bc57efbc8..000000000 --- a/packages/backend/src/server/web/views/cli.pug +++ /dev/null @@ -1,21 +0,0 @@ -doctype html - -html - - head - meta(charset='utf-8') - meta(name='application-name' content='FoundKey') - title FoundKey Cli - style - include ../cli.css - script - include ../cli.js - - body - header - h1 FoundKey Cli #{version} - main - div#form - textarea#text - button#submit submit - div#tl