-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f04a5e4
commit fadf33e
Showing
12 changed files
with
722 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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 } | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.