From 8fc755ff029777fccc4b170acc06338ed68f8301 Mon Sep 17 00:00:00 2001 From: xream Date: Sat, 15 Feb 2025 20:32:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=96=87=E4=BB=B6=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E4=B8=BA=20mihomo=20=E9=85=8D=E7=BD=AE=E6=97=B6,=20=E4=B8=8D?= =?UTF-8?q?=E5=BA=94=E5=A4=84=E7=90=86=E6=9C=AC=E5=9C=B0=E6=88=96=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E5=86=85=E5=AE=B9=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/preview.js | 76 +++++++------ backend/src/restful/sync.js | 200 +++++++++++++++++---------------- 3 files changed, 146 insertions(+), 132 deletions(-) diff --git a/backend/package.json b/backend/package.json index 39c783f..a239f3c 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.16.43", + "version": "2.16.44", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/preview.js b/backend/src/restful/preview.js index daabd1f..7d5c861 100644 --- a/backend/src/restful/preview.js +++ b/backend/src/restful/preview.js @@ -15,46 +15,48 @@ export default function register($app) { async function previewFile(req, res) { try { const file = req.body; - let content; - if ( - file.source === 'local' && - !['localFirst', 'remoteFirst'].includes(file.mergeSources) - ) { - content = file.content; - } else { - const errors = {}; - content = await Promise.all( - file.url - .split(/[\r\n]+/) - .map((i) => i.trim()) - .filter((i) => i.length) - .map(async (url) => { - try { - return await download(url, file.ua); - } catch (err) { - errors[url] = err; - $.error( - `文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`, - ); - return ''; - } - }), - ); - + let content = ''; + if (file.type !== 'mihomoProfile') { if ( - !file.ignoreFailedRemoteFile && - Object.keys(errors).length > 0 + file.source === 'local' && + !['localFirst', 'remoteFirst'].includes(file.mergeSources) ) { - throw new Error( - `文件 ${file.name} 的远程文件 ${Object.keys(errors).join( - ', ', - )} 发生错误, 请查看日志`, + content = file.content; + } else { + const errors = {}; + content = await Promise.all( + file.url + .split(/[\r\n]+/) + .map((i) => i.trim()) + .filter((i) => i.length) + .map(async (url) => { + try { + return await download(url, file.ua); + } catch (err) { + errors[url] = err; + $.error( + `文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`, + ); + return ''; + } + }), ); - } - if (file.mergeSources === 'localFirst') { - content.unshift(file.content); - } else if (file.mergeSources === 'remoteFirst') { - content.push(file.content); + + if ( + !file.ignoreFailedRemoteFile && + Object.keys(errors).length > 0 + ) { + throw new Error( + `文件 ${file.name} 的远程文件 ${Object.keys( + errors, + ).join(', ')} 发生错误, 请查看日志`, + ); + } + if (file.mergeSources === 'localFirst') { + content.unshift(file.content); + } else if (file.mergeSources === 'remoteFirst') { + content.push(file.content); + } } } // parse proxies diff --git a/backend/src/restful/sync.js b/backend/src/restful/sync.js index 4c0c369..6117a72 100644 --- a/backend/src/restful/sync.js +++ b/backend/src/restful/sync.js @@ -410,105 +410,117 @@ async function produceArtifact({ const allFiles = $.read(FILES_KEY); const file = findByName(allFiles, name); if (!file) throw new Error(`找不到文件 ${name}`); - let raw; - if (content && !['localFirst', 'remoteFirst'].includes(mergeSources)) { - raw = content; - } else if (url) { - const errors = {}; - raw = await Promise.all( - url - .split(/[\r\n]+/) - .map((i) => i.trim()) - .filter((i) => i.length) - .map(async (url) => { - try { - return await download( - url, - ua || file.ua, - undefined, - file.proxy || proxy, - undefined, - undefined, - noCache, - ); - } catch (err) { - errors[url] = err; - $.error( - `文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`, - ); - return ''; - } - }), - ); - let fileIgnoreFailedRemoteFile = file.ignoreFailedRemoteFile; + let raw = ''; + console.log(file); + if (file.type !== 'mihomoProfile') { if ( - ignoreFailedRemoteFile != null && - ignoreFailedRemoteFile !== '' + content && + !['localFirst', 'remoteFirst'].includes(mergeSources) ) { - fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile; - } - if (!fileIgnoreFailedRemoteFile && Object.keys(errors).length > 0) { - throw new Error( - `文件 ${file.name} 的远程文件 ${Object.keys(errors).join( - ', ', - )} 发生错误, 请查看日志`, + raw = content; + } else if (url) { + const errors = {}; + raw = await Promise.all( + url + .split(/[\r\n]+/) + .map((i) => i.trim()) + .filter((i) => i.length) + .map(async (url) => { + try { + return await download( + url, + ua || file.ua, + undefined, + file.proxy || proxy, + undefined, + undefined, + noCache, + ); + } catch (err) { + errors[url] = err; + $.error( + `文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`, + ); + return ''; + } + }), ); - } - if (mergeSources === 'localFirst') { - raw.unshift(content); - } else if (mergeSources === 'remoteFirst') { - raw.push(content); - } - } else if ( - file.source === 'local' && - !['localFirst', 'remoteFirst'].includes(file.mergeSources) - ) { - raw = file.content; - } else { - const errors = {}; - raw = await Promise.all( - file.url - .split(/[\r\n]+/) - .map((i) => i.trim()) - .filter((i) => i.length) - .map(async (url) => { - try { - return await download( - url, - ua || file.ua, - undefined, - file.proxy || proxy, - undefined, - undefined, - noCache, - ); - } catch (err) { - errors[url] = err; - $.error( - `文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`, - ); - return ''; - } - }), - ); - let fileIgnoreFailedRemoteFile = file.ignoreFailedRemoteFile; - if ( - ignoreFailedRemoteFile != null && - ignoreFailedRemoteFile !== '' + let fileIgnoreFailedRemoteFile = file.ignoreFailedRemoteFile; + if ( + ignoreFailedRemoteFile != null && + ignoreFailedRemoteFile !== '' + ) { + fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile; + } + if ( + !fileIgnoreFailedRemoteFile && + Object.keys(errors).length > 0 + ) { + throw new Error( + `文件 ${file.name} 的远程文件 ${Object.keys( + errors, + ).join(', ')} 发生错误, 请查看日志`, + ); + } + if (mergeSources === 'localFirst') { + raw.unshift(content); + } else if (mergeSources === 'remoteFirst') { + raw.push(content); + } + } else if ( + file.source === 'local' && + !['localFirst', 'remoteFirst'].includes(file.mergeSources) ) { - fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile; - } - if (!fileIgnoreFailedRemoteFile && Object.keys(errors).length > 0) { - throw new Error( - `文件 ${file.name} 的远程文件 ${Object.keys(errors).join( - ', ', - )} 发生错误, 请查看日志`, + raw = file.content; + } else { + const errors = {}; + raw = await Promise.all( + file.url + .split(/[\r\n]+/) + .map((i) => i.trim()) + .filter((i) => i.length) + .map(async (url) => { + try { + return await download( + url, + ua || file.ua, + undefined, + file.proxy || proxy, + undefined, + undefined, + noCache, + ); + } catch (err) { + errors[url] = err; + $.error( + `文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`, + ); + return ''; + } + }), ); - } - if (file.mergeSources === 'localFirst') { - raw.unshift(file.content); - } else if (file.mergeSources === 'remoteFirst') { - raw.push(file.content); + let fileIgnoreFailedRemoteFile = file.ignoreFailedRemoteFile; + if ( + ignoreFailedRemoteFile != null && + ignoreFailedRemoteFile !== '' + ) { + fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile; + } + if ( + !fileIgnoreFailedRemoteFile && + Object.keys(errors).length > 0 + ) { + throw new Error( + `文件 ${file.name} 的远程文件 ${Object.keys( + errors, + ).join(', ')} 发生错误, 请查看日志`, + ); + } + if (file.mergeSources === 'localFirst') { + raw.unshift(file.content); + } else if (file.mergeSources === 'remoteFirst') { + raw.push(file.content); + } } } const files = (Array.isArray(raw) ? raw : [raw]).flat();