This commit is contained in:
xishang0128 2025-01-02 20:59:53 +08:00
parent d0a6d515a1
commit 8fe1f4f86b
4 changed files with 48 additions and 33 deletions

View File

@ -41,11 +41,10 @@ export async function patchControledMihomoConfig(patch: Partial<IMihomoConfig>):
controledMihomoConfig.dns = controledMihomoConfig.dns || {} controledMihomoConfig.dns = controledMihomoConfig.dns || {}
controledMihomoConfig.dns['nameserver-policy'] = patch.dns['nameserver-policy'] controledMihomoConfig.dns['nameserver-policy'] = patch.dns['nameserver-policy']
} }
controledMihomoConfig = deepMerge(controledMihomoConfig, patch) if (patch.dns?.['use-hosts']) {
if (patch.hosts && patch.dns?.['use-hosts']) {
delete controledMihomoConfig.hosts
controledMihomoConfig.hosts = patch.hosts controledMihomoConfig.hosts = patch.hosts
} }
controledMihomoConfig = deepMerge(controledMihomoConfig, patch)
if (!useNameserverPolicy) { if (!useNameserverPolicy) {
delete controledMihomoConfig?.dns?.['nameserver-policy'] delete controledMihomoConfig?.dns?.['nameserver-policy']
} }

View File

