Skip to content

Commit c9d0e7e

Browse files
committed
feat: 增强 mihomo 输入的兼容性
1 parent 8b49cf5 commit c9d0e7e

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.36.20",
3+
"version": "2.36.21",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"packageManager": "pnpm@11.0.9",

backend/src/core/proxy-utils/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,33 @@ function formatTransportPath(path) {
719719
}
720720

721721
function lastParse(proxy) {
722+
// normalize keys to lowercase for all -opts keys and their subkeys
723+
// 通常来说够用了, 在重构之前暂不考虑引入更复杂的逻辑
724+
const hasOwn = (value, key) =>
725+
Object.prototype.hasOwnProperty.call(value, key);
726+
const normalizeOpts = (value) => {
727+
if (!value || typeof value !== 'object' || Array.isArray(value)) return;
728+
for (const key of Object.keys(value)) {
729+
const normalizedKey = key.toLowerCase();
730+
if (key !== normalizedKey) {
731+
if (!hasOwn(value, normalizedKey)) {
732+
value[normalizedKey] = value[key];
733+
}
734+
delete value[key];
735+
}
736+
}
737+
};
738+
for (const key of Object.keys(proxy)) {
739+
const normalizedKey = key.toLowerCase();
740+
if (!normalizedKey.endsWith('-opts')) continue;
741+
if (key !== normalizedKey) {
742+
if (!hasOwn(proxy, normalizedKey)) {
743+
proxy[normalizedKey] = proxy[key];
744+
}
745+
delete proxy[key];
746+
}
747+
normalizeOpts(proxy[normalizedKey]);
748+
}
722749
proxy.udp = ![false, 0, '0', 'false', 'off'].includes(
723750
typeof proxy.udp === 'string' ? proxy.udp.toLowerCase() : proxy.udp,
724751
);

0 commit comments

Comments
 (0)