feat: 支持更多的脚本信息自定义

This commit is contained in:
helloplhm-qwq 2023-12-24 16:22:45 +08:00
parent 37f1b5bbb0
commit 02fe38e780
No known key found for this signature in database
GPG Key ID: B7542212855B2C26
2 changed files with 18 additions and 5 deletions

View File

@ -68,11 +68,19 @@ default = {
"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": {

View File

@ -13,6 +13,8 @@ from . import scheduler
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'
})