feat: connect guarded asset import api
This commit is contained in:
1 parent
3497df9dfd
commit
eb759f54bf
26 files changed
+2342
-24
No files matched your search
+16
-21
@@ -1,24 +1,19 @@
|
||||
"use server";
|
||||
'use server'
|
||||
|
||||
import { requireStaff } from "@/lib/admin/guard";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import type { ActionResult } from "@/lib/safe-action-shared";
|
||||
import { z } from 'zod'
|
||||
import { PERMS } from '@/lib/permissions'
|
||||
import { adminAction } from '@/lib/safe-action'
|
||||
import { actionOk } from '@/lib/safe-action-shared'
|
||||
import { cleanupConvertedSwfs, deleteImportedItem } from '@/lib/services/furni-import'
|
||||
|
||||
export async function cleanSwfFiles(): Promise<ActionResult<{ deleted: number; remaining: number }>> {
|
||||
try {
|
||||
await requireStaff();
|
||||
return { ok: true, data: { deleted: 0, remaining: 0 } };
|
||||
} catch {
|
||||
return { ok: false, error: "Failed to clean SWF files" };
|
||||
}
|
||||
}
|
||||
export const cleanSwfFiles = adminAction({ permission: PERMS.ASSETS_IMPORT }, async () => {
|
||||
const result = await cleanupConvertedSwfs()
|
||||
return actionOk(result as unknown as Record<string, unknown>)
|
||||
})
|
||||
|
||||
export async function deleteImportedFurni({ classname }: { classname: string }) {
|
||||
await requireStaff();
|
||||
try {
|
||||
await prisma.itemsBase.deleteMany({ where: { itemName: classname } });
|
||||
return { ok: true as const, data: { deletedFiles: [classname], errors: [] as string[] } };
|
||||
} catch {
|
||||
return { ok: false as const, error: `Failed to delete ${classname}` };
|
||||
}
|
||||
}
|
||||
const deleteSchema = z.object({ classname: z.string().trim().min(1) })
|
||||
|
||||
export const deleteImportedFurni = adminAction(
|
||||
{ permission: PERMS.ASSETS_IMPORT, schema: deleteSchema },
|
||||
async (ctx) => actionOk((await deleteImportedItem(ctx.data.classname)) as unknown as Record<string, unknown>),
|
||||
)
|
||||
Reference in new issue
Block a user