- Add admin middleware protecting /admin page (ROLE_ADMIN check) - Fix useAvatarService to use useApi() with FormData detection - Create extractIdFromIri() utility, replace manual IRI parsing - Remove redundant Nitro devProxy (Vite proxy handles dev) Tickets: T-014, T-015, T-017, T-021 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
27 lines
750 B
TypeScript
27 lines
750 B
TypeScript
export function useAvatarService() {
|
|
const api = useApi()
|
|
|
|
async function upload(userId: number, file: Blob): Promise<{ avatarUrl: string }> {
|
|
const formData = new FormData()
|
|
formData.append('file', file, 'avatar.png')
|
|
|
|
return api.post<{ avatarUrl: string }>(
|
|
`/users/${userId}/avatar`,
|
|
formData as unknown as Record<string, unknown>,
|
|
{
|
|
toastSuccessKey: 'profile.avatarUpdated',
|
|
}
|
|
)
|
|
}
|
|
|
|
async function remove(userId: number): Promise<void> {
|
|
await api.delete(`/users/${userId}/avatar`)
|
|
}
|
|
|
|
function getUrl(userId: number): string {
|
|
return `/api/users/${userId}/avatar`
|
|
}
|
|
|
|
return { upload, remove, getUrl }
|
|
}
|