Skip to content

Commit

Permalink
feat: 脚本下载优化
Browse files Browse the repository at this point in the history
  • Loading branch information
helloplhm-qwq committed Jan 13, 2024
1 parent 5fb8913 commit a20367b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class ConfigReadException(Exception):
"ports": [ 9763 ],
"_ports-desc": "服务器启动时所使用的端口",
"ssl_info": {
"desc": "服务器https配置",
"desc": "服务器https配置,is_https是这个服务器是否是https服务器,如果你使用了反向代理来转发这个服务器,如果它使用了https,也请将它设置为true",
"is_https": False,
"enable": False,
"ssl_ports": [ 443 ],
"path": {
Expand Down Expand Up @@ -85,9 +86,11 @@ class ConfigReadException(Exception):
"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"],
Expand Down
8 changes: 6 additions & 2 deletions common/lx_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"')
Expand All @@ -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')):
Expand Down
2 changes: 1 addition & 1 deletion modules/kw/encrypt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ----------------------------------------
# - mode: python -
# - author: helloplhm-qwq -
# - name: kwdes.py -
# - name: encrypt.py -
# - project: lx-music-api-server -
# - license: MIT -
# ----------------------------------------
Expand Down

0 comments on commit a20367b

Please sign in to comment.