mirror of
https://github.com/MeoProject/lx-music-api-server.git
synced 2025-05-23 19:17:41 +08:00
feat: 优化脚本下载
This commit is contained in:
parent
08375b9b10
commit
ee0c894d05
@ -10,7 +10,6 @@
|
||||
from . import Httpx
|
||||
from . import config
|
||||
from . import scheduler
|
||||
from .variable import iscn
|
||||
from .log import log
|
||||
from aiohttp.web import Response
|
||||
import ujson as json
|
||||
@ -70,12 +69,12 @@ async def get_script():
|
||||
|
||||
async def generate_script_response(request):
|
||||
if (request.query.get('key') != config.read_config('security.key.value') and config.read_config('security.key.enable')):
|
||||
return Response(body = json.dumps({'code': 6, 'msg': 'key验证失败', 'data': None}, indent=2, ensure_ascii=False), content_type='application/json', status = 400)
|
||||
return {'code': 6, 'msg': 'key验证失败', 'data': None}, 403
|
||||
try:
|
||||
with open('./lx-music-source-example.js', 'r', encoding='utf-8') as f:
|
||||
script = f.read()
|
||||
except:
|
||||
return Response(body = json.dumps({'code': 4, 'msg': '本地无源脚本', 'data': None}, indent=2, ensure_ascii=False), content_type='application/json', status = 500)
|
||||
return {'code': 4, 'msg': '本地无源脚本', 'data': None}, 400
|
||||
scriptLines = script.split('\n')
|
||||
newScriptLines = []
|
||||
for line in scriptLines:
|
||||
|
10
main.py
10
main.py
@ -91,10 +91,14 @@ async def handle_before_request(app, handler):
|
||||
return handleResult({'code': 6, 'msg': '未找到您所请求的资源', 'data': None}, 404)
|
||||
|
||||
resp = await handler(request)
|
||||
if (isinstance(resp, str)):
|
||||
resp = Response(body = resp, content_type='text/plain', status = 200)
|
||||
elif (isinstance(resp, (list, dict))):
|
||||
if (isinstance(resp, (str, list, dict))):
|
||||
resp = handleResult(resp)
|
||||
elif (isinstance(resp, tuple) and len(resp) == 2): # flask like response
|
||||
body, status = resp
|
||||
if (isinstance(body, (str, list, dict))):
|
||||
resp = handleResult(body, status)
|
||||
else:
|
||||
resp = Response(body = str(body), content_type='text/plain', status = status)
|
||||
elif (not isinstance(resp, Response)):
|
||||
resp = Response(body = str(resp), content_type='text/plain', status = 200)
|
||||
aiologger.info(f'{request.remote_addr + ("" if (request.remote == request.remote_addr) else f"|proxy@{request.remote}")} - {request.method} "{request.path}", {resp.status}')
|
||||
|
Loading…
x
Reference in New Issue
Block a user