fix: 文件类型为 mihomo 配置时, 不应处理本地或远程内容字段

This commit is contained in:
xream 2025-02-15 20:32:29 +08:00
parent 6d3d6fa1b3
commit 8fc755ff02
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
3 changed files with 146 additions and 132 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.16.43", "version": "2.16.44",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {

View File

@ -15,46 +15,48 @@ export default function register($app) {
async function previewFile(req, res) { async function previewFile(req, res) {
try { try {
const file = req.body; const file = req.body;
let content; let content = '';
if ( if (file.type !== 'mihomoProfile') {
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 '';
}
}),
);
if ( if (
!file.ignoreFailedRemoteFile && file.source === 'local' &&
Object.keys(errors).length > 0 !['localFirst', 'remoteFirst'].includes(file.mergeSources)
) { ) {
throw new Error( content = file.content;
`文件 ${file.name} 的远程文件 ${Object.keys(errors).join( } 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') { if (
content.unshift(file.content); !file.ignoreFailedRemoteFile &&
} else if (file.mergeSources === 'remoteFirst') { Object.keys(errors).length > 0
content.push(file.content); ) {
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 // parse proxies

View File

@ -410,105 +410,117 @@ async function produceArtifact({
const allFiles = $.read(FILES_KEY); const allFiles = $.read(FILES_KEY);
const file = findByName(allFiles, name); const file = findByName(allFiles, name);
if (!file) throw new Error(`找不到文件 ${name}`); if (!file) throw new Error(`找不到文件 ${name}`);
let raw; let raw = '';
if (content && !['localFirst', 'remoteFirst'].includes(mergeSources)) { console.log(file);
raw = content; if (file.type !== 'mihomoProfile') {
} 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;
if ( if (
ignoreFailedRemoteFile != null && content &&
ignoreFailedRemoteFile !== '' !['localFirst', 'remoteFirst'].includes(mergeSources)
) { ) {
fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile; raw = content;
} } else if (url) {
if (!fileIgnoreFailedRemoteFile && Object.keys(errors).length > 0) { const errors = {};
throw new Error( raw = await Promise.all(
`文件 ${file.name} 的远程文件 ${Object.keys(errors).join( 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 (mergeSources === 'localFirst') { if (
raw.unshift(content); ignoreFailedRemoteFile != null &&
} else if (mergeSources === 'remoteFirst') { ignoreFailedRemoteFile !== ''
raw.push(content); ) {
} fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile;
} else if ( }
file.source === 'local' && if (
!['localFirst', 'remoteFirst'].includes(file.mergeSources) !fileIgnoreFailedRemoteFile &&
) { Object.keys(errors).length > 0
raw = file.content; ) {
} else { throw new Error(
const errors = {}; `文件 ${file.name} 的远程文件 ${Object.keys(
raw = await Promise.all( errors,
file.url ).join(', ')} 发生错误, 请查看日志`,
.split(/[\r\n]+/) );
.map((i) => i.trim()) }
.filter((i) => i.length) if (mergeSources === 'localFirst') {
.map(async (url) => { raw.unshift(content);
try { } else if (mergeSources === 'remoteFirst') {
return await download( raw.push(content);
url, }
ua || file.ua, } else if (
undefined, file.source === 'local' &&
file.proxy || proxy, !['localFirst', 'remoteFirst'].includes(file.mergeSources)
undefined,
undefined,
noCache,
);
} catch (err) {
errors[url] = err;
$.error(
`文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`,
);
return '';
}
}),
);
let fileIgnoreFailedRemoteFile = file.ignoreFailedRemoteFile;
if (
ignoreFailedRemoteFile != null &&
ignoreFailedRemoteFile !== ''
) { ) {
fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile; raw = file.content;
} } else {
if (!fileIgnoreFailedRemoteFile && Object.keys(errors).length > 0) { const errors = {};
throw new Error( raw = await Promise.all(
`文件 ${file.name} 的远程文件 ${Object.keys(errors).join( 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 (file.mergeSources === 'localFirst') { if (
raw.unshift(file.content); ignoreFailedRemoteFile != null &&
} else if (file.mergeSources === 'remoteFirst') { ignoreFailedRemoteFile !== ''
raw.push(file.content); ) {
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(); const files = (Array.isArray(raw) ? raw : [raw]).flat();