From 455892b41436e49e9c82b9f90ca1d4f7645754a3 Mon Sep 17 00:00:00 2001 From: Sukka Date: Sat, 15 Jun 2024 19:23:58 +0800 Subject: [PATCH] fix(#1203): correct types (#1207) --- src/services/api.ts | 57 ++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/src/services/api.ts b/src/services/api.ts index 58b9ad74..a82edda1 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -134,43 +134,32 @@ export const getProxies = async () => { const { GLOBAL: global, DIRECT: direct, REJECT: reject } = proxyRecord; - interface Group { - all: IProxyItem[]; - name: string; - type: string; - udp: boolean; - xudp: boolean; - tfo: boolean; - history: { - time: string; - delay: number; - }[]; - } + let groups: IProxyGroupItem[] = Object.values(proxyRecord).reduce< + IProxyGroupItem[] + >((acc, each) => { + if (each.name !== "GLOBAL" && each.all) { + acc.push({ + ...each, + all: each.all!.map((item) => generateItem(item)), + }); + } - let groups: Group[] = Object.values(proxyRecord).reduce( - (acc, each) => { - if (each.name !== "GLOBAL" && each.all) { - acc.push({ - ...each, - all: each.all!.map((item) => generateItem(item)), - }); - } - - return acc; - }, - [] - ); + return acc; + }, []); if (global?.all) { - let globalGroups: Group[] = global.all.reduce((acc, name) => { - if (proxyRecord[name]?.all) { - acc.push({ - ...proxyRecord[name], - all: proxyRecord[name].all!.map((item) => generateItem(item)), - }); - } - return acc; - }, []); + let globalGroups: IProxyGroupItem[] = global.all.reduce( + (acc, name) => { + if (proxyRecord[name]?.all) { + acc.push({ + ...proxyRecord[name], + all: proxyRecord[name].all!.map((item) => generateItem(item)), + }); + } + return acc; + }, + [] + ); let globalNames = new Set(globalGroups.map((each) => each.name)); groups = groups