mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-17 02:25:02 +03:00
554d85c2f7
* feat: select node inbounds for synchronization Allow node owners to import either all remote inbounds or an explicit tag-based selection. Add remote inbound discovery, persistence, snapshot filtering, API documentation, tests, and localized UI labels. * fix * fix: scope node reconcile and orphan sweep to selected inbound tags In 'selected' sync mode unselected inbounds never enter the panel DB, so ReconcileNode treated them as undesired and deleted them from the node the first time it went config-dirty. Reconcile now only sweeps remote tags that are part of the selection; everything else on the node is unmanaged. Panel-created or renamed inbounds on a selected-mode node also vanished: their tag was outside the selection, so the next traffic pull filtered them out of the snapshot and the orphan sweep silently dropped the central row. AddInbound/UpdateInbound now allow the tag on the node before committing. --------- Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
86 lines
3.2 KiB
TypeScript
86 lines
3.2 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
import { HttpUtil, Msg } from '@/utils';
|
|
import { parseMsg } from '@/utils/zodValidate';
|
|
import { keys } from '@/api/queryKeys';
|
|
import type { NodeRecord } from '@/api/queries/useNodesQuery';
|
|
import { ProbeResultSchema, type ProbeResult } from '@/schemas/node';
|
|
|
|
export type { ProbeResult };
|
|
|
|
export interface NodeUpdateResult {
|
|
id: number;
|
|
name?: string;
|
|
ok: boolean;
|
|
error?: string;
|
|
}
|
|
|
|
export interface RemoteInboundOption {
|
|
tag: string;
|
|
remark?: string;
|
|
protocol?: string;
|
|
port?: number;
|
|
}
|
|
|
|
export function useNodeMutations() {
|
|
const queryClient = useQueryClient();
|
|
const invalidate = () => queryClient.invalidateQueries({ queryKey: keys.nodes.root() });
|
|
|
|
const createMut = useMutation({
|
|
mutationFn: (payload: Partial<NodeRecord>) =>
|
|
HttpUtil.post('/panel/api/nodes/add', payload),
|
|
onSuccess: (msg) => { if (msg?.success) invalidate(); },
|
|
});
|
|
|
|
const updateMut = useMutation({
|
|
mutationFn: ({ id, payload }: { id: number; payload: Partial<NodeRecord> }) =>
|
|
HttpUtil.post(`/panel/api/nodes/update/${id}`, payload),
|
|
onSuccess: (msg) => { if (msg?.success) invalidate(); },
|
|
});
|
|
|
|
const removeMut = useMutation({
|
|
mutationFn: (id: number) =>
|
|
HttpUtil.post(`/panel/api/nodes/del/${id}`),
|
|
onSuccess: (msg) => { if (msg?.success) invalidate(); },
|
|
});
|
|
|
|
const setEnableMut = useMutation({
|
|
mutationFn: ({ id, enable }: { id: number; enable: boolean }) =>
|
|
HttpUtil.post(`/panel/api/nodes/setEnable/${id}`, { enable }),
|
|
onSuccess: (msg) => { if (msg?.success) invalidate(); },
|
|
});
|
|
|
|
const probeMut = useMutation({
|
|
mutationFn: async (id: number): Promise<Msg<ProbeResult>> => {
|
|
const raw = await HttpUtil.post(`/panel/api/nodes/probe/${id}`);
|
|
return parseMsg(raw, ProbeResultSchema, 'nodes/probe');
|
|
},
|
|
onSuccess: (msg) => { if (msg?.success) invalidate(); },
|
|
});
|
|
|
|
const updatePanelsMut = useMutation({
|
|
mutationFn: (ids: number[]) =>
|
|
HttpUtil.post<NodeUpdateResult[]>('/panel/api/nodes/updatePanel', { ids }, {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
}),
|
|
onSuccess: (msg) => { if (msg?.success) invalidate(); },
|
|
});
|
|
|
|
return {
|
|
create: (payload: Partial<NodeRecord>) => createMut.mutateAsync(payload),
|
|
update: (id: number, payload: Partial<NodeRecord>) => updateMut.mutateAsync({ id, payload }),
|
|
remove: (id: number) => removeMut.mutateAsync(id),
|
|
setEnable: (id: number, enable: boolean) => setEnableMut.mutateAsync({ id, enable }),
|
|
probe: (id: number) => probeMut.mutateAsync(id),
|
|
updatePanels: (ids: number[]): Promise<Msg<NodeUpdateResult[]>> => updatePanelsMut.mutateAsync(ids),
|
|
testConnection: async (payload: Partial<NodeRecord>): Promise<Msg<ProbeResult>> => {
|
|
const raw = await HttpUtil.post('/panel/api/nodes/test', payload);
|
|
return parseMsg(raw, ProbeResultSchema, 'nodes/test');
|
|
},
|
|
fetchFingerprint: (payload: Partial<NodeRecord>): Promise<Msg<string>> =>
|
|
HttpUtil.post<string>('/panel/api/nodes/certFingerprint', payload),
|
|
fetchInbounds: (payload: Partial<NodeRecord>): Promise<Msg<RemoteInboundOption[]>> =>
|
|
HttpUtil.post<RemoteInboundOption[]>('/panel/api/nodes/inbounds', payload),
|
|
};
|
|
}
|