mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-26 20:50:30 +08:00
Compare commits
3 Commits
b10075737f
...
392285058e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
392285058e | ||
|
|
508d7d63c9 | ||
|
|
9863c1a1de |
@ -9,7 +9,13 @@ let appConfig: IAppConfig // config.yaml
|
||||
export async function getAppConfig(force = false): Promise<IAppConfig> {
|
||||
if (force || !appConfig) {
|
||||
const data = await readFile(appConfigPath(), 'utf-8')
|
||||
appConfig = parse(data) || defaultConfig
|
||||
const parsedConfig = parse(data)
|
||||
const mergedConfig = deepMerge({ ...defaultConfig }, parsedConfig || {})
|
||||
if (JSON.stringify(mergedConfig) !== JSON.stringify(parsedConfig)) {
|
||||
await writeFile(appConfigPath(), stringify(mergedConfig))
|
||||
}
|
||||
|
||||
appConfig = mergedConfig
|
||||
}
|
||||
if (typeof appConfig !== 'object') appConfig = defaultConfig
|
||||
return appConfig
|
||||
|
||||
@ -191,9 +191,26 @@ export async function createProfile(item: Partial<IProfileItem>): Promise<IProfi
|
||||
timeout: subscriptionTimeout
|
||||
})
|
||||
}
|
||||
|
||||
// 检查状态码,例如: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'])
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ const ProfileCard: React.FC<Props> = (props) => {
|
||||
id: 'profile'
|
||||
})
|
||||
const transform = tf ? { x: tf.x, y: tf.y, scaleX: 1, scaleY: 1 } : null
|
||||
const info = items?.find((item) => item.id === current) ?? {
|
||||
const info = items?.find((item) => item && item.id === current) ?? {
|
||||
id: 'default',
|
||||
type: 'local',
|
||||
name: t('sider.cards.emptyProfile')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user