mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-04 12:41:50 +08:00
fix: clean up proxy settings and empty pool handling
This commit is contained in:
1 parent
05dd5b40e8
commit
4b037bf5b0
5 files changed
+502
-107
No files matched your search
+35
-6
@@ -251,6 +251,13 @@ const del = <T>(p: string, body?: unknown) =>
|
||||
|
||||
// Go serializes nil slices as JSON null — coerce to [].
|
||||
const arr = <T>(x: T[] | null | undefined): T[] => x ?? [];
|
||||
|
||||
// Empty Go slices can arrive as null from older servers. Keep proxy-pool
|
||||
// consumers safe across initial load, import, and health-check refreshes.
|
||||
function normalizeProxyPool<T extends { entries: ProxyPoolEntry[]; switch_log: ProxySwitchLog[] }>(pool: T): T {
|
||||
return { ...pool, entries: arr(pool.entries), switch_log: arr(pool.switch_log) };
|
||||
}
|
||||
|
||||
const tq = (task?: string, sep: "?" | "&" = "?") => (task ? `${sep}task=${encodeURIComponent(task)}` : "");
|
||||
|
||||
// findingFilterParams 把发现页的筛选条件序列化成 query string。列表 / 分组 /
|
||||
@@ -994,13 +1001,35 @@ export const api = {
|
||||
// global_proxy 传空 = 测直连;probe_url 可覆盖默认探测地址(隔离网用)。
|
||||
testEgressProxy: (patch: { global_proxy?: string; probe_url?: string; resume?: boolean }) =>
|
||||
post<EgressReport>(`/settings/proxy/test`, patch),
|
||||
proxyPool: () => get<{ entries: ProxyPoolEntry[]; active_id: string; active_proxy: string; switch_log: ProxySwitchLog[] }>(`/settings/proxy-pool`),
|
||||
importProxyPool: (payload: Record<string, unknown>) => post<{ entries: ProxyPoolEntry[]; active_id: string; switch_log: ProxySwitchLog[]; errors: Array<{ line: number; input: string; error: string }> }>(`/settings/proxy-pool/import`, payload),
|
||||
updateProxyPool: (id: string, payload: Partial<Pick<ProxyPoolEntry, "url" | "name" | "remark" | "enabled">>) => put<{ entry: ProxyPoolEntry }>(`/settings/proxy-pool/${encodeURIComponent(id)}`, payload),
|
||||
proxyPool: () =>
|
||||
get<{ entries: ProxyPoolEntry[]; active_id: string; active_proxy: string; switch_log: ProxySwitchLog[] }>(
|
||||
`/settings/proxy-pool`,
|
||||
).then(normalizeProxyPool),
|
||||
importProxyPool: (payload: Record<string, unknown>) =>
|
||||
post<{
|
||||
entries: ProxyPoolEntry[];
|
||||
active_id: string;
|
||||
switch_log: ProxySwitchLog[];
|
||||
errors: Array<{ line: number; input: string; error: string }>;
|
||||
}>(`/settings/proxy-pool/import`, payload).then((r) => ({ ...normalizeProxyPool(r), errors: arr(r.errors) })),
|
||||
updateProxyPool: (id: string, payload: Partial<Pick<ProxyPoolEntry, "url" | "name" | "remark" | "enabled">>) =>
|
||||
put<{ entry: ProxyPoolEntry }>(`/settings/proxy-pool/${encodeURIComponent(id)}`, payload),
|
||||
deleteProxyPool: (id: string) => del<{ ok: boolean }>(`/settings/proxy-pool/${encodeURIComponent(id)}`),
|
||||
testProxyPoolEntry: (id: string) => post<{ ok: boolean; result?: EgressReport["checks"][number]["result"] }>(`/settings/proxy-pool/${encodeURIComponent(id)}/test`, {}),
|
||||
testAllProxyPool: () => post<{ entries: ProxyPoolEntry[]; active_id: string; switch_log: ProxySwitchLog[] }>(`/settings/proxy-pool/test-all`, {}),
|
||||
activateProxyPool: (id: string) => post<{ ok: boolean; active_id: string; active_proxy: string }>(`/settings/proxy-pool/${encodeURIComponent(id)}/activate`, {}),
|
||||
testProxyPoolEntry: (id: string) =>
|
||||
post<{ ok: boolean; result?: EgressReport["checks"][number]["result"] }>(
|
||||
`/settings/proxy-pool/${encodeURIComponent(id)}/test`,
|
||||
{},
|
||||
),
|
||||
testAllProxyPool: () =>
|
||||
post<{ entries: ProxyPoolEntry[]; active_id: string; switch_log: ProxySwitchLog[] }>(
|
||||
`/settings/proxy-pool/test-all`,
|
||||
{},
|
||||
).then(normalizeProxyPool),
|
||||
activateProxyPool: (id: string) =>
|
||||
post<{ ok: boolean; active_id: string; active_proxy: string }>(
|
||||
`/settings/proxy-pool/${encodeURIComponent(id)}/activate`,
|
||||
{},
|
||||
),
|
||||
testTaskProxy: (taskID: string) => post<{ ok: boolean; error?: string }>(`/tasks/${taskID}/proxy/test`, {}),
|
||||
|
||||
// ---- 漏洞 IM 推送 ----
|
||||
|
||||
Reference in new issue
Block a user