mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-21 06:34:30 +01:00
27 lines
687 B
TypeScript
27 lines
687 B
TypeScript
import { NextResponse } from 'next/server'
|
|
import fs from 'fs/promises'
|
|
import path from 'path'
|
|
|
|
export async function GET(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ path: string[] }> }
|
|
) {
|
|
try {
|
|
const { path: pathSegments } = await Promise.resolve(params)
|
|
const filePath = path.join(process.cwd(), 'data', 'avatars', ...(pathSegments || []))
|
|
const file = await fs.readFile(filePath)
|
|
const ext = path.extname(filePath).slice(1)
|
|
|
|
return new NextResponse(file, {
|
|
headers: {
|
|
'Content-Type': `image/${ext}`,
|
|
},
|
|
})
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{ error: 'File not found' },
|
|
{ status: 404 }
|
|
)
|
|
}
|
|
}
|