60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
"use server";
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
|
|
import { createStableId } from "@/lib/password";
|
|
import { requireAdminAccess } from "@/lib/session";
|
|
import {
|
|
getSubscriptionSettings,
|
|
saveProxyGroups,
|
|
saveSubscriptionSettings,
|
|
} from "@/lib/store";
|
|
|
|
export async function saveSubscriptionSettingsAction(formData: FormData) {
|
|
await requireAdminAccess();
|
|
|
|
await saveSubscriptionSettings({
|
|
template: String(formData.get("template") ?? ""),
|
|
extraProxyGroups: String(formData.get("extra_proxy_groups") ?? ""),
|
|
profileName: String(formData.get("profile_name") ?? "").trim() || "FeieProxy",
|
|
});
|
|
|
|
revalidatePath("/admin/subscriptions");
|
|
}
|
|
|
|
export async function saveProxyGroupAction(formData: FormData) {
|
|
await requireAdminAccess();
|
|
|
|
const settings = await getSubscriptionSettings();
|
|
const id = String(formData.get("id") ?? "").trim() || createStableId();
|
|
const name = String(formData.get("name") ?? "").trim();
|
|
const memberSlugs = formData
|
|
.getAll("member_slugs")
|
|
.map((value) => String(value))
|
|
.filter(Boolean);
|
|
|
|
if (!name) {
|
|
return;
|
|
}
|
|
|
|
const proxyGroups = settings.proxyGroups.filter((group) => group.id !== id);
|
|
proxyGroups.push({
|
|
id,
|
|
name,
|
|
type: "select",
|
|
memberSlugs,
|
|
});
|
|
|
|
await saveProxyGroups(proxyGroups);
|
|
revalidatePath("/admin/subscriptions");
|
|
}
|
|
|
|
export async function deleteProxyGroupAction(formData: FormData) {
|
|
await requireAdminAccess();
|
|
|
|
const settings = await getSubscriptionSettings();
|
|
const id = String(formData.get("id") ?? "").trim();
|
|
await saveProxyGroups(settings.proxyGroups.filter((group) => group.id !== id));
|
|
revalidatePath("/admin/subscriptions");
|
|
}
|