feat: 脚本下载优化

This commit is contained in:
helloplhm-qwq
2024-01-13 13:55:44 +08:00
parent 5fb8913704
commit a20367b86e
3 changed files with 12 additions and 5 deletions

View File

@ -52,7 +52,8 @@ default = {
"ports": [ 9763 ],
"_ports-desc": "服务器启动时所使用的端口",
"ssl_info": {
"desc": "服务器https配置",
"desc": "服务器https配置is_https是这个服务器是否是https服务器如果你使用了反向代理来转发这个服务器如果它使用了https也请将它设置为true",
"is_https": False,
"enable": False,
"ssl_ports": [ 443 ],
"path": {
@ -85,9 +86,11 @@ default = {
"intro": "修改为你的源脚本描述",
"author": "修改为你的源脚本作者",
"version": "修改为你的源版本",
"filename": "lx-music-source.js",
"_filename-desc": "客户端保存脚本时的文件名(可能因浏览器不同出现不一样的情况)",
"dev": True,
"quality": {
"kw": ["128k", "320k", "flac"],
"kw": ["128k"],
"kg": ["128k"],
"tx": ["128k"],
"wy": ["128k"],

View File

@ -79,6 +79,7 @@ async def generate_script_response(request):
scriptLines = script.split('\n')
newScriptLines = []
for line in scriptLines:
oline = line
line = line.strip()
if (line.startswith('const API_URL')):
newScriptLines.append(f'const API_URL = "{request.scheme}://{request.host}"')
@ -95,14 +96,17 @@ async def generate_script_response(request):
elif (line.startswith("const DEV_ENABLE ")):
newScriptLines.append("const DEV_ENABLE = " + str(config.read_config("common.download_config.dev")).lower())
else:
newScriptLines.append(line)
newScriptLines.append(oline)
r = '\n'.join(newScriptLines)
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'
'Content-Disposition': f'attachment; filename={
config.read_config("common.download_config.filename")
if config.read_config("common.download_config.filename").endswith(".js")
else (config.read_config("common.download_config.filename" + ".js"))}'
})
if (config.read_config('common.allow_download_script')):

View File

@ -1,7 +1,7 @@
# ----------------------------------------
# - mode: python -
# - author: helloplhm-qwq -
# - name: kwdes.py -
# - name: encrypt.py -
# - project: lx-music-api-server -
# - license: MIT -
# ----------------------------------------