diff --git a/src/main/config/profile.ts b/src/main/config/profile.ts index 9ec6796..61e0f5f 100644 --- a/src/main/config/profile.ts +++ b/src/main/config/profile.ts @@ -142,6 +142,7 @@ export async function createProfile(item: Partial): Promise): Promise = { + 'User-Agent': userAgent || `mihomo.party/v${app.getVersion()} (clash.meta)` + } + if (item.authToken) { + headers['Authorization'] = item.authToken + } res = await chromeRequest.get(urlObj.toString(), { - headers: { - 'User-Agent': userAgent || `mihomo.party/v${app.getVersion()} (clash.meta)` - }, + headers, responseType: 'text', timeout: subscriptionTimeout }) } else { + const headers: Record = { + 'User-Agent': userAgent || `mihomo.party/v${app.getVersion()} (clash.meta)` + } + if (item.authToken) { + headers['Authorization'] = item.authToken + } res = await chromeRequest.get(item.url, { proxy: newItem.useProxy ? { @@ -175,9 +186,7 @@ export async function createProfile(item: Partial): Promise = (props) => { }} /> + + { + setValues({ ...values, authToken: v }) + }} + placeholder={t('profiles.editInfo.authTokenPlaceholder')} + /> + { const navigate = useNavigate() const [sortedItems, setSortedItems] = useState(items) const [useProxy, setUseProxy] = useState(false) + const [authToken, setAuthToken] = useState('') + const [showAdvanced, setShowAdvanced] = useState(false) const [subStoreImporting, setSubStoreImporting] = useState(false) const [importing, setImporting] = useState(false) const [updating, setUpdating] = useState(false) @@ -125,8 +128,15 @@ const Profiles: React.FC = () => { }, [subs, collections]) const handleImport = async (): Promise => { setImporting(true) - await addProfileItem({ name: '', type: 'remote', url, useProxy }) + await addProfileItem({ + name: '', + type: 'remote', + url, + useProxy, + authToken: authToken || undefined + }) setUrl('') + setAuthToken('') setImporting(false) } const pageRef = useRef(null) @@ -225,68 +235,79 @@ const Profiles: React.FC = () => { } >
-
- - - - {t('profiles.useProxy')} - - - } - /> +
+
+ + + + {t('profiles.useProxy')} + + + } + /> - - {useSubStore && ( - { - mutateSubs() - mutateCollections() - }} + + + + - + {t('profiles.import')} + + {useSubStore && ( + { + mutateSubs() + mutateCollections() + }} + > + + + { @@ -342,40 +363,53 @@ const Profiles: React.FC = () => { ))} - - )} - - - - - { - if (key === 'open') { - try { - const files = await getFilePath(['yml', 'yaml']) - if (files?.length) { - const content = await readTextFile(files[0]) - const fileName = files[0].split('/').pop()?.split('\\').pop() - await addProfileItem({ name: fileName, type: 'local', file: content }) + + )} + + + + + { + if (key === 'open') { + try { + const files = await getFilePath(['yml', 'yaml']) + if (files?.length) { + const content = await readTextFile(files[0]) + const fileName = files[0].split('/').pop()?.split('\\').pop() + await addProfileItem({ name: fileName, type: 'local', file: content }) + } + } catch (e) { + alert(e) } - } catch (e) { - alert(e) + } else if (key === 'new') { + await addProfileItem({ + name: t('profiles.newProfile'), + type: 'local', + file: 'proxies: []\nproxy-groups: []\nrules: []' + }) } - } else if (key === 'new') { - await addProfileItem({ - name: t('profiles.newProfile'), - type: 'local', - file: 'proxies: []\nproxy-groups: []\nrules: []' - }) - } - }} - > - {t('profiles.open')} - {t('profiles.new')} - - + }} + > + {t('profiles.open')} + {t('profiles.new')} + + +
+ {showAdvanced && ( + 🔑} + /> + )}
diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index b74b825..996f1af 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -492,6 +492,7 @@ interface IProfileItem { substore?: boolean allowFixedInterval?: boolean autoUpdate?: boolean + authToken?: string } interface ISubStoreSub {