From a58d86806beae3f05e717f677b1f97a0faaba362 Mon Sep 17 00:00:00 2001
From: forchannot <100580891+forchannot@users.noreply.github.com>
Date: Sun, 7 Jan 2024 14:17:13 +0800
Subject: [PATCH] =?UTF-8?q?:children=5Fcrossing:=20=E6=9B=B4=E6=94=B9?=
=?UTF-8?q?=E7=BD=91=E9=A1=B5=E5=90=8E=E5=8F=B0cdn=20(#492)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
LittlePaimon/web/__init__.py | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/LittlePaimon/web/__init__.py b/LittlePaimon/web/__init__.py
index 73c7e1b..2ba9675 100644
--- a/LittlePaimon/web/__init__.py
+++ b/LittlePaimon/web/__init__.py
@@ -8,13 +8,13 @@ from .api import BaseApiRouter
from .pages import admin_app, login_page, bind_cookie_page, blank_page
-requestAdaptor = '''
+requestAdaptor = """
requestAdaptor(api) {
api.headers["token"] = localStorage.getItem("token");
return api;
},
-'''
-responseAdaptor = '''
+"""
+responseAdaptor = """
responseAdaptor(api, payload, query, request, response) {
if (response.data.detail == '登录验证失败或已失效,请重新登录') {
window.location.href = '/LittlePaimon/login'
@@ -24,9 +24,10 @@ responseAdaptor(api, payload, query, request, response) {
}
return payload
},
-'''
+"""
-icon_path = 'https://s1.ax1x.com/2023/02/05/pS62DJK.png'
+icon_path = "https://s1.ax1x.com/2023/02/05/pS62DJK.png"
+cdn = "https://npm.onmicrosoft.cn"
@DRIVER.on_startup
@@ -34,41 +35,44 @@ def init_web():
app: FastAPI = nonebot.get_app()
app.include_router(BaseApiRouter)
logger.info(
- 'Web UI',
- f'启用成功,默认地址为http://127.0.0.1:{DRIVER.config.port}/LittlePaimon/login',
+ "Web UI",
+ f"启用成功,默认地址为http://127.0.0.1:{DRIVER.config.port}/LittlePaimon/login",
)
- @app.get('/LittlePaimon/admin', response_class=HTMLResponse)
+ @app.get("/LittlePaimon/admin", response_class=HTMLResponse)
async def admin():
if config.admin_enable:
return admin_app.render(
- site_title='LittlePaimon 后台管理',
+ site_title="LittlePaimon 后台管理",
site_icon=icon_path,
theme=config.admin_theme,
+ cdn=cdn,
requestAdaptor=requestAdaptor,
responseAdaptor=responseAdaptor,
)
else:
- return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
+ return blank_page.render(site_title="LittlePaimon", site_icon=icon_path)
- @app.get('/LittlePaimon/login', response_class=HTMLResponse)
+ @app.get("/LittlePaimon/login", response_class=HTMLResponse)
async def login():
if config.admin_enable:
return login_page.render(
- site_title='登录 | LittlePaimon 后台管理',
+ site_title="登录 | LittlePaimon 后台管理",
+ cdn=cdn,
site_icon=icon_path,
theme=config.admin_theme,
)
else:
- return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
+ return blank_page.render(site_title="LittlePaimon", site_icon=icon_path)
- @app.get('/LittlePaimon/cookie', response_class=HTMLResponse)
+ @app.get("/LittlePaimon/cookie", response_class=HTMLResponse)
async def bind_cookie():
if config.CookieWeb_enable:
return bind_cookie_page.render(
- site_title='绑定Cookie | LittlePaimon',
+ site_title="绑定Cookie | LittlePaimon",
+ cdn=cdn,
site_icon=icon_path,
theme=config.admin_theme,
)
else:
- return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
+ return blank_page.render(site_title="LittlePaimon", site_icon=icon_path)