fetch profile use no proxy

This commit is contained in:
pompurin404 2024-08-16 17:18:53 +08:00
parent d9f190796f
commit 60bfd92a68
No known key found for this signature in database
4 changed files with 68 additions and 43 deletions

View File

@ -103,6 +103,7 @@ export async function createProfile(item: Partial<IProfileItem>): Promise<IProfi
url: item.url, url: item.url,
interval: item.interval || 0, interval: item.interval || 0,
override: item.override || [], override: item.override || [],
useProxy: item.useProxy || false,
updated: new Date().getTime() updated: new Date().getTime()
} as IProfileItem } as IProfileItem
switch (newItem.type) { switch (newItem.type) {
@ -111,11 +112,13 @@ export async function createProfile(item: Partial<IProfileItem>): Promise<IProfi
const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig() const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig()
if (!item.url) throw new Error('Empty URL') if (!item.url) throw new Error('Empty URL')
const res = await axios.get(item.url, { const res = await axios.get(item.url, {
proxy: { proxy: newItem.useProxy
? {
protocol: 'http', protocol: 'http',
host: '127.0.0.1', host: '127.0.0.1',
port: mixedPort port: mixedPort
}, }
: false,
headers: { headers: {
'User-Agent': userAgent 'User-Agent': userAgent
} }

View File

@ -7,7 +7,8 @@ import {
Button, Button,
Input, Input,
Select, Select,
SelectItem SelectItem,
Switch
} from '@nextui-org/react' } from '@nextui-org/react'
import React, { useState } from 'react' import React, { useState } from 'react'
import SettingItem from '../base/base-setting-item' import SettingItem from '../base/base-setting-item'
@ -58,6 +59,7 @@ const EditInfoModal: React.FC<Props> = (props) => {
/> />
</SettingItem> </SettingItem>
{values.type === 'remote' && ( {values.type === 'remote' && (
<>
<SettingItem title="订阅地址"> <SettingItem title="订阅地址">
<Input <Input
size="sm" size="sm"
@ -68,8 +70,15 @@ const EditInfoModal: React.FC<Props> = (props) => {
}} }}
/> />
</SettingItem> </SettingItem>
)} <SettingItem title="使用代理更新">
{values.type === 'remote' && ( <Switch
size="sm"
isSelected={values.useProxy ?? false}
onValueChange={(v) => {
setValues({ ...values, useProxy: v })
}}
/>
</SettingItem>
<SettingItem title="更新间隔(分钟)"> <SettingItem title="更新间隔(分钟)">
<Input <Input
size="sm" size="sm"
@ -81,6 +90,7 @@ const EditInfoModal: React.FC<Props> = (props) => {
}} }}
/> />
</SettingItem> </SettingItem>
</>
)} )}
<SettingItem title="覆写脚本"> <SettingItem title="覆写脚本">
<Select <Select

View File

@ -1,4 +1,4 @@
import { Button, Input } from '@nextui-org/react' import { Button, Checkbox, Input } from '@nextui-org/react'
import BasePage from '@renderer/components/base/base-page' import BasePage from '@renderer/components/base/base-page'
import ProfileItem from '@renderer/components/profiles/profile-item' import ProfileItem from '@renderer/components/profiles/profile-item'
import { useProfileConfig } from '@renderer/hooks/use-profile-config' import { useProfileConfig } from '@renderer/hooks/use-profile-config'
@ -27,6 +27,7 @@ const Profiles: React.FC = () => {
} = useProfileConfig() } = useProfileConfig()
const { current, items = [] } = profileConfig || {} const { current, items = [] } = profileConfig || {}
const [sortedItems, setSortedItems] = useState(items) const [sortedItems, setSortedItems] = useState(items)
const [useProxy, setUseProxy] = useState(false)
const [importing, setImporting] = useState(false) const [importing, setImporting] = useState(false)
const [updating, setUpdating] = useState(false) const [updating, setUpdating] = useState(false)
const [fileOver, setFileOver] = useState(false) const [fileOver, setFileOver] = useState(false)
@ -34,7 +35,7 @@ const Profiles: React.FC = () => {
const sensors = useSensors(useSensor(PointerSensor)) const sensors = useSensors(useSensor(PointerSensor))
const handleImport = async (): Promise<void> => { const handleImport = async (): Promise<void> => {
setImporting(true) setImporting(true)
await addProfileItem({ name: '', type: 'remote', url }) await addProfileItem({ name: '', type: 'remote', url, useProxy })
setImporting(false) setImporting(false)
} }
const pageRef = useRef<HTMLDivElement>(null) const pageRef = useRef<HTMLDivElement>(null)
@ -128,6 +129,7 @@ const Profiles: React.FC = () => {
value={url} value={url}
onValueChange={setUrl} onValueChange={setUrl}
endContent={ endContent={
<>
<Button <Button
size="sm" size="sm"
isIconOnly isIconOnly
@ -140,8 +142,17 @@ const Profiles: React.FC = () => {
> >
<MdContentPaste className="text-lg" /> <MdContentPaste className="text-lg" />
</Button> </Button>
<Checkbox
className="whitespace-nowrap"
checked={useProxy}
onValueChange={setUseProxy}
>
</Checkbox>
</>
} }
/> />
<Button <Button
size="sm" size="sm"
color="primary" color="primary"

View File

@ -355,5 +355,6 @@ interface IProfileItem {
home?: string home?: string
updated?: number updated?: number
override?: string[] override?: string[]
useProxy?: boolean
extra?: ISubscriptionUserInfo extra?: ISubscriptionUserInfo
} }