mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-05 07:02:09 +08:00
fix: update js-yaml imports for v5
This commit is contained in:
@@ -32,7 +32,7 @@ import {
|
||||
cancelIdleCallback,
|
||||
requestIdleCallback,
|
||||
} from 'foxact/request-idle-callback'
|
||||
import yaml from 'js-yaml'
|
||||
import { dump, load } from 'js-yaml'
|
||||
import {
|
||||
startTransition,
|
||||
useCallback,
|
||||
@@ -126,7 +126,7 @@ const buildGroupsYaml = (
|
||||
append: IProxyGroupConfig[],
|
||||
deleteList: string[],
|
||||
) => {
|
||||
return yaml.dump(
|
||||
return dump(
|
||||
{
|
||||
prepend,
|
||||
append,
|
||||
@@ -334,7 +334,7 @@ export const GroupsEditorViewer = (props: Props) => {
|
||||
}
|
||||
const fetchContent = useCallback(async () => {
|
||||
const data = await readProfileFile(property)
|
||||
const obj = yaml.load(data) as ISeqProfileConfig | null
|
||||
const obj = load(data) as ISeqProfileConfig | null
|
||||
|
||||
setPrependSeq(obj?.prepend || [])
|
||||
setAppendSeq(obj?.append || [])
|
||||
@@ -358,7 +358,7 @@ export const GroupsEditorViewer = (props: Props) => {
|
||||
return
|
||||
}
|
||||
|
||||
const obj = yaml.load(currData) as ISeqProfileConfig | null
|
||||
const obj = load(currData) as ISeqProfileConfig | null
|
||||
startTransition(() => {
|
||||
setPrependSeq(obj?.prepend ?? [])
|
||||
setAppendSeq(obj?.append ?? [])
|
||||
@@ -397,13 +397,13 @@ export const GroupsEditorViewer = (props: Props) => {
|
||||
const fetchProxyPolicy = useCallback(async () => {
|
||||
const data = await readProfileFile(profileUid)
|
||||
const proxiesData = await readProfileFile(proxiesUid)
|
||||
const originGroupsObj = yaml.load(data) as {
|
||||
const originGroupsObj = load(data) as {
|
||||
'proxy-groups': IProxyGroupConfig[]
|
||||
} | null
|
||||
|
||||
const originProxiesObj = yaml.load(data) as { proxies: [] } | null
|
||||
const originProxiesObj = load(data) as { proxies: [] } | null
|
||||
const originProxies = originProxiesObj?.proxies || []
|
||||
const moreProxiesObj = yaml.load(proxiesData) as ISeqProfileConfig | null
|
||||
const moreProxiesObj = load(proxiesData) as ISeqProfileConfig | null
|
||||
const morePrependProxies = moreProxiesObj?.prepend || []
|
||||
const moreAppendProxies = moreProxiesObj?.append || []
|
||||
const moreDeleteProxies = normalizeDeleteSeq(moreProxiesObj?.delete)
|
||||
@@ -443,21 +443,21 @@ export const GroupsEditorViewer = (props: Props) => {
|
||||
const mergeData = await readProfileFile(mergeUid)
|
||||
const globalMergeData = await readProfileFile('Merge')
|
||||
|
||||
const originGroupsObj = yaml.load(data) as {
|
||||
const originGroupsObj = load(data) as {
|
||||
'proxy-groups': IProxyGroupConfig[]
|
||||
} | null
|
||||
|
||||
const originProviderObj = yaml.load(data) as {
|
||||
const originProviderObj = load(data) as {
|
||||
'proxy-providers': Record<string, unknown>
|
||||
} | null
|
||||
const originProvider = originProviderObj?.['proxy-providers'] || {}
|
||||
|
||||
const moreProviderObj = yaml.load(mergeData) as {
|
||||
const moreProviderObj = load(mergeData) as {
|
||||
'proxy-providers': Record<string, unknown>
|
||||
} | null
|
||||
const moreProvider = moreProviderObj?.['proxy-providers'] || {}
|
||||
|
||||
const globalProviderObj = yaml.load(globalMergeData) as {
|
||||
const globalProviderObj = load(globalMergeData) as {
|
||||
'proxy-providers': Record<string, unknown>
|
||||
} | null
|
||||
const globalProvider = globalProviderObj?.['proxy-providers'] || {}
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
styled,
|
||||
} from '@mui/material'
|
||||
import { useLockFn } from 'ahooks'
|
||||
import yaml from 'js-yaml'
|
||||
import { dump, load } from 'js-yaml'
|
||||
import {
|
||||
startTransition,
|
||||
useCallback,
|
||||
@@ -272,7 +272,7 @@ export const ProxiesEditorViewer = (props: Props) => {
|
||||
const fetchProfile = useCallback(async () => {
|
||||
const data = await readProfileFile(profileUid)
|
||||
|
||||
const originProxiesObj = yaml.load(data) as {
|
||||
const originProxiesObj = load(data) as {
|
||||
proxies: IProxyConfig[]
|
||||
} | null
|
||||
|
||||
@@ -281,7 +281,7 @@ export const ProxiesEditorViewer = (props: Props) => {
|
||||
|
||||
const fetchContent = useCallback(async () => {
|
||||
const data = await readProfileFile(property)
|
||||
const obj = yaml.load(data) as ISeqProfileConfig | null
|
||||
const obj = load(data) as ISeqProfileConfig | null
|
||||
|
||||
setPrependSeq(obj?.prepend || [])
|
||||
setAppendSeq(obj?.append || [])
|
||||
@@ -296,7 +296,7 @@ export const ProxiesEditorViewer = (props: Props) => {
|
||||
return
|
||||
}
|
||||
|
||||
const obj = yaml.load(currData) as ISeqProfileConfig | null
|
||||
const obj = load(currData) as ISeqProfileConfig | null
|
||||
startTransition(() => {
|
||||
setPrependSeq(obj?.prepend ?? [])
|
||||
setAppendSeq(obj?.append ?? [])
|
||||
@@ -312,7 +312,7 @@ export const ProxiesEditorViewer = (props: Props) => {
|
||||
const serialize = () => {
|
||||
try {
|
||||
setCurrData(
|
||||
yaml.dump(
|
||||
dump(
|
||||
{ prepend: prependSeq, append: appendSeq, delete: deleteSeq },
|
||||
{ forceQuotes: true },
|
||||
),
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
styled,
|
||||
} from '@mui/material'
|
||||
import { useLockFn } from 'ahooks'
|
||||
import yaml from 'js-yaml'
|
||||
import { dump, load } from 'js-yaml'
|
||||
import {
|
||||
startTransition,
|
||||
useCallback,
|
||||
@@ -407,7 +407,7 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
}
|
||||
const fetchContent = useCallback(async () => {
|
||||
const data = await readProfileFile(property)
|
||||
const obj = yaml.load(data) as ISeqProfileConfig | null
|
||||
const obj = load(data) as ISeqProfileConfig | null
|
||||
|
||||
setPrependSeq(obj?.prepend || [])
|
||||
setAppendSeq(obj?.append || [])
|
||||
@@ -422,7 +422,7 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
return
|
||||
}
|
||||
|
||||
const obj = yaml.load(currData) as ISeqProfileConfig | null
|
||||
const obj = load(currData) as ISeqProfileConfig | null
|
||||
startTransition(() => {
|
||||
setPrependSeq(obj?.prepend ?? [])
|
||||
setAppendSeq(obj?.append ?? [])
|
||||
@@ -439,7 +439,7 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
const serialize = () => {
|
||||
try {
|
||||
setCurrData(
|
||||
yaml.dump(
|
||||
dump(
|
||||
{ prepend: prependSeq, append: appendSeq, delete: deleteSeq },
|
||||
{ forceQuotes: true },
|
||||
),
|
||||
@@ -471,13 +471,13 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
const mergeData = await readProfileFile(mergeUid) // merge配置文件
|
||||
const globalMergeData = await readProfileFile('Merge') // global merge配置文件
|
||||
|
||||
const rulesObj = yaml.load(data) as { rules: [] } | null
|
||||
const rulesObj = load(data) as { rules: [] } | null
|
||||
|
||||
const originGroupsObj = yaml.load(data) as {
|
||||
const originGroupsObj = load(data) as {
|
||||
'proxy-groups': IProxyGroupConfig[]
|
||||
} | null
|
||||
const originGroups = originGroupsObj?.['proxy-groups'] || []
|
||||
const moreGroupsObj = yaml.load(groupsData) as ISeqProfileConfig | null
|
||||
const moreGroupsObj = load(groupsData) as ISeqProfileConfig | null
|
||||
const rawPrependGroups = moreGroupsObj?.['prepend']
|
||||
const morePrependGroups = Array.isArray(rawPrependGroups)
|
||||
? (rawPrependGroups as IProxyGroupConfig[])
|
||||
@@ -503,29 +503,29 @@ export const RulesEditorViewer = (props: Props) => {
|
||||
moreAppendGroups,
|
||||
)
|
||||
|
||||
const originRuleSetObj = yaml.load(data) as {
|
||||
const originRuleSetObj = load(data) as {
|
||||
'rule-providers': Record<string, unknown>
|
||||
} | null
|
||||
const originRuleSet = originRuleSetObj?.['rule-providers'] || {}
|
||||
const moreRuleSetObj = yaml.load(mergeData) as {
|
||||
const moreRuleSetObj = load(mergeData) as {
|
||||
'rule-providers': Record<string, unknown>
|
||||
} | null
|
||||
const moreRuleSet = moreRuleSetObj?.['rule-providers'] || {}
|
||||
const globalRuleSetObj = yaml.load(globalMergeData) as {
|
||||
const globalRuleSetObj = load(globalMergeData) as {
|
||||
'rule-providers': Record<string, unknown>
|
||||
} | null
|
||||
const globalRuleSet = globalRuleSetObj?.['rule-providers'] || {}
|
||||
const ruleSet = Object.assign({}, originRuleSet, moreRuleSet, globalRuleSet)
|
||||
|
||||
const originSubRuleObj = yaml.load(data) as {
|
||||
const originSubRuleObj = load(data) as {
|
||||
'sub-rules': Record<string, unknown>
|
||||
} | null
|
||||
const originSubRule = originSubRuleObj?.['sub-rules'] || {}
|
||||
const moreSubRuleObj = yaml.load(mergeData) as {
|
||||
const moreSubRuleObj = load(mergeData) as {
|
||||
'sub-rules': Record<string, unknown>
|
||||
} | null
|
||||
const moreSubRule = moreSubRuleObj?.['sub-rules'] || {}
|
||||
const globalSubRuleObj = yaml.load(globalMergeData) as {
|
||||
const globalSubRuleObj = load(globalMergeData) as {
|
||||
'sub-rules': Record<string, unknown>
|
||||
} | null
|
||||
const globalSubRule = globalSubRuleObj?.['sub-rules'] || {}
|
||||
|
||||
@@ -33,7 +33,7 @@ import {
|
||||
Typography,
|
||||
useTheme,
|
||||
} from '@mui/material'
|
||||
import yaml from 'js-yaml'
|
||||
import { load } from 'js-yaml'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
@@ -431,7 +431,7 @@ export const ProxyChain = ({
|
||||
if (chainConfigData) {
|
||||
try {
|
||||
// JSON is valid YAML, so one parser covers both persisted formats.
|
||||
const parsedConfig = yaml.load(chainConfigData) as ParsedChainConfig
|
||||
const parsedConfig = load(chainConfigData) as ParsedChainConfig
|
||||
const chainItems = toChainItems(parsedConfig)
|
||||
|
||||
if (chainItems.length > 0) {
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
} from '@mui/material'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { useLockFn } from 'ahooks'
|
||||
import yaml from 'js-yaml'
|
||||
import { dump, load } from 'js-yaml'
|
||||
import type { Ref } from 'react'
|
||||
import {
|
||||
useCallback,
|
||||
@@ -385,7 +385,7 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
config.hosts = hosts
|
||||
}
|
||||
|
||||
setYamlContent(yaml.dump(config, { forceQuotes: true }))
|
||||
setYamlContent(dump(config, { forceQuotes: true }))
|
||||
}, [generateDnsConfig, setYamlContent, values.hosts])
|
||||
|
||||
// 重置为默认值
|
||||
@@ -428,7 +428,7 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
// 从YAML更新表单值
|
||||
const updateValuesFromYaml = useCallback(() => {
|
||||
try {
|
||||
const parsedYaml = yaml.load(yamlContent) as any
|
||||
const parsedYaml = load(yamlContent) as any
|
||||
if (!parsedYaml) return
|
||||
|
||||
skipYamlSyncRef.current = true
|
||||
@@ -478,7 +478,7 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
|
||||
if (dnsConfigExists) {
|
||||
const dnsConfig = await invoke<string>('get_dns_config_content', {})
|
||||
const config = yaml.load(dnsConfig) as any
|
||||
const config = load(dnsConfig) as any
|
||||
|
||||
updateValuesFromConfig(config)
|
||||
setYamlContent(dnsConfig)
|
||||
@@ -524,7 +524,7 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
}
|
||||
} else {
|
||||
// 使用YAML编辑器的值
|
||||
const parsedConfig = yaml.load(yamlContent)
|
||||
const parsedConfig = load(yamlContent)
|
||||
if (typeof parsedConfig !== 'object' || parsedConfig === null) {
|
||||
throw new Error(t('settings.modals.dns.errors.invalid'))
|
||||
}
|
||||
@@ -594,7 +594,7 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
|
||||
// 允许YAML编辑后立即分析和更新表单值
|
||||
try {
|
||||
const config = yaml.load(value || '') as any
|
||||
const config = load(value || '') as any
|
||||
if (config && typeof config === 'object') {
|
||||
setTimeout(() => {
|
||||
updateValuesFromConfig(config)
|
||||
|
||||
Reference in New Issue
Block a user