Skip to content

Commit

Permalink
feat: 支持更多的脚本信息自定义
Browse files Browse the repository at this point in the history
  • Loading branch information
helloplhm-qwq committed Dec 24, 2023
1 parent 37f1b5b commit 02fe38e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 10 additions & 2 deletions common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 8 additions & 3 deletions common/lx_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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")):
Expand All @@ -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'
})
Expand Down

0 comments on commit 02fe38e

Please sign in to comment.