- added settings page and function
- add Role Ring for avatar and display role for user nav
This commit is contained in:
17
src/service/profile.api.ts
Normal file
17
src/service/profile.api.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { authMiddleware } from '@/lib/middleware';
|
||||
import { saveFile } from '@/utils/disk-storage';
|
||||
import { createServerFn } from '@tanstack/react-start';
|
||||
import z from 'zod';
|
||||
|
||||
export const uploadProfileImage = createServerFn({ method: 'POST' })
|
||||
.middleware([authMiddleware])
|
||||
.inputValidator(z.instanceof(FormData))
|
||||
.handler(async ({ data: formData }) => {
|
||||
const uuid = crypto.randomUUID();
|
||||
const file = formData.get('file') as File;
|
||||
if (!(file instanceof File)) throw new Error('File not found');
|
||||
const imageKey = `${uuid}.${file.type.split('/')[1]}`;
|
||||
const buffer = Buffer.from(await file.arrayBuffer());
|
||||
await saveFile(imageKey, buffer);
|
||||
return { imageKey };
|
||||
});
|
||||
Reference in New Issue
Block a user