Skip to content
Snippets Groups Projects
Commit 433716cf authored by GyDi's avatar GyDi
Browse files

feat: optimize the proxy group order

parent e737bb4c
No related branches found
No related tags found
No related merge requests found
...@@ -12,35 +12,39 @@ export interface ProxyItem { ...@@ -12,35 +12,39 @@ export interface ProxyItem {
now?: string; now?: string;
} }
export type ProxyGroupItem = Omit<ProxyItem, "all" | "now"> & { export type ProxyGroupItem = Omit<ProxyItem, "all"> & {
all?: ProxyItem[]; all: ProxyItem[];
now?: string;
}; };
/// Get the Proxy infomation /// Get the Proxy infomation
export async function getProxyInfo() { export async function getProxyInfo() {
const response = (await axiosIns.get("/proxies")) as any; const response = (await axiosIns.get("/proxies")) as any;
const results = (response?.proxies ?? {}) as Record<string, ProxyItem>; const proxies = (response?.proxies ?? {}) as Record<string, ProxyItem>;
const global = results["GLOBAL"] || results["global"]; const global = proxies["GLOBAL"];
const proxies = Object.values(results).filter((each) => each.all == null); const order = global?.all;
const groups = Object.values(results).filter( let groups: ProxyGroupItem[] = [];
(each) => each.name.toLocaleUpperCase() !== "GLOBAL" && each.all != null
) as ProxyGroupItem[]; if (order) {
groups = order
groups.forEach((each) => { .filter((name) => proxies[name]?.all)
// @ts-ignore .map((name) => proxies[name])
each.all = each.all?.map((item) => results[item]).filter((e) => e); .map((each) => ({
}); ...each,
all: each.all!.map((item) => proxies[item]),
groups.sort((a, b) => b.name.localeCompare(a.name)); }));
} else {
return { groups = Object.values(proxies)
global, .filter((each) => each.name !== "GLOBAL" && each.all)
groups, .map((each) => ({
proxies, ...each,
}; all: each.all!.map((item) => proxies[item]),
}));
groups.sort((a, b) => b.name.localeCompare(a.name));
}
return { global, groups, proxies };
} }
/// Update the Proxy Choose /// Update the Proxy Choose
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment