40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
'use server'
|
|
|
|
import { z } from 'zod'
|
|
import { PERMS } from '@/lib/permissions'
|
|
import { prisma } from '@/lib/prisma'
|
|
import { adminAction } from '@/lib/safe-action'
|
|
import { actionOk } from '@/lib/safe-action-shared'
|
|
import { logAudit } from '@/lib/services/audit'
|
|
import { rcon } from '@/lib/services/rcon'
|
|
|
|
const saveEmulatorSettingsSchema = z.object({
|
|
settings: z.record(z.string(), z.string()),
|
|
})
|
|
|
|
export const saveEmulatorSettings = adminAction(
|
|
{ permission: PERMS.SETTINGS_EDIT, schema: saveEmulatorSettingsSchema },
|
|
async (ctx) => {
|
|
const entries = Object.entries(ctx.data.settings)
|
|
|
|
for (const [key, value] of entries) {
|
|
await prisma.emulatorSettings.upsert({
|
|
where: { key },
|
|
update: { value: String(value) },
|
|
create: { key, value: String(value) },
|
|
})
|
|
}
|
|
|
|
await rcon.updateConfig()
|
|
|
|
logAudit({
|
|
userId: ctx.session.user.id,
|
|
action: 'emulator_settings_update',
|
|
target: 'EmulatorSettings',
|
|
after: ctx.data.settings,
|
|
})
|
|
|
|
return actionOk()
|
|
},
|
|
)
|