@ -27,7 +27,7 @@ const ProxyProvider: React.FC = () => {
if (showDetails.title) { if (showDetails.title) {
const fetchProviderPath = async (name: string): Promise<void> => { const fetchProviderPath = async (name: string): Promise<void> => {
try { try {
const providers= await getRuntimeConfig() const providers = await getRuntimeConfig()
const provider = providers['proxy-providers'][name] const provider = providers['proxy-providers'][name]
if (provider) { if (provider) {
setShowDetails((prev) => ({ setShowDetails((prev) => ({
@ -48,6 +48,20 @@ const ProxyProvider: React.FC = () => {
const providers = useMemo(() => { const providers = useMemo(() => {
if (!data) return [] if (!data) return []
return Object.values(data.providers) return Object.values(data.providers)
.map(provider => {
if (provider.vehicleType === 'Inline' || (provider.subscriptionInfo &&
provider.subscriptionInfo.Upload === 0 &&
provider.subscriptionInfo.Download === 0 &&
provider.subscriptionInfo.Total === 0 &&
provider.subscriptionInfo.Expire === 0)) {
return {
...provider,
subscriptionInfo: null
}
}
return provider
})
.filter(provider => 'subscriptionInfo' in provider) .filter(provider => 'subscriptionInfo' in provider)
.sort((a, b) => { .sort((a, b) => {
if (a.vehicleType === 'File' && b.vehicleType !== 'File') { if (a.vehicleType === 'File' && b.vehicleType !== 'File') {
@ -122,26 +136,28 @@ const ProxyProvider: React.FC = () => {
{/* <Button isIconOnly className="ml-2" size="sm"> {/* <Button isIconOnly className="ml-2" size="sm">
<IoMdEye className="text-lg" /> <IoMdEye className="text-lg" />
</Button> */} </Button> */}
<Button {provider.vehicleType !== 'Inline' && (
isIconOnly <Button
title={provider.vehicleType == 'File' ? '编辑' : '查看'} isIconOnly
className="ml-2" title={provider.vehicleType == 'File' ? '编辑' : '查看'}
size="sm" className="ml-2"
onPress={() => { size="sm"
setShowDetails({ onPress={() => {
show: false, setShowDetails({
path: provider.name, show: false,
type: provider.vehicleType, path: provider.name,
title: provider.name type: provider.vehicleType,
}) title: provider.name
}} })
> }}
{provider.vehicleType == 'File' ? ( >
<MdEditDocument className={`text-lg`} /> {provider.vehicleType == 'File' ? (
) : ( <MdEditDocument className={`text-lg`} />
<CgLoadbarDoc className={`text-lg`} /> ) : (
)} <CgLoadbarDoc className={`text-lg`} />
</Button> )}
</Button>
)}
<Button <Button
isIconOnly isIconOnly
title="更新" title="更新"

View File

@ -117,7 +117,7 @@ const RuleProvider: React.FC = () => {
> >
<div className="flex h-[32px] leading-[32px] text-foreground-500"> <div className="flex h-[32px] leading-[32px] text-foreground-500">
<div>{dayjs(provider.updatedAt).fromNow()}</div> <div>{dayjs(provider.updatedAt).fromNow()}</div>
{provider.format !== 'MrsRule' && ( {provider.format !== 'MrsRule' && provider.vehicleType !== 'Inline' && (
<Button <Button
isIconOnly isIconOnly
title={provider.vehicleType == 'File' ? '编辑' : '查看'} title={provider.vehicleType == 'File' ? '编辑' : '查看'}

View File

@ -12,7 +12,7 @@ const DNS: React.FC = () => {
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig() const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const { appConfig, patchAppConfig } = useAppConfig() const { appConfig, patchAppConfig } = useAppConfig()
const { nameserverPolicy, useNameserverPolicy } = appConfig || {} const { nameserverPolicy, useNameserverPolicy } = appConfig || {}
const { dns, hosts } = controledMihomoConfig || {} const { dns } = controledMihomoConfig || {}
const { const {
ipv6 = false, ipv6 = false,
'fake-ip-range': fakeIPRange = '198.18.0.1/16', 'fake-ip-range': fakeIPRange = '198.18.0.1/16',
@ -54,7 +54,7 @@ const DNS: React.FC = () => {
domain, domain,
value value
})), })),
hosts: Object.entries(hosts || {}).map(([domain, value]) => ({ domain, value })) hosts: useHosts ? [] : undefined
}) })
const setValues = (v: typeof values): void => { const setValues = (v: typeof values): void => {
@ -140,7 +140,7 @@ const DNS: React.FC = () => {
className="app-nodrag" className="app-nodrag"
color="primary" color="primary"
onPress={() => { onPress={() => {
const hostsObject = values.useHosts const hostsObject = values.useHosts && values.hosts && values.hosts.length > 0
? Object.fromEntries(values.hosts.map(({ domain, value }) => [domain, value])) ? Object.fromEntries(values.hosts.map(({ domain, value }) => [domain, value]))
: undefined : undefined
const dnsConfig = { const dnsConfig = {
@ -187,7 +187,7 @@ const DNS: React.FC = () => {
<Tab key="normal" title="取消映射" /> <Tab key="normal" title="取消映射" />
</Tabs> </Tabs>
</SettingItem> </SettingItem>
{values.enhancedMode === 'fake-ip' ? ( {values.enhancedMode === 'fake-ip' && (
<> <>
<SettingItem title="回应范围" divider> <SettingItem title="回应范围" divider>
<Input <Input
@ -205,7 +205,7 @@ const DNS: React.FC = () => {
</div> </div>
<Divider className="my-2" /> <Divider className="my-2" />
</> </>
) : null} )}
<SettingItem title="IPv6" divider> <SettingItem title="IPv6" divider>
<Switch <Switch
size="sm" size="sm"
@ -320,14 +320,14 @@ const DNS: React.FC = () => {
size="sm" size="sm"
isSelected={values.useHosts} isSelected={values.useHosts}
onValueChange={(v) => { onValueChange={(v) => {
setValues({ ...values, useHosts: v }) setValues({ ...values, useHosts: v, hosts: v ? [] : undefined })
}} }}
/> />
</SettingItem> </SettingItem>
{values.useHosts && ( {values.useHosts && (
<div className="flex flex-col items-stretch"> <div className="flex flex-col items-stretch">
<h3 className="mb-2"></h3> <h3 className="mb-2"></h3>
{[...values.hosts, { domain: '', value: '' }].map(({ domain, value }, index) => ( {[...(values.hosts || []), { domain: '', value: '' }].map(({ domain, value }, index) => (
<div key={index} className="flex mb-2"> <div key={index} className="flex mb-2">
<div className="flex-[4]"> <div className="flex-[4]">
<Input <Input
@ -354,7 +354,7 @@ const DNS: React.FC = () => {
value={Array.isArray(value) ? value.join(',') : value} value={Array.isArray(value) ? value.join(',') : value}
onValueChange={(v) => handleSubkeyChange('hosts', domain, v, index)} onValueChange={(v) => handleSubkeyChange('hosts', domain, v, index)}
/> />
{index < values.hosts.length && ( {index < (values.hosts || []).length && (
<Button <Button
size="sm" size="sm"
color="warning" color="warning"