Skip to content

Commit bb669ca

Browse files
authored
fix: plugin cost (labring#3533)
1 parent 72ed72e commit bb669ca

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

packages/service/common/middle/cors.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import NextCors from 'nextjs-cors';
33

44
export async function withNextCors(req: NextApiRequest, res: NextApiResponse) {
55
const methods = ['GET', 'eHEAD', 'PUT', 'PATCH', 'POST', 'DELETE'];
6+
7+
const allowedOrigins = process.env.ALLOWED_ORIGINS?.split(',');
68
const origin = req.headers.origin;
9+
710
await NextCors(req, res, {
811
methods,
9-
origin: origin,
12+
origin: allowedOrigins || origin,
1013
optionsSuccessStatus: 200
1114
});
1215
}
+16-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type';
22
import { PluginRuntimeType } from '@fastgpt/global/core/plugin/type';
3+
import { splitCombinePluginId } from './controller';
4+
import { PluginSourceEnum } from '@fastgpt/global/core/plugin/constants';
35

46
/*
57
Plugin points calculation:
6-
1. Return 0 if error
7-
2. Add configured points if commercial plugin
8-
3. Add sum of child nodes points
8+
1. 商业版插件:
9+
- 有错误:返回 0
10+
- 无错误:返回 配置的点数 + 子节点点数
11+
2. 其他插件:
12+
- 返回 子节点点数
913
*/
1014
export const computedPluginUsage = async ({
1115
plugin,
@@ -16,13 +20,16 @@ export const computedPluginUsage = async ({
1620
childrenUsage: ChatNodeUsageType[];
1721
error?: boolean;
1822
}) => {
19-
if (error) {
20-
return 0;
21-
}
23+
const { source } = await splitCombinePluginId(plugin.id);
24+
const childrenUsages = childrenUsage.reduce((sum, item) => sum + (item.totalPoints || 0), 0);
25+
26+
if (source !== PluginSourceEnum.personal) {
27+
if (error) return 0;
2228

23-
const childrenIUsages = childrenUsage.reduce((sum, item) => sum + (item.totalPoints || 0), 0);
29+
const pluginCurrentCose = plugin.currentCost ?? 0;
2430

25-
const pluginCurrentCose = plugin.currentCost ?? 0;
31+
return plugin.hasTokenFee ? pluginCurrentCose + childrenUsages : pluginCurrentCose;
32+
}
2633

27-
return plugin.hasTokenFee ? pluginCurrentCose + childrenIUsages : pluginCurrentCose;
34+
return childrenUsages;
2835
};

packages/web/i18n/en/app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"publish_success": "Publish Successful",
107107
"question_guide_tip": "After the conversation, 3 guiding questions will be generated for you.",
108108
"saved_success": "Saved successfully! \nTo use this version externally, click Save and Publish",
109-
"search_app": "Search Application",
109+
"search_app": "Search apps",
110110
"setting_app": "Workflow",
111111
"setting_plugin": "Workflow",
112112
"simple_tool_tips": "This plugin contains special inputs and is not currently supported for invocation by simple applications.",

projects/app/src/pages/api/common/file/read.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getDownloadStream, getFileById } from '@fastgpt/service/common/file/gri
66
import { CommonErrEnum } from '@fastgpt/global/common/error/code/common';
77
import { stream2Encoding } from '@fastgpt/service/common/file/gridfs/utils';
88

9+
// Abandoned, use: file/read/[filename].ts
910
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
1011
try {
1112
await connectToDatabase();
@@ -37,9 +38,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
3738
return stream2Encoding(fileStream);
3839
})();
3940

41+
const extension = file.filename.split('.').pop() || '';
42+
const disposition = ['html', 'htm'].includes(extension) ? 'attachment' : 'inline';
43+
4044
res.setHeader('Content-Type', `${file.contentType}; charset=${encoding}`);
4145
res.setHeader('Cache-Control', 'public, max-age=31536000');
42-
res.setHeader('Content-Disposition', `inline; filename="${encodeURIComponent(file.filename)}"`);
46+
res.setHeader(
47+
'Content-Disposition',
48+
`${disposition}; filename="${encodeURIComponent(file.filename)}"`
49+
);
4350
res.setHeader('Content-Length', file.length);
4451

4552
stream.pipe(res);

projects/app/src/pages/api/common/file/read/[filename].ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
3737
return stream2Encoding(fileStream);
3838
})();
3939

40+
const extension = file.filename.split('.').pop() || '';
41+
const disposition = ['html', 'htm'].includes(extension) ? 'attachment' : 'inline';
42+
4043
res.setHeader('Content-Type', `${file.contentType}; charset=${encoding}`);
4144
res.setHeader('Cache-Control', 'public, max-age=31536000');
42-
res.setHeader('Content-Disposition', `inline; filename="${encodeURIComponent(filename)}"`);
45+
res.setHeader(
46+
'Content-Disposition',
47+
`${disposition}; filename="${encodeURIComponent(filename)}"`
48+
);
4349
res.setHeader('Content-Length', file.length);
4450

4551
stream.pipe(res);

0 commit comments

Comments
 (0)