Compare commits

...

3 Commits

3 changed files with 25 additions and 2 deletions

View File

@ -9,7 +9,13 @@ let appConfig: IAppConfig // config.yaml
export async function getAppConfig(force = false): Promise<IAppConfig> { export async function getAppConfig(force = false): Promise<IAppConfig> {
if (force || !appConfig) { if (force || !appConfig) {
const data = await readFile(appConfigPath(), 'utf-8') 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 if (typeof appConfig !== 'object') appConfig = defaultConfig
return appConfig return appConfig

View File

@ -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 data = res.data
const headers = res.headers 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') { if (headers['content-disposition'] && newItem.name === 'Remote File') {
newItem.name = parseFilename(headers['content-disposition']) newItem.name = parseFilename(headers['content-disposition'])
} }

View File

@ -45,7 +45,7 @@ const ProfileCard: React.FC<Props> = (props) => {
id: 'profile' id: 'profile'
}) })
const transform = tf ? { x: tf.x, y: tf.y, scaleX: 1, scaleY: 1 } : null 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', id: 'default',
type: 'local', type: 'local',
name: t('sider.cards.emptyProfile') name: t('sider.cards.emptyProfile')