mirror of
https://github.com/MeoProject/lx-music-api-server.git
synced 2025-05-23 19:17:41 +08:00
fix: 修复源脚本检查更新
This commit is contained in:
parent
3ea3c75859
commit
10dcfdb8aa
@ -36,6 +36,12 @@ common:
|
|||||||
version: 修改为你的源版本
|
version: 修改为你的源版本
|
||||||
filename: lx-music-source.js # 客户端保存脚本时的文件名(可能因浏览器不同出现不一样的情况)
|
filename: lx-music-source.js # 客户端保存脚本时的文件名(可能因浏览器不同出现不一样的情况)
|
||||||
dev: true # 是否启用开发模式
|
dev: true # 是否启用开发模式
|
||||||
|
update: true # 是否开启脚本更新提醒
|
||||||
|
# 可用参数
|
||||||
|
# {updateUrl}为更新地址(带请求key)
|
||||||
|
# {url}为请求时的url(不带请求的param)
|
||||||
|
# {key}为请求时携带的key
|
||||||
|
updateMsg: "源脚本有更新啦,更新地址:\n{updateUrl}"
|
||||||
quality:
|
quality:
|
||||||
kw: [128k]
|
kw: [128k]
|
||||||
kg: [128k]
|
kg: [128k]
|
||||||
|
@ -95,6 +95,8 @@ async def generate_script_response(request):
|
|||||||
newScriptLines.append(" * @version " + config.read_config("common.download_config.version"))
|
newScriptLines.append(" * @version " + config.read_config("common.download_config.version"))
|
||||||
elif (line.startswith("const DEV_ENABLE ")):
|
elif (line.startswith("const DEV_ENABLE ")):
|
||||||
newScriptLines.append("const DEV_ENABLE = " + str(config.read_config("common.download_config.dev")).lower())
|
newScriptLines.append("const DEV_ENABLE = " + str(config.read_config("common.download_config.dev")).lower())
|
||||||
|
elif (line.startswith("const UPDATE_ENABLE ")):
|
||||||
|
newScriptLines.append("const UPDATE_ENABLE = " + str(config.read_config("common.download_config.update")).lower())
|
||||||
else:
|
else:
|
||||||
newScriptLines.append(oline)
|
newScriptLines.append(oline)
|
||||||
r = '\n'.join(newScriptLines)
|
r = '\n'.join(newScriptLines)
|
||||||
@ -102,13 +104,16 @@ async def generate_script_response(request):
|
|||||||
r = re.sub(r'const MUSIC_QUALITY = {[^}]+}', f'const MUSIC_QUALITY = JSON.parse(\'{json.dumps(config.read_config("common.download_config.quality"))}\')', r)
|
r = re.sub(r'const MUSIC_QUALITY = {[^}]+}', f'const MUSIC_QUALITY = JSON.parse(\'{json.dumps(config.read_config("common.download_config.quality"))}\')', r)
|
||||||
|
|
||||||
# 用于检查更新
|
# 用于检查更新
|
||||||
md5 = createMD5(r)
|
if (config.read_config("common.download_config.update")):
|
||||||
r = r.replace(r"const SCRIPT_MD5 = ''", f"const SCRIPT_MD5 = '{md5}'")
|
md5 = createMD5(r)
|
||||||
if (request.query.get('checkUpdate')):
|
r = r.replace(r"const SCRIPT_MD5 = ''", f"const SCRIPT_MD5 = '{md5}'")
|
||||||
if (request.query.get('checkUpdate') == md5):
|
if (request.query.get('checkUpdate')):
|
||||||
return {'code': 0, 'msg': 'success', 'data': None}, 200
|
if (request.query.get('checkUpdate') == md5):
|
||||||
updateUrl = f"{'https' if config.read_config('common.ssl_info.is_https') else 'http'}://{request.host}/script{('?key=' + request.query.get('key')) if request.query.get('key') else ''}"
|
return {'code': 0, 'msg': 'success', 'data': None}, 200
|
||||||
return {'code': 0, 'msg': 'success', 'data': {'updateMsg': f'源脚本有更新啦,更新地址:\n{updateUrl}', 'updateUrl': updateUrl}}, 200
|
url = f"{'https' if config.read_config('common.ssl_info.is_https') else 'http'}://{request.host}/script"
|
||||||
|
updateUrl = f"{url}{('?key=' + request.query.get('key')) if request.query.get('key') else ''}"
|
||||||
|
updateMsg = config.read_config('common.download_config.updateMsg').format(updateUrl = updateUrl, url = url, key = request.query.get('key')).replace('\\n', '\n')
|
||||||
|
return {'code': 0, 'msg': 'success', 'data': {'updateMsg': updateMsg, 'updateUrl': updateUrl}}, 200
|
||||||
|
|
||||||
return Response(text = r, content_type = 'text/javascript',
|
return Response(text = r, content_type = 'text/javascript',
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
// 是否开启开发模式
|
// 是否开启开发模式
|
||||||
const DEV_ENABLE = true
|
const DEV_ENABLE = true
|
||||||
|
// 是否开启更新提醒
|
||||||
|
const UPDATE_ENABLE = true
|
||||||
// 服务端地址
|
// 服务端地址
|
||||||
const API_URL = 'http://127.0.0.1:9763'
|
const API_URL = 'http://127.0.0.1:9763'
|
||||||
// 服务端配置的请求key
|
// 服务端配置的请求key
|
||||||
@ -281,6 +283,6 @@ on(EVENT_NAMES.request, ({ action, source, info }) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 检查更新
|
// 检查更新
|
||||||
checkUpdate()
|
if (UPDATE_ENABLE) checkUpdate()
|
||||||
// 向 LX Music 发送初始化成功事件
|
// 向 LX Music 发送初始化成功事件
|
||||||
send(EVENT_NAMES.inited, { status: true, openDevTools: DEV_ENABLE, sources: musicSources })
|
send(EVENT_NAMES.inited, { status: true, openDevTools: DEV_ENABLE, sources: musicSources })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user