-
Notifications
You must be signed in to change notification settings - Fork 7.3k
fix: model avatar #5848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: model avatar #5848
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,18 @@ | ||
| import type { NextApiRequest, NextApiResponse } from 'next'; | ||
| import { jsonRes } from '@fastgpt/service/common/response'; | ||
| import { request } from 'http'; | ||
| import { FastGPTPluginUrl } from '@fastgpt/service/common/system/constants'; | ||
| import { S3Buckets } from '@fastgpt/service/common/s3/constants'; | ||
| import type { S3PublicBucket } from '@fastgpt/service/common/s3/buckets/public'; | ||
|
|
||
| export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
| try { | ||
| const { path = [] } = req.query as any; | ||
| const requestPath = `/imgs/${path?.join('/')}`; | ||
| const { path = [] } = req.query as { path: ['models' | 'tools', string] }; | ||
|
|
||
| if (!requestPath) { | ||
| throw new Error('url is empty'); | ||
| } | ||
| if (!FastGPTPluginUrl) { | ||
| throw new Error(`未配置插件服务链接: ${path}`); | ||
| } | ||
| const bucket = global.s3BucketMap[S3Buckets.public] as S3PublicBucket; | ||
|
|
||
| const parsedUrl = new URL(FastGPTPluginUrl); | ||
| delete req.headers?.rootkey; | ||
| delete req.headers?.cookie; | ||
| delete req.headers?.host; | ||
| delete req.headers?.origin; | ||
| const baseUrl = `system/plugin/${path.join('/')}`.split('.')[0]; | ||
| const requestPath = bucket.createPublicUrl(`${baseUrl}/logo`); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: S3 Redirect URL: Path and Extension Handling ErrorsThe S3 redirect URL construction has a couple of issues. An empty |
||
|
|
||
| const requestResult = request({ | ||
| protocol: parsedUrl.protocol, | ||
| hostname: parsedUrl.hostname, | ||
| port: parsedUrl.port, | ||
| path: requestPath, | ||
| method: req.method, | ||
| headers: req.headers | ||
| }); | ||
| req.pipe(requestResult); | ||
|
|
||
| requestResult.on('response', (response) => { | ||
| Object.keys(response.headers).forEach((key) => { | ||
| // @ts-ignore | ||
| res.setHeader(key, response.headers[key]); | ||
| }); | ||
| response.statusCode && res.writeHead(response.statusCode); | ||
| response.pipe(res); | ||
| }); | ||
|
|
||
| requestResult.on('error', (e) => { | ||
| res.send(e); | ||
| res.end(); | ||
| }); | ||
| res.redirect(requestPath); | ||
| } catch (error) { | ||
| jsonRes(res, { | ||
| code: 500, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.