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

View File

@ -7,7 +7,8 @@ import {
Button,
Input,
Select,
SelectItem
SelectItem,
Switch
} from '@nextui-org/react'
import React, { useState } from 'react'
import SettingItem from '../base/base-setting-item'
@ -58,29 +59,38 @@ const EditInfoModal: React.FC<Props> = (props) => {
/>
</SettingItem>
{values.type === 'remote' && (
<SettingItem title="订阅地址">
<Input
size="sm"
className="w-[200px]"
value={values.url}
onValueChange={(v) => {
setValues({ ...values, url: v })
}}
/>
</SettingItem>
)}
{values.type === 'remote' && (
<SettingItem title="更新间隔(分钟)">
<Input
size="sm"
type="number"
className="w-[200px]"
value={values.interval?.toString() ?? ''}
onValueChange={(v) => {
setValues({ ...values, interval: parseInt(v) })
}}
/>
</SettingItem>
<>
<SettingItem title="订阅地址">
<Input
size="sm"
className="w-[200px]"
value={values.url}
onValueChange={(v) => {
setValues({ ...values, url: v })
}}
/>
</SettingItem>
<SettingItem title="使用代理更新">
<Switch
size="sm"
isSelected={values.useProxy ?? false}
onValueChange={(v) => {
setValues({ ...values, useProxy: v })
}}
/>
</SettingItem>
<SettingItem title="更新间隔(分钟)">
<Input
size="sm"
type="number"
className="w-[200px]"
value={values.interval?.toString() ?? ''}
onValueChange={(v) => {
setValues({ ...values, interval: parseInt(v) })
}}
/>
</SettingItem>
</>
)}
<SettingItem title="覆写脚本">
<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 ProfileItem from '@renderer/components/profiles/profile-item'
import { useProfileConfig } from '@renderer/hooks/use-profile-config'
@ -27,6 +27,7 @@ const Profiles: React.FC = () => {
} = useProfileConfig()
const { current, items = [] } = profileConfig || {}
const [sortedItems, setSortedItems] = useState(items)
const [useProxy, setUseProxy] = useState(false)
const [importing, setImporting] = useState(false)
const [updating, setUpdating] = useState(false)
const [fileOver, setFileOver] = useState(false)
@ -34,7 +35,7 @@ const Profiles: React.FC = () => {
const sensors = useSensors(useSensor(PointerSensor))
const handleImport = async (): Promise<void> => {
setImporting(true)
await addProfileItem({ name: '', type: 'remote', url })
await addProfileItem({ name: '', type: 'remote', url, useProxy })
setImporting(false)
}
const pageRef = useRef<HTMLDivElement>(null)
@ -128,20 +129,30 @@ const Profiles: React.FC = () => {
value={url}
onValueChange={setUrl}
endContent={
<Button
size="sm"
isIconOnly
variant="light"
onPress={() => {
navigator.clipboard.readText().then((text) => {
setUrl(text)
})
}}
>
<MdContentPaste className="text-lg" />
</Button>
<>
<Button
size="sm"
isIconOnly
variant="light"
onPress={() => {
navigator.clipboard.readText().then((text) => {
setUrl(text)
})
}}
>
<MdContentPaste className="text-lg" />
</Button>
<Checkbox
className="whitespace-nowrap"
checked={useProxy}
onValueChange={setUseProxy}
>
</Checkbox>
</>
}
/>
<Button
size="sm"
color="primary"

View File

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