feat(ST-351): add UserAvatar component and /api/users/[id]/avatar route
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
1158470a47
commit
ef5c7c7675
3 changed files with 170 additions and 0 deletions
28
app/api/users/[id]/avatar/route.ts
Normal file
28
app/api/users/[id]/avatar/route.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { prisma } from '@/lib/prisma'
|
||||
import { requireUser } from '@/lib/auth'
|
||||
|
||||
export async function GET(_request: Request, { params }: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
await requireUser()
|
||||
} catch {
|
||||
return new Response(null, { status: 401 })
|
||||
}
|
||||
|
||||
const { id } = await params
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id },
|
||||
select: { avatar_data: true },
|
||||
})
|
||||
|
||||
if (!user?.avatar_data) {
|
||||
return new Response(null, { status: 404 })
|
||||
}
|
||||
|
||||
return new Response(user.avatar_data, {
|
||||
headers: {
|
||||
'Content-Type': 'image/webp',
|
||||
'Cache-Control': 'private, max-age=3600',
|
||||
},
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue