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
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
12 deletions
+35
-12
packages/service/common/middle/cors.ts
+4
-1
packages/service/core/app/plugin/utils.ts
+15
-8
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';
...
@@ -3,10 +3,13 @@ import NextCors from 'nextjs-cors';
export
async
function
withNextCors
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
export
async
function
withNextCors
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
const
methods
=
[
'GET'
,
'eHEAD'
,
'PUT'
,
'PATCH'
,
'POST'
,
'DELETE'
];
const
methods
=
[
'GET'
,
'eHEAD'
,
'PUT'
,
'PATCH'
,
'POST'
,
'DELETE'
];
const
allowedOrigins
=
process
.
env
.
ALLOWED_ORIGINS
?.
split
(
','
);
const
origin
=
req
.
headers
.
origin
;
const
origin
=
req
.
headers
.
origin
;
await
NextCors
(
req
,
res
,
{
await
NextCors
(
req
,
res
,
{
methods
,
methods
,
origin
:
origin
,
origin
:
allowedOrigins
||
origin
,
optionsSuccessStatus
:
200
optionsSuccessStatus
:
200
});
});
}
}
packages/service/core/app/plugin/utils.ts
View file @
bb669ca3
import
{
ChatNodeUsageType
}
from
'@fastgpt/global/support/wallet/bill/type'
;
import
{
ChatNodeUsageType
}
from
'@fastgpt/global/support/wallet/bill/type'
;
import
{
PluginRuntimeType
}
from
'@fastgpt/global/core/plugin/type'
;
import
{
PluginRuntimeType
}
from
'@fastgpt/global/core/plugin/type'
;
import
{
splitCombinePluginId
}
from
'./controller'
;
import
{
PluginSourceEnum
}
from
'@fastgpt/global/core/plugin/constants'
;
/*
/*
Plugin points calculation:
Plugin points calculation:
1. Return 0 if error
1. 商业版插件:
2. Add configured points if commercial plugin
- 有错误:返回 0
3. Add sum of child nodes points
- 无错误:返回 配置的点数 + 子节点点数
2. 其他插件:
- 返回 子节点点数
*/
*/
export
const
computedPluginUsage
=
async
({
export
const
computedPluginUsage
=
async
({
plugin
,
plugin
,
...
@@ -16,13 +20,16 @@ export const computedPluginUsage = async ({
...
@@ -16,13 +20,16 @@ export const computedPluginUsage = async ({
childrenUsage
:
ChatNodeUsageType
[];
childrenUsage
:
ChatNodeUsageType
[];
error
?:
boolean
;
error
?:
boolean
;
})
=>
{
})
=>
{
if
(
error
)
{
const
{
source
}
=
await
splitCombinePluginId
(
plugin
.
id
);
return
0
;
const
childrenUsages
=
childrenUsage
.
reduce
((
sum
,
item
)
=>
sum
+
(
item
.
totalPoints
||
0
),
0
);
}
const
childrenIUsages
=
childrenUsage
.
reduce
((
sum
,
item
)
=>
sum
+
(
item
.
totalPoints
||
0
),
0
);
if
(
source
!==
PluginSourceEnum
.
personal
)
{
if
(
error
)
return
0
;
const
pluginCurrentCose
=
plugin
.
currentCost
??
0
;
const
pluginCurrentCose
=
plugin
.
currentCost
??
0
;
return
plugin
.
hasTokenFee
?
pluginCurrentCose
+
childrenIUsages
:
pluginCurrentCose
;
return
plugin
.
hasTokenFee
?
pluginCurrentCose
+
childrenUsages
:
pluginCurrentCose
;
}
return
childrenUsages
;
};
};
packages/web/i18n/en/app.json
View file @
bb669ca3
...
@@ -106,7 +106,7 @@
...
@@ -106,7 +106,7 @@
"publish_success"
:
"Publish Successful"
,
"publish_success"
:
"Publish Successful"
,
"question_guide_tip"
:
"After the conversation, 3 guiding questions will be generated for you."
,
"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"
,
"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_app"
:
"Workflow"
,
"setting_plugin"
:
"Workflow"
,
"setting_plugin"
:
"Workflow"
,
"simple_tool_tips"
:
"This plugin contains special inputs and is not currently supported for invocation by simple applications."
,
"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
...
@@ -6,6 +6,7 @@ import { getDownloadStream, getFileById } from '@fastgpt/service/common/file/gri
import
{
CommonErrEnum
}
from
'@fastgpt/global/common/error/code/common'
;
import
{
CommonErrEnum
}
from
'@fastgpt/global/common/error/code/common'
;
import
{
stream2Encoding
}
from
'@fastgpt/service/common/file/gridfs/utils'
;
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
>
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
try
{
await
connectToDatabase
();
await
connectToDatabase
();
...
@@ -37,9 +38,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -37,9 +38,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
return
stream2Encoding
(
fileStream
);
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
(
'Content-Type'
,
`
${
file
.
contentType
}
; charset=
${
encoding
}
`
);
res
.
setHeader
(
'Cache-Control'
,
'public, max-age=31536000'
);
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
);
res
.
setHeader
(
'Content-Length'
,
file
.
length
);
stream
.
pipe
(
res
);
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<
...
@@ -37,9 +37,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
return
stream2Encoding
(
fileStream
);
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
(
'Content-Type'
,
`
${
file
.
contentType
}
; charset=
${
encoding
}
`
);
res
.
setHeader
(
'Cache-Control'
,
'public, max-age=31536000'
);
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
);
res
.
setHeader
(
'Content-Length'
,
file
.
length
);
stream
.
pipe
(
res
);
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