mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-26 20:50:30 +08:00
fix: handle subscription with failed status code or invalid profile
This commit is contained in:
parent
9863c1a1de
commit
508d7d63c9
@ -192,8 +192,25 @@ export async function createProfile(item: Partial<IProfileItem>): Promise<IProfi
|
||||
})
|
||||
}
|
||||
|
||||
// 检查状态码,例如:403
|
||||
if (res.status < 200 || res.status >= 300) {
|
||||
throw new Error(`Subscription failed: Request status code ${res.status}`)
|
||||
}
|
||||
|
||||
const data = res.data
|
||||
const headers = res.headers
|
||||
|
||||
// 校验是否为对象结构 (拦截 HTML字符串、普通文本、乱码)
|
||||
const parsed = parse(data)
|
||||
if (typeof parsed !== 'object' || parsed === null) {
|
||||
throw new Error('Subscription failed: Profile is not a valid YAML')
|
||||
}
|
||||
// 检查是否包含必要的字段,防止空对象
|
||||
const profile = parsed as any
|
||||
if (!profile.proxies && !profile['proxy-providers']) {
|
||||
throw new Error('Subscription failed: Profile missing proxies or providers')
|
||||
}
|
||||
|
||||
if (headers['content-disposition'] && newItem.name === 'Remote File') {
|
||||
newItem.name = parseFilename(headers['content-disposition'])
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user