mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 11:43:56 +00:00
fix: plugin cost (#3533)
This commit is contained in:
@@ -3,10 +3,13 @@ import NextCors from 'nextjs-cors';
|
||||
|
||||
export async function withNextCors(req: NextApiRequest, res: NextApiResponse) {
|
||||
const methods = ['GET', 'eHEAD', 'PUT', 'PATCH', 'POST', 'DELETE'];
|
||||
|
||||
const allowedOrigins = process.env.ALLOWED_ORIGINS?.split(',');
|
||||
const origin = req.headers.origin;
|
||||
|
||||
await NextCors(req, res, {
|
||||
methods,
|
||||
origin: origin,
|
||||
origin: allowedOrigins || origin,
|
||||
optionsSuccessStatus: 200
|
||||
});
|
||||
}
|
||||
|
@@ -1,11 +1,15 @@
|
||||
import { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type';
|
||||
import { PluginRuntimeType } from '@fastgpt/global/core/plugin/type';
|
||||
import { splitCombinePluginId } from './controller';
|
||||
import { PluginSourceEnum } from '@fastgpt/global/core/plugin/constants';
|
||||
|
||||
/*
|
||||
Plugin points calculation:
|
||||
1. Return 0 if error
|
||||
2. Add configured points if commercial plugin
|
||||
3. Add sum of child nodes points
|
||||
1. 商业版插件:
|
||||
- 有错误:返回 0
|
||||
- 无错误:返回 配置的点数 + 子节点点数
|
||||
2. 其他插件:
|
||||
- 返回 子节点点数
|
||||
*/
|
||||
export const computedPluginUsage = async ({
|
||||
plugin,
|
||||
@@ -16,13 +20,16 @@ export const computedPluginUsage = async ({
|
||||
childrenUsage: ChatNodeUsageType[];
|
||||
error?: boolean;
|
||||
}) => {
|
||||
if (error) {
|
||||
return 0;
|
||||
const { source } = await splitCombinePluginId(plugin.id);
|
||||
const childrenUsages = childrenUsage.reduce((sum, item) => sum + (item.totalPoints || 0), 0);
|
||||
|
||||
if (source !== PluginSourceEnum.personal) {
|
||||
if (error) return 0;
|
||||
|
||||
const pluginCurrentCose = plugin.currentCost ?? 0;
|
||||
|
||||
return plugin.hasTokenFee ? pluginCurrentCose + childrenUsages : pluginCurrentCose;
|
||||
}
|
||||
|
||||
const childrenIUsages = childrenUsage.reduce((sum, item) => sum + (item.totalPoints || 0), 0);
|
||||
|
||||
const pluginCurrentCose = plugin.currentCost ?? 0;
|
||||
|
||||
return plugin.hasTokenFee ? pluginCurrentCose + childrenIUsages : pluginCurrentCose;
|
||||
return childrenUsages;
|
||||
};
|
||||
|
@@ -106,7 +106,7 @@
|
||||
"publish_success": "Publish Successful",
|
||||
"question_guide_tip": "After the conversation, 3 guiding questions will be generated for you.",
|
||||
"saved_success": "Saved successfully! \nTo use this version externally, click Save and Publish",
|
||||
"search_app": "Search Application",
|
||||
"search_app": "Search apps",
|
||||
"setting_app": "Workflow",
|
||||
"setting_plugin": "Workflow",
|
||||
"simple_tool_tips": "This plugin contains special inputs and is not currently supported for invocation by simple applications.",
|
||||
|
@@ -6,6 +6,7 @@ import { getDownloadStream, getFileById } from '@fastgpt/service/common/file/gri
|
||||
import { CommonErrEnum } from '@fastgpt/global/common/error/code/common';
|
||||
import { stream2Encoding } from '@fastgpt/service/common/file/gridfs/utils';
|
||||
|
||||
// Abandoned, use: file/read/[filename].ts
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
try {
|
||||
await connectToDatabase();
|
||||
@@ -37,9 +38,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
return stream2Encoding(fileStream);
|
||||
})();
|
||||
|
||||
const extension = file.filename.split('.').pop() || '';
|
||||
const disposition = ['html', 'htm'].includes(extension) ? 'attachment' : 'inline';
|
||||
|
||||
res.setHeader('Content-Type', `${file.contentType}; charset=${encoding}`);
|
||||
res.setHeader('Cache-Control', 'public, max-age=31536000');
|
||||
res.setHeader('Content-Disposition', `inline; filename="${encodeURIComponent(file.filename)}"`);
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
`${disposition}; filename="${encodeURIComponent(file.filename)}"`
|
||||
);
|
||||
res.setHeader('Content-Length', file.length);
|
||||
|
||||
stream.pipe(res);
|
||||
|
@@ -37,9 +37,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
return stream2Encoding(fileStream);
|
||||
})();
|
||||
|
||||
const extension = file.filename.split('.').pop() || '';
|
||||
const disposition = ['html', 'htm'].includes(extension) ? 'attachment' : 'inline';
|
||||
|
||||
res.setHeader('Content-Type', `${file.contentType}; charset=${encoding}`);
|
||||
res.setHeader('Cache-Control', 'public, max-age=31536000');
|
||||
res.setHeader('Content-Disposition', `inline; filename="${encodeURIComponent(filename)}"`);
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
`${disposition}; filename="${encodeURIComponent(filename)}"`
|
||||
);
|
||||
res.setHeader('Content-Length', file.length);
|
||||
|
||||
stream.pipe(res);
|
||||
|
Reference in New Issue
Block a user