From 1fb758a201b137064d88ece31d5c574d8d20a397 Mon Sep 17 00:00:00 2001 From: lan Date: Mon, 16 Jan 2023 17:54:08 +0800 Subject: [PATCH] =?UTF-8?q?update:=E5=90=8E=E5=8F=B0=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- core/database.py | 2 +- main.py | 24 +++++-- settings.py | 11 ++- templates/admin.html | 167 +++++++++++++++++++++++++++++++++++++------ 5 files changed, 174 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index 65e95b4..15314f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.9.5-slim-buster LABEL author="Lan" LABEL email="vast@tom.com" -LABEL version="1.5.9.2" +LABEL version="6" COPY . /app diff --git a/core/database.py b/core/database.py index 908222f..2330b42 100644 --- a/core/database.py +++ b/core/database.py @@ -68,7 +68,7 @@ async def init_models(): ) else: # 从数据库更新缓存中的setting - await settings.update(await conn.execute(select(Options).filter())) + await settings.updates(await conn.execute(select(Options).filter())) async def get_session(): diff --git a/main.py b/main.py index 89d82dc..ad1fc27 100644 --- a/main.py +++ b/main.py @@ -75,9 +75,15 @@ async def admin_post(page: int = Form(default=1), size: int = Form(default=10), }} -# @app.patch(f'/{settings.ADMIN_ADDRESS}', dependencies=[Depends(admin_required)], description='修改数据库数据') -# async def admin_patch(request: Request, s: AsyncSession = Depends(get_session)): -# return {'detail': '修改成功'} +@app.patch(f'/{settings.ADMIN_ADDRESS}', dependencies=[Depends(admin_required)], description='修改数据库数据') +async def admin_patch(request: Request, s: AsyncSession = Depends(get_session)): + data = await request.json() + data.pop('INSTALL') + for key, value in data.items(): + await s.execute(update(Options).where(Options.key == key).values(value=value)) + await settings.update(key, value) + await s.commit() + return {'detail': '修改成功'} @app.delete(f'/{settings.ADMIN_ADDRESS}', dependencies=[Depends(admin_required)], description='删除数据库记录') @@ -98,7 +104,17 @@ async def admin_delete(code: str, s: AsyncSession = Depends(get_session)): @app.get(f'/{settings.ADMIN_ADDRESS}/config', description='获取系统配置', dependencies=[Depends(admin_required)]) async def config(s: AsyncSession = Depends(get_session)): - return {'detail': '获取成功', 'data': (await s.execute(select(Options))).scalars().all()} + # 查询数据库 + data = {} + for i in (await s.execute(select(Options))).scalars().all(): + data[i.key] = i.value + return {'detail': '获取成功', 'data': data, 'menus': [ + {'key': 'INSTALL', 'name': '版本信息'}, + {'key': 'WEBSITE', 'name': '网站设置'}, + {'key': 'SHARE', 'name': '分享设置'}, + {'key': 'BANNERS', 'name': 'Banner'}, + {'key': 'WEBSITE', 'name': '网站设置'}, + ]} @app.get('/') diff --git a/settings.py b/settings.py index 9cc1b66..adcf15d 100644 --- a/settings.py +++ b/settings.py @@ -61,11 +61,16 @@ class Settings: 'url': 'https://www.lanol.cn', 'src': '/static/banners/img_2.png' }] + int_dict = {'PORT', 'MAX_DAYS', 'ERROR_COUNT', 'ERROR_MINUTE', 'UPLOAD_COUNT', 'UPLOAD_MINUTE', + 'DELETE_EXPIRE_FILES_INTERVAL', 'FILE_SIZE_LIMIT'} - async def update(self, options) -> None: + async def update(self, key, value) -> None: + if hasattr(self, key): + setattr(self, key, int(value) if key in self.int_dict else value) + + async def updates(self, options) -> None: for i, key, value in options: - if hasattr(self, key): - setattr(self, key, value) + await self.update(key, value) settings = Settings() diff --git a/templates/admin.html b/templates/admin.html index 09efc1c..bc56891 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -22,6 +22,34 @@ body { background: #f5f5f5; } + + @media (prefers-color-scheme: dark) { + + body { + background-color: #18181c; + } + + .el-card, .el-textarea__inner, .el-upload-dragger { + border-radius: 20px; + border: 1px solid transparent; + background-color: rgba(255, 255, 255, 0.1); + box-shadow: 5px 5px 0 0 rgba(0, 0, 0, 0.2); + } + + #app * { + color: #ccc !important; + } + + .el-input-group__prepend, .el-menu, .btn-prev, .el-input__inner, .el-input-group__append, .el-empty__description, .el-select-dropdown, .el-button { + border: 1px solid transparent; + background-color: rgba(0, 0, 0, 0.2); + } + + .el-drawer, #el-drawer__title, .el-drawer__body, .el-drawer__wrapper { + background-color: rgba(0, 0, 0, 0.5); + border: 1px solid transparent; + } + } @@ -29,8 +57,9 @@ - 文件管理 - 系统配置 + 分享文件管理 + 本地文件列表 + 系统配置 @@ -72,24 +101,113 @@ > - - -
- - - -
-
- 删除 -
-
- - 新增Banner - - - 更新 - -
+ + + + +
${menu.name}
+
+
+ + +
+
+

FileCodeBox V${config.INSTALL}

+

Github:FileCodeBox

+
+
+
+ + +
+ + + +
+
+ 删除 +
+
+ + 新增Banner + + + 更新 + +
+
+
+ + + + + + + + + + + + + + + + + + + 更新 + + +
+
+ + + + + + + + + + + + 单位:(bit),1mb=1 * 1024 * 1024 + + + + + + + + 每几分钟 + + 允许错误几次 + + + + 每几分钟 + + 允许上传几次 + + + + 更新 + + +
+
+
+
@@ -113,6 +231,8 @@ config: { banners: [] }, + menus: [], + updateTab: 'INSTALL', files: [], paginate: { page: 1, @@ -126,12 +246,13 @@ if (pwd) { login = true; this.pwd = pwd; - axios.get('{{admin_address}}/config', { + axios.get(window.location.href + '/config', { headers: { pwd: pwd } }).then(res => { this.config = res.data.data; + this.menus = res.data.menus; }); this.loginAdmin(); } @@ -146,10 +267,10 @@ this.loginAdmin(); }, deleteBanner: function (index) { - this.config.banners.splice(index, 1); + this.config.BANNERS.splice(index, 1); }, addBanner: function () { - this.config.banners.push({ + this.config.BANNERS.push({ 'url': '', 'src': '', 'text': '',