feat: 支持托管中转主机和节点接入线路
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"use server";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { requireAdminAccess } from "@/lib/session";
|
||||
import {
|
||||
deleteRelay,
|
||||
RelayError,
|
||||
saveRelayHost,
|
||||
saveRelayRoute,
|
||||
} from "@/lib/relays";
|
||||
const value = (form: FormData, key: string) => String(form.get(key) || "");
|
||||
async function run(work: () => Promise<unknown>) {
|
||||
await requireAdminAccess();
|
||||
try {
|
||||
await work();
|
||||
revalidatePath("/admin/relays");
|
||||
revalidatePath("/admin/subscriptions");
|
||||
} catch (e) {
|
||||
return {
|
||||
error: e instanceof RelayError ? e.message : "保存失败,请检查输入。",
|
||||
};
|
||||
}
|
||||
}
|
||||
export async function saveHostAction(form: FormData) {
|
||||
return run(() =>
|
||||
saveRelayHost({
|
||||
id: value(form, "id") || undefined,
|
||||
name: value(form, "name"),
|
||||
server_host: value(form, "server_host"),
|
||||
enabled: form.get("enabled") === "on",
|
||||
}),
|
||||
);
|
||||
}
|
||||
export async function saveRouteAction(form: FormData) {
|
||||
return run(() =>
|
||||
saveRelayRoute({
|
||||
id: value(form, "id") || undefined,
|
||||
name: value(form, "name"),
|
||||
host_id: value(form, "host_id"),
|
||||
node_id: value(form, "node_id"),
|
||||
public_port: value(form, "public_port"),
|
||||
listen_port: value(form, "listen_port"),
|
||||
enabled: form.get("enabled") === "on",
|
||||
}),
|
||||
);
|
||||
}
|
||||
export async function deleteHostAction(form: FormData) {
|
||||
return run(() => deleteRelay("host", value(form, "id")));
|
||||
}
|
||||
export async function deleteRouteAction(form: FormData) {
|
||||
return run(() => deleteRelay("route", value(form, "id")));
|
||||
}
|
||||
Reference in New Issue
Block a user