generated from Amery2010/nextjs-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Forward data using the common proxy interface
fix: Fixed the problem of being unable to upload to using the backend server build: Use multiple rewrites rule hack to solve the problem of invalid rewrites rule variables in standalone mode
- Loading branch information
Showing
6 changed files
with
120 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { NextResponse, type NextRequest } from 'next/server' | ||
import FileManager from '@/utils/FileManager' | ||
import { ErrorType } from '@/constant/errors' | ||
import { isUndefined } from 'lodash-es' | ||
|
||
const geminiApiKey = process.env.GEMINI_API_KEY as string | ||
const geminiApiBaseUrl = process.env.GEMINI_API_BASE_URL as string | ||
const geminiUploadProxyUrl = process.env.GEMINI_UPLOAD_BASE_URL || 'https://generativelanguage.googleapis.com' | ||
const mode = process.env.NEXT_PUBLIC_BUILD_MODE | ||
|
||
export const preferredRegion = ['sfo1'] | ||
|
||
export async function GET(req: NextRequest) { | ||
if (mode === 'export') return new NextResponse('Not available under static deployment') | ||
|
||
const id = req.url.split('/').pop() | ||
|
||
if (isUndefined(id)) { | ||
return NextResponse.json({ code: 40001, message: ErrorType.MissingParam }, { status: 400 }) | ||
} | ||
|
||
const fileManager = new FileManager({ | ||
apiKey: geminiApiKey, | ||
baseUrl: geminiApiBaseUrl, | ||
uploadUrl: geminiUploadProxyUrl, | ||
}) | ||
const result = await fileManager.getFileMetadata(id) | ||
return NextResponse.json(result) | ||
} | ||
|
||
export async function POST(req: NextRequest) { | ||
req.nextUrl.searchParams.append('key', geminiApiKey) | ||
const blob = await req.blob() | ||
const response = await fetch(`${geminiUploadProxyUrl}/upload/v1beta/files?${req.nextUrl.searchParams.toString()}`, { | ||
method: 'POST', | ||
body: blob, | ||
}) | ||
return new NextResponse(response.body) | ||
} | ||
|
||
export async function PUT(req: NextRequest) { | ||
req.nextUrl.searchParams.append('key', geminiApiKey) | ||
const blob = await req.blob() | ||
const response = await fetch(`${geminiUploadProxyUrl}/upload/v1beta/files?${req.nextUrl.searchParams.toString()}`, { | ||
method: 'PUT', | ||
body: blob, | ||
}) | ||
return new NextResponse(response.body) | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "talk-with-gemini", | ||
"version": "0.10.6", | ||
"version": "0.10.7", | ||
"private": true, | ||
"author": "Amery2010 <[email protected]>", | ||
"license": "GPL-3.0-only", | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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