Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
bb669ca3
authored
Jan 06, 2025
by
Archer
Committed by
GitHub
Jan 06, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: plugin cost (#3533)
parent
72ed72e5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
13 deletions
+36
-13
packages/service/common/middle/cors.ts
+4
-1
packages/service/core/app/plugin/utils.ts
+16
-9
packages/web/i18n/en/app.json
+1
-1
projects/app/src/pages/api/common/file/read.ts
+8
-1
projects/app/src/pages/api/common/file/read/[filename].ts
+7
-1
No files found.
packages/service/common/middle/cors.ts
View file @
bb669ca3
...
...
@@ -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
});
}
packages/service/core/app/plugin/utils.ts
View file @
bb669ca3
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
childrenIUsages
=
childrenUsage
.
reduce
((
sum
,
item
)
=>
sum
+
(
item
.
totalPoints
||
0
),
0
)
;
const
pluginCurrentCose
=
plugin
.
currentCost
??
0
;
const
pluginCurrentCose
=
plugin
.
currentCost
??
0
;
return
plugin
.
hasTokenFee
?
pluginCurrentCose
+
childrenUsages
:
pluginCurrentCose
;
}
return
plugin
.
hasTokenFee
?
pluginCurrentCose
+
childrenIUsages
:
pluginCurrentCose
;
return
childrenUsages
;
};
packages/web/i18n/en/app.json
View file @
bb669ca3
...
...
@@ -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!
\n
To 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."
,
...
...
projects/app/src/pages/api/common/file/read.ts
View file @
bb669ca3
...
...
@@ -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
);
...
...
projects/app/src/pages/api/common/file/read/[filename].ts
View file @
bb669ca3
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment