diff --git a/packages/service/common/middle/cors.ts b/packages/service/common/middle/cors.ts index 775dc31e1..73b294162 100644 --- a/packages/service/common/middle/cors.ts +++ b/packages/service/common/middle/cors.ts @@ -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 }); } diff --git a/packages/service/core/app/plugin/utils.ts b/packages/service/core/app/plugin/utils.ts index 3ec4ecc56..bd1b764da 100644 --- a/packages/service/core/app/plugin/utils.ts +++ b/packages/service/core/app/plugin/utils.ts @@ -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; }; diff --git a/packages/web/i18n/en/app.json b/packages/web/i18n/en/app.json index 8e1d2ca10..d206af376 100644 --- a/packages/web/i18n/en/app.json +++ b/packages/web/i18n/en/app.json @@ -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.", diff --git a/projects/app/src/pages/api/common/file/read.ts b/projects/app/src/pages/api/common/file/read.ts index e18375478..dc59693fe 100644 --- a/projects/app/src/pages/api/common/file/read.ts +++ b/projects/app/src/pages/api/common/file/read.ts @@ -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) { 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); diff --git a/projects/app/src/pages/api/common/file/read/[filename].ts b/projects/app/src/pages/api/common/file/read/[filename].ts index f33b58e86..fd51aa882 100644 --- a/projects/app/src/pages/api/common/file/read/[filename].ts +++ b/projects/app/src/pages/api/common/file/read/[filename].ts @@ -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);