From 02fe38e78013c6946d78af73d11182a5ca5da18c Mon Sep 17 00:00:00 2001 From: helloplhm-qwq Date: Sun, 24 Dec 2023 16:22:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E8=84=9A=E6=9C=AC=E4=BF=A1=E6=81=AF=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/config.py | 12 ++++++++++-- common/lx_script.py | 11 ++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/common/config.py b/common/config.py index c41e34c..35e86a6 100644 --- a/common/config.py +++ b/common/config.py @@ -68,11 +68,19 @@ class ConfigReadException(Exception): "allow_download_script": True, '_allow_download_script-desc': '是否允许直接从服务端下载脚本,开启后可以直接访问 /script?key=你的请求key 下载脚本', "download_config": { - "desc": "源脚本的相关配置", + "desc": "源脚本的相关配置,dev为是否启用开发模式", "name": "修改为你的源脚本名称", "intro": "修改为你的源脚本描述", "author": "修改为你的源脚本作者", - "version": "修改为你的源版本" + "version": "修改为你的源版本", + "dev": True, + "quality": { + "kw": ["128k", "320k", "flac"], + "kg": ["128k"], + "tx": ["128k"], + "wy": ["128k"], + "mg": ["128k"], + } } }, "security": { diff --git a/common/lx_script.py b/common/lx_script.py index 41f416d..4235a7f 100644 --- a/common/lx_script.py +++ b/common/lx_script.py @@ -13,6 +13,8 @@ from .variable import iscn from .log import log from aiohttp.web import Response +import ujson as json +import re logger = log('lx_script') @@ -55,8 +57,6 @@ async def generate_script_response(request): newScriptLines.append(f'const API_URL = "{request.scheme}://{request.host}"') elif (line.startswith('const API_KEY')): newScriptLines.append(f'const API_KEY = "{config.read_config("security.key.value")}"') - elif (line.startswith("/*")): - newScriptLines.append(" /*") elif (line.startswith("* @name")): newScriptLines.append(" * @name " + config.read_config("common.download_config.name")) elif (line.startswith("* @description")): @@ -65,10 +65,15 @@ async def generate_script_response(request): newScriptLines.append((" * @author helloplhm-qwq & Folltoshe & " + config.read_config("common.download_config.author")) if config.read_config("common.download_config.author") else " * @author helloplhm-qwq & Folltoshe") elif (line.startswith("* @version")): newScriptLines.append(" * @name " + config.read_config("common.download_config.version")) + elif (line.startswith("const DEV_ENABLE ")): + newScriptLines.append("const DEV_ENABLE = " + str(config.read_config("common.download_config.dev")).lower()) else: newScriptLines.append(line) + r = '\n'.join(newScriptLines) - return Response(text = '\n'.join(newScriptLines), content_type = 'text/javascript', + r = re.sub(r'const MUSIC_QUALITY = {[^}]+}', f'const MUSIC_QUALITY = JSON.parse(\'{json.dumps(config.read_config("common.download_config.quality"))}\')', r) + + return Response(text = r, content_type = 'text/javascript', headers = { 'Content-Disposition': 'attachment; filename=lx-music-source.js' })