-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: upload image with local fs storage
- Loading branch information
Showing
4 changed files
with
50 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { RouteProps } from '@/lib/next/types'; | ||
import { baseRegistry } from '@/rag-spec/base'; | ||
import { getFlow } from '@/rag-spec/createFlow'; | ||
import mime from 'mime'; | ||
import { notFound } from 'next/navigation'; | ||
import { type NextRequest, NextResponse } from 'next/server'; | ||
|
||
export async function GET (req: NextRequest, { params }: RouteProps<{ path: string[] }>) { | ||
const flow = await getFlow(baseRegistry); | ||
const storage = flow.getStorage('rag.document-storage.fs'); | ||
|
||
if (!storage.available()) { | ||
notFound(); | ||
} | ||
|
||
const name = params.path.join('/'); | ||
|
||
try { | ||
const buffer = await storage.get(name); | ||
const contentType = mime.getType(name); | ||
|
||
return new NextResponse(buffer, { | ||
headers: contentType ? { 'Content-Type': contentType } : {}, | ||
}); | ||
} catch (e) { | ||
notFound(); | ||
} | ||
} | ||
|
||
export const dynamic = 'force-static'; |
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