- Fix 17 unused ctx params in module-builder, verbandsverwaltung, sitzungsprotokolle actions - Remove unused CardDescription/CardHeader/CardTitle from pricing calculator - Remove unused FileSignature import from layout
70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
'use server';
|
|
|
|
import { z } from 'zod';
|
|
|
|
import { authActionClient } from '@kit/next/safe-action';
|
|
import { getLogger } from '@kit/shared/logger';
|
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
|
|
|
import { createModuleBuilderApi } from '../api';
|
|
|
|
export const uploadFile = authActionClient
|
|
.inputSchema(
|
|
z.object({
|
|
accountId: z.string().uuid(),
|
|
fileName: z.string().min(1),
|
|
fileType: z.string().min(1),
|
|
fileSize: z
|
|
.number()
|
|
.int()
|
|
.min(1)
|
|
.max(10 * 1024 * 1024), // 10MB max
|
|
base64: z.string().min(1),
|
|
moduleName: z.string().optional(),
|
|
fieldName: z.string().optional(),
|
|
recordId: z.string().uuid().optional(),
|
|
}),
|
|
)
|
|
.action(async ({ parsedInput: input, ctx: _ctx }) => {
|
|
const client = getSupabaseServerClient();
|
|
const logger = await getLogger();
|
|
const api = createModuleBuilderApi(client);
|
|
|
|
logger.info(
|
|
{ name: 'files.upload', fileName: input.fileName },
|
|
'Uploading file...',
|
|
);
|
|
|
|
const data = await api.files.uploadFile({
|
|
accountId: input.accountId,
|
|
userId: ctx.user.id,
|
|
file: {
|
|
name: input.fileName,
|
|
type: input.fileType,
|
|
size: input.fileSize,
|
|
base64: input.base64,
|
|
},
|
|
moduleName: input.moduleName,
|
|
fieldName: input.fieldName,
|
|
recordId: input.recordId,
|
|
});
|
|
|
|
logger.info({ name: 'files.upload' }, 'File uploaded');
|
|
|
|
return { success: true, data };
|
|
});
|
|
|
|
export const deleteFile = authActionClient
|
|
.inputSchema(z.object({ fileId: z.string().uuid() }))
|
|
.action(async ({ parsedInput: { fileId } }) => {
|
|
const client = getSupabaseServerClient();
|
|
const logger = await getLogger();
|
|
const api = createModuleBuilderApi(client);
|
|
|
|
logger.info({ name: 'files.delete', fileId }, 'Deleting file...');
|
|
await api.files.deleteFile(fileId);
|
|
logger.info({ name: 'files.delete' }, 'File deleted');
|
|
|
|
return { success: true };
|
|
});
|