From 08fa5205b02077410b198424e531dfa84429c52a Mon Sep 17 00:00:00 2001 From: GyDi Date: Sat, 5 Mar 2022 16:18:44 +0800 Subject: [PATCH] fix: simply compatible with proxy providers --- src/services/api.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/services/api.ts b/src/services/api.ts index 751e56f..d5c96c3 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -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("/providers/proxies"); + return response.providers as any; +}