feat: add switchable SlipOK and Slip2Go verification
Build and Push Image / build-backend (push) Successful in 2m27s
Build and Push Image / build-frontend (push) Successful in 4m4s
Build and Push Image / push (push) Successful in 1m1s

This commit is contained in:
2026-10-15 02:17:35 +07:00 Unverified
parent c3022f4d37
commit beb0cfaf3d
12 changed files with 792 additions and 68 deletions
+38 -8
View File
@@ -1,22 +1,52 @@
"use server";
import { revalidatePath } from "next/cache";
import { actionLog } from "@/lib/api";
import { db } from "@/lib/db";
import { settings } from "@/lib/db/schema";
import { adminCheck } from "@/lib/auth";
import { sse } from "@/lib/db/sse-endpoints";
import { syncAmber as syncAmberRaw } from "@/util/sync";
import type { ToastType } from "@/components/fake-toast";
import { actionLog } from "@/lib/api";
import { adminCheck } from "@/lib/auth";
import { db, primaryDb } from "@/lib/db";
import { settings } from "@/lib/db/schema";
import { sse } from "@/lib/db/sse-endpoints";
import { getSlipConfiguration, isSlipProvider } from "@/lib/slip-checker";
import { syncAmber as syncAmberRaw } from "@/util/sync";
export async function getSettongs() {
if (!(await adminCheck())) throw "Unauthorized";
const [
settangs = { enka: true, donatePromptpay: true, donateTruemoney: true },
] = await db.select().from(settings).limit(1);
settangs = {
enka: true,
donatePromptpay: true,
donateTruemoney: true,
slipCheckProvider: "slipok" as const,
},
] = await primaryDb.select().from(settings).limit(1);
return settangs;
}
export async function setSlipCheckProvider(provider: string) {
if (!(await adminCheck())) throw "Unauthorized";
if (!isSlipProvider(provider))
return { success: false as const, message: "บริการตรวจสอบสลิปไม่ถูกต้อง" };
try {
getSlipConfiguration(provider);
} catch (error) {
return {
success: false as const,
message: error instanceof Error ? error.message : "การตั้งค่าไม่ถูกต้อง",
};
}
await primaryDb
.insert(settings)
.values({ slipCheckProvider: provider })
.onConflictDoUpdate({
target: settings.id,
set: { slipCheckProvider: provider },
});
await actionLog("Changed slip verification provider", { provider });
revalidatePath("/admin/settings");
return { success: true as const, provider };
}
export async function toggleEnka(state: boolean) {
if (!(await adminCheck())) throw "Unauthorized";
await db