fix: simply compatible with proxy providers

This commit is contained in:
GyDi 2022-03-05 16:18:44 +08:00
parent b91daebd92
commit 08fa5205b0
No known key found for this signature in database
GPG Key ID: 1C95E0D3467B3084

View File

@ -96,20 +96,26 @@ export async function getProxies() {
let groups: ApiType.ProxyGroupItem[] = [];
// compatible with proxy-providers
const generateItem = (name: string) => {
if (records[name]) return records[name];
return { name, type: "unknown", udp: false, history: [] };
};
if (order) {
groups = order
.filter((name) => records[name]?.all)
.map((name) => records[name])
.map((each) => ({
...each,
all: each.all!.map((item) => records[item]),
all: each.all!.map((item) => generateItem(item)),
}));
} else {
groups = Object.values(records)
.filter((each) => each.name !== "GLOBAL" && each.all)
.map((each) => ({
...each,
all: each.all!.map((item) => records[item]),
all: each.all!.map((item) => generateItem(item)),
}));
groups.sort((a, b) => b.name.localeCompare(a.name));
}
@ -122,3 +128,10 @@ export async function getProxies() {
return { global, direct, groups, records, proxies };
}
// todo: get proxy providers
export async function getProviders() {
const instance = await getAxios();
const response = await instance.get<any, any>("/providers/proxies");
return response.providers as any;
}