Skip to content

Commit 062d8bb

Browse files
FinleyGec121914yu
andcommitted
fix: model avatar (#5848)
* fix: model avatar * fix: ts * fix: avatar migration to s3 * update lock * fix: avatar redirect --------- Co-authored-by: archer <[email protected]>
1 parent ddf4ff9 commit 062d8bb

File tree

6 files changed

+38
-62
lines changed

6 files changed

+38
-62
lines changed

packages/global/core/ai/provider.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,30 @@ export const defaultProvider: ModelProviderItemType = {
2323
order: 999
2424
};
2525

26-
export const formatModelProviders = (data: { provider: string; value: I18nStringStrictType }[]) => {
26+
export const formatModelProviders = (
27+
data: { provider: string; value: I18nStringStrictType; avatar: string }[]
28+
) => {
2729
const getLocalizedName = (translations: I18nStringStrictType, language = 'en'): string => {
2830
return translations[language as langType] || translations.en;
2931
};
3032

3133
const formatModelProviderList = (language?: string): ModelProviderItemType[] => {
32-
return data.map(({ provider, value }, index) => ({
34+
return data.map(({ provider, value, avatar }, index) => ({
3335
id: provider,
3436
name: getLocalizedName(value, language),
35-
avatar: `/api/system/plugin/models/${provider}.svg`,
37+
avatar,
3638
order: index
3739
}));
3840
};
3941

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

43-
data.forEach(({ provider: id, value }, index) => {
45+
data.forEach(({ provider: id, value, avatar }, index) => {
4446
provider[id] = {
4547
id,
4648
name: getLocalizedName(value, language),
47-
avatar: `/api/system/plugin/models/${id}.svg`,
49+
avatar,
4850
order: index
4951
};
5052
});

packages/global/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@fastgpt/global",
33
"version": "1.0.0",
44
"dependencies": {
5-
"@fastgpt-sdk/plugin": "0.2.13",
5+
"@fastgpt-sdk/plugin": "0.2.15",
66
"@apidevtools/swagger-parser": "^10.1.0",
77
"@bany/curl-to-json": "^1.2.8",
88
"axios": "^1.12.1",

packages/service/core/ai/type.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export type SystemDefaultModelType = {
3838
};
3939

4040
declare global {
41-
var ModelProviderRawCache: { provider: string; value: I18nStringStrictType }[];
41+
var ModelProviderRawCache: { provider: string; value: I18nStringStrictType; avatar: string }[];
4242
var ModelProviderListCache: Record<langType, ModelProviderItemType[]>;
4343
var ModelProviderMapCache: Record<langType, Record<string, ModelProviderItemType>>;
4444
var aiproxyIdMapCache: AiproxyMapProviderType;

pnpm-lock.yaml

Lines changed: 21 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/app/src/pages/api/common/system/getInitData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type InitDateResponse = {
1919

2020
activeModelList?: SystemModelItemType[];
2121
defaultModels?: SystemDefaultModelType;
22-
modelProviders?: { provider: string; value: I18nStringStrictType }[];
22+
modelProviders?: { provider: string; value: I18nStringStrictType; avatar: string }[];
2323
aiproxyIdMap?: AiproxyMapProviderType;
2424
};
2525

projects/app/src/pages/api/system/plugin/[...path].ts

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,18 @@
11
import type { NextApiRequest, NextApiResponse } from 'next';
22
import { jsonRes } from '@fastgpt/service/common/response';
3-
import { request } from 'http';
4-
import { FastGPTPluginUrl } from '@fastgpt/service/common/system/constants';
3+
import { S3Buckets } from '@fastgpt/service/common/s3/constants';
4+
import type { S3PublicBucket } from '@fastgpt/service/common/s3/buckets/public';
55

66
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
77
try {
8-
const { path = [] } = req.query as any;
9-
const requestPath = `/imgs/${path?.join('/')}`;
8+
const { path = [] } = req.query as { path: ['models' | 'tools', string] };
109

11-
if (!requestPath) {
12-
throw new Error('url is empty');
13-
}
14-
if (!FastGPTPluginUrl) {
15-
throw new Error(`未配置插件服务链接: ${path}`);
16-
}
10+
const bucket = global.s3BucketMap[S3Buckets.public] as S3PublicBucket;
1711

18-
const parsedUrl = new URL(FastGPTPluginUrl);
19-
delete req.headers?.rootkey;
20-
delete req.headers?.cookie;
21-
delete req.headers?.host;
22-
delete req.headers?.origin;
12+
const baseUrl = `system/plugin/${path.join('/')}`.split('.')[0];
13+
const requestPath = bucket.createPublicUrl(`${baseUrl}/logo`);
2314

24-
const requestResult = request({
25-
protocol: parsedUrl.protocol,
26-
hostname: parsedUrl.hostname,
27-
port: parsedUrl.port,
28-
path: requestPath,
29-
method: req.method,
30-
headers: req.headers
31-
});
32-
req.pipe(requestResult);
33-
34-
requestResult.on('response', (response) => {
35-
Object.keys(response.headers).forEach((key) => {
36-
// @ts-ignore
37-
res.setHeader(key, response.headers[key]);
38-
});
39-
response.statusCode && res.writeHead(response.statusCode);
40-
response.pipe(res);
41-
});
42-
43-
requestResult.on('error', (e) => {
44-
res.send(e);
45-
res.end();
46-
});
15+
res.redirect(requestPath);
4716
} catch (error) {
4817
jsonRes(res, {
4918
code: 500,

0 commit comments

Comments
 (0)