From 01cfb897a41d86b23059917c031364790407b0fc Mon Sep 17 00:00:00 2001 From: ChisatoNishikigi73 <89033115+chisatonishikigi73@users.noreply.github.com> Date: Sat, 14 Sep 2024 23:19:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=90=8E=E5=8F=B0Das?= =?UTF-8?q?hboard=20#1=20=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AEConfig=20api?= =?UTF-8?q?=20=E9=A1=B5=E9=9D=A2=EF=BC=8C=E7=8E=B0=E5=9C=A8=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=9C=A8=E7=BD=91=E9=A1=B5=E6=8E=A7=E5=88=B6Config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/server/v2Server.ts | 81 +++++- src/public/App.vue | 238 +++++------------- src/public/components/Config.vue | 111 ++++++++ src/public/components/Dashboard.vue | 194 ++++++++++++++ src/public/components/WaveformChart.vue | 146 ----------- .../components/config/ConfigSection.vue | 213 ++++++++++++++++ src/public/components/status/ProgressBox.vue | 7 +- .../{ => status}/StatusOverview.vue | 19 +- src/public/static/font-awesome@5.15.3.css | 42 ++-- src/public/static/fonts/cyrillic-ext.woff2 | Bin 0 -> 25888 bytes src/public/static/fonts/cyrillic.woff2 | Bin 0 -> 18740 bytes src/public/static/fonts/greek-ext.woff2 | Bin 0 -> 11200 bytes src/public/static/fonts/greek.woff2 | Bin 0 -> 19072 bytes src/public/static/fonts/latin-ext.woff2 | Bin 0 -> 74328 bytes src/public/static/fonts/latin.woff2 | Bin 0 -> 48444 bytes src/public/static/fonts/vietnamese.woff2 | Bin 0 -> 10252 bytes src/public/v2.js | 20 ++ src/utils/config/config.ts | 57 +++++ 18 files changed, 776 insertions(+), 352 deletions(-) create mode 100644 src/public/components/Config.vue create mode 100644 src/public/components/Dashboard.vue delete mode 100644 src/public/components/WaveformChart.vue create mode 100644 src/public/components/config/ConfigSection.vue rename src/public/components/{ => status}/StatusOverview.vue (83%) create mode 100644 src/public/static/fonts/cyrillic-ext.woff2 create mode 100644 src/public/static/fonts/cyrillic.woff2 create mode 100644 src/public/static/fonts/greek-ext.woff2 create mode 100644 src/public/static/fonts/greek.woff2 create mode 100644 src/public/static/fonts/latin-ext.woff2 create mode 100644 src/public/static/fonts/latin.woff2 create mode 100644 src/public/static/fonts/vietnamese.woff2 diff --git a/src/core/server/v2Server.ts b/src/core/server/v2Server.ts index 5a4330f..855c07c 100644 --- a/src/core/server/v2Server.ts +++ b/src/core/server/v2Server.ts @@ -6,7 +6,6 @@ import { Server as ServerType, ServerResponse, IncomingMessage } from 'http' import { common, config } from 'karin/utils' import { apiV2 } from 'karin/utils/api/v2/v2' import cors from 'cors' - export const api2Server = new (class Api2Server { reg: RegExp list: string[] @@ -36,6 +35,7 @@ export const api2Server = new (class Api2Server { credentials: true, })) + /** 获取服务器信息 **/ this.app.get('/api/v2/info/status', async (req, res) => { res.json({ code: 200, @@ -60,6 +60,85 @@ export const api2Server = new (class Api2Server { }) }) + /** Config处理 **/ + this.app.get('/api/v2/config/get/:type', async (req, res) => { + const type = req.params.type + let _config = {} + switch (type) { + case 'app': + _config = config.App + break + case 'config': + _config = config.Config + break + case 'group': + _config = config.group + break + case 'pm2': + // Where is pm2 config? + _config = {} + break + case 'redis': + _config = config.redis + break + case 'server': + _config = config.Server + break + case 'all': + _config = config + break + } + + res.json({ + code: 200, + message: 'ok', + data: { + config: _config, + }, + }) + }) + + this.app.post('/api/v2/config/save/:type', async (req, res) => { + let type = req.params.type + if (type === 'app') { + type = 'App' + } else if (type === 'config') { + type = 'config' + } else if (type === 'group') { + type = 'group' + } else if (type === 'pm2') { + type = 'pm2' + } else if (type === 'redis') { + type = 'redis' + } else if (type === 'server') { + type = 'server' + } else { + res.status(400).json({ + code: 400, + message: 'Invalid config type', + }) + return + } + + const data = req.body + try { + await config.saveConfig(type as keyof typeof config, data) + res.json({ + code: 200, + message: 'ok', + data: { + // config: data, + }, + }) + } catch (error) { + logger.error(error) + res.status(500).json({ + code: 500, + message: 'Error saving config', + }) + } + }) + const { host } = config.Server.http this.api2Server.listen(9000, host, () => { const localIP = common.getLocalIP() diff --git a/src/public/App.vue b/src/public/App.vue index 41e7e94..fe25ba8 100644 --- a/src/public/App.vue +++ b/src/public/App.vue @@ -1,163 +1,60 @@ \ No newline at end of file diff --git a/src/public/components/Config.vue b/src/public/components/Config.vue new file mode 100644 index 0000000..191a4ae --- /dev/null +++ b/src/public/components/Config.vue @@ -0,0 +1,111 @@ + + + + + diff --git a/src/public/components/Dashboard.vue b/src/public/components/Dashboard.vue new file mode 100644 index 0000000..babb857 --- /dev/null +++ b/src/public/components/Dashboard.vue @@ -0,0 +1,194 @@ + + + + + \ No newline at end of file diff --git a/src/public/components/WaveformChart.vue b/src/public/components/WaveformChart.vue deleted file mode 100644 index dc4dae4..0000000 --- a/src/public/components/WaveformChart.vue +++ /dev/null @@ -1,146 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/public/components/config/ConfigSection.vue b/src/public/components/config/ConfigSection.vue new file mode 100644 index 0000000..bfdb9cb --- /dev/null +++ b/src/public/components/config/ConfigSection.vue @@ -0,0 +1,213 @@ + + + + + \ No newline at end of file diff --git a/src/public/components/status/ProgressBox.vue b/src/public/components/status/ProgressBox.vue index 9859276..bb8d950 100644 --- a/src/public/components/status/ProgressBox.vue +++ b/src/public/components/status/ProgressBox.vue @@ -79,25 +79,28 @@ onMounted(() => { margin-right: 15px; } .percentage-value { + font-family: monospace; color: #ffffff; font-size: 1.5em; opacity: 0.7; margin-bottom: 5px; } .percentage-label { + font-family: monospace; color: #ffffff; - font-size: 1em; + font-size: 1.4em; opacity: 0.7; margin-bottom: 5px; margin-top: 5px; } .down-title { + font-family: monospace; position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%); color: #ffffff; - font-size: 1em; + font-size: 1.3em; opacity: 0.7; text-align: center; width: 100%; diff --git a/src/public/components/StatusOverview.vue b/src/public/components/status/StatusOverview.vue similarity index 83% rename from src/public/components/StatusOverview.vue rename to src/public/components/status/StatusOverview.vue index 8fb69c0..a93a3ef 100644 --- a/src/public/components/StatusOverview.vue +++ b/src/public/components/status/StatusOverview.vue @@ -6,7 +6,8 @@
- + +

Karin

@@ -34,9 +35,9 @@