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', ? {
host: '127.0.0.1', protocol: 'http',
port: mixedPort host: '127.0.0.1',
}, 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,29 +59,38 @@ const EditInfoModal: React.FC<Props> = (props) => {
/> />
</SettingItem> </SettingItem>
{values.type === 'remote' && ( {values.type === 'remote' && (
<SettingItem title="订阅地址"> <>
<Input <SettingItem title="订阅地址">
size="sm" <Input
className="w-[200px]" size="sm"
value={values.url} className="w-[200px]"
onValueChange={(v) => { value={values.url}
setValues({ ...values, url: v }) onValueChange={(v) => {
}} setValues({ ...values, url: v })
/> }}
</SettingItem> />
)} </SettingItem>
{values.type === 'remote' && ( <SettingItem title="使用代理更新">
<SettingItem title="更新间隔(分钟)"> <Switch
<Input size="sm"
size="sm" isSelected={values.useProxy ?? false}
type="number" onValueChange={(v) => {
className="w-[200px]" setValues({ ...values, useProxy: v })
value={values.interval?.toString() ?? ''} }}
onValueChange={(v) => { />
setValues({ ...values, interval: parseInt(v) }) </SettingItem>
}} <SettingItem title="更新间隔(分钟)">
/> <Input
</SettingItem> size="sm"
type="number"
className="w-[200px]"
value={values.interval?.toString() ?? ''}
onValueChange={(v) => {
setValues({ ...values, interval: parseInt(v) })
}}
/>
</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,20 +129,30 @@ const Profiles: React.FC = () => {
value={url} value={url}
onValueChange={setUrl} onValueChange={setUrl}
endContent={ endContent={
<Button <>
size="sm" <Button
isIconOnly size="sm"
variant="light" isIconOnly
onPress={() => { variant="light"
navigator.clipboard.readText().then((text) => { onPress={() => {
setUrl(text) navigator.clipboard.readText().then((text) => {
}) setUrl(text)
}} })
> }}
<MdContentPaste className="text-lg" /> >
</Button> <MdContentPaste className="text-lg" />
</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
} }