From 10dcfdb8aa41228b03ceed82549425b843411968 Mon Sep 17 00:00:00 2001 From: lerdb Date: Wed, 12 Jun 2024 19:27:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=BA=90=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=A3=80=E6=9F=A5=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/default_config.py | 6 ++++++ common/lx_script.py | 19 ++++++++++++------- lx-music-source-example.js | 4 +++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/common/default_config.py b/common/default_config.py index 80c415e..422aafb 100644 --- a/common/default_config.py +++ b/common/default_config.py @@ -36,6 +36,12 @@ common: version: 修改为你的源版本 filename: lx-music-source.js # 客户端保存脚本时的文件名(可能因浏览器不同出现不一样的情况) dev: true # 是否启用开发模式 + update: true # 是否开启脚本更新提醒 + # 可用参数 + # {updateUrl}为更新地址(带请求key) + # {url}为请求时的url(不带请求的param) + # {key}为请求时携带的key + updateMsg: "源脚本有更新啦,更新地址:\n{updateUrl}" quality: kw: [128k] kg: [128k] diff --git a/common/lx_script.py b/common/lx_script.py index 4ea9b6c..731f135 100644 --- a/common/lx_script.py +++ b/common/lx_script.py @@ -95,6 +95,8 @@ async def generate_script_response(request): newScriptLines.append(" * @version " + 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()) + elif (line.startswith("const UPDATE_ENABLE ")): + newScriptLines.append("const UPDATE_ENABLE = " + str(config.read_config("common.download_config.update")).lower()) else: newScriptLines.append(oline) 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) # 用于检查更新 - md5 = createMD5(r) - r = r.replace(r"const SCRIPT_MD5 = ''", f"const SCRIPT_MD5 = '{md5}'") - if (request.query.get('checkUpdate')): - if (request.query.get('checkUpdate') == md5): - return {'code': 0, 'msg': 'success', 'data': None}, 200 - 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': {'updateMsg': f'源脚本有更新啦,更新地址:\n{updateUrl}', 'updateUrl': updateUrl}}, 200 + if (config.read_config("common.download_config.update")): + md5 = createMD5(r) + r = r.replace(r"const SCRIPT_MD5 = ''", f"const SCRIPT_MD5 = '{md5}'") + if (request.query.get('checkUpdate')): + if (request.query.get('checkUpdate') == md5): + return {'code': 0, 'msg': 'success', 'data': None}, 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', headers = { diff --git a/lx-music-source-example.js b/lx-music-source-example.js index e0bc6cd..af37af0 100644 --- a/lx-music-source-example.js +++ b/lx-music-source-example.js @@ -8,6 +8,8 @@ // 是否开启开发模式 const DEV_ENABLE = true +// 是否开启更新提醒 +const UPDATE_ENABLE = true // 服务端地址 const API_URL = 'http://127.0.0.1:9763' // 服务端配置的请求key @@ -281,6 +283,6 @@ on(EVENT_NAMES.request, ({ action, source, info }) => { }) // 检查更新 -checkUpdate() +if (UPDATE_ENABLE) checkUpdate() // 向 LX Music 发送初始化成功事件 send(EVENT_NAMES.inited, { status: true, openDevTools: DEV_ENABLE, sources: musicSources })