Skip to content

Commit

Permalink
feat: 优化脚本下载
Browse files Browse the repository at this point in the history
  • Loading branch information
helloplhm-qwq committed Jan 30, 2024
1 parent 08375b9 commit ee0c894
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 2 additions & 3 deletions common/lx_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ async def handle_request(request):
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}')
Expand Down

0 comments on commit ee0c894

Please sign in to comment.