Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/global/core/ai/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,30 @@ export const defaultProvider: ModelProviderItemType = {
order: 999
};

export const formatModelProviders = (data: { provider: string; value: I18nStringStrictType }[]) => {
export const formatModelProviders = (
data: { provider: string; value: I18nStringStrictType; avatar: string }[]
) => {
const getLocalizedName = (translations: I18nStringStrictType, language = 'en'): string => {
return translations[language as langType] || translations.en;
};

const formatModelProviderList = (language?: string): ModelProviderItemType[] => {
return data.map(({ provider, value }, index) => ({
return data.map(({ provider, value, avatar }, index) => ({
id: provider,
name: getLocalizedName(value, language),
avatar: `/api/system/plugin/models/${provider}.svg`,
avatar,
order: index
}));
};

const formatModelProviderMap = (language?: string) => {
const provider = {} as Record<string, ModelProviderItemType>;

data.forEach(({ provider: id, value }, index) => {
data.forEach(({ provider: id, value, avatar }, index) => {
provider[id] = {
id,
name: getLocalizedName(value, language),
avatar: `/api/system/plugin/models/${id}.svg`,
avatar,
order: index
};
});
Expand Down
2 changes: 1 addition & 1 deletion packages/global/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@fastgpt/global",
"version": "1.0.0",
"dependencies": {
"@fastgpt-sdk/plugin": "0.2.13",
"@fastgpt-sdk/plugin": "0.2.15",
Comment thread
c121914yu marked this conversation as resolved.
"@apidevtools/swagger-parser": "^10.1.0",
"@bany/curl-to-json": "^1.2.8",
"axios": "^1.12.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/service/core/ai/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type SystemDefaultModelType = {
};

declare global {
var ModelProviderRawCache: { provider: string; value: I18nStringStrictType }[];
var ModelProviderRawCache: { provider: string; value: I18nStringStrictType; avatar: string }[];
var ModelProviderListCache: Record<langType, ModelProviderItemType[]>;
var ModelProviderMapCache: Record<langType, Record<string, ModelProviderItemType>>;
var aiproxyIdMapCache: AiproxyMapProviderType;
Expand Down
37 changes: 21 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/app/src/pages/api/common/system/getInitData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type InitDateResponse = {

activeModelList?: SystemModelItemType[];
defaultModels?: SystemDefaultModelType;
modelProviders?: { provider: string; value: I18nStringStrictType }[];
modelProviders?: { provider: string; value: I18nStringStrictType; avatar: string }[];
aiproxyIdMap?: AiproxyMapProviderType;
};

Expand Down
45 changes: 7 additions & 38 deletions projects/app/src/pages/api/system/plugin/[...path].ts
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`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: S3 Redirect URL: Path and Extension Handling Errors

The S3 redirect URL construction has a couple of issues. An empty path array creates a malformed URL with double slashes. Also, the split('.')[0] logic incorrectly truncates the path at the first dot in the entire string, rather than just removing a file extension from the last segment.

Fix in Cursor Fix in Web


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,
Expand Down
Loading