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
1c8db69a
authored
May 22, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: limit export kb
parent
5128bbcc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
7 deletions
+43
-7
src/pages/api/plugins/kb/data/exportModelData.ts
+25
-2
src/pages/kb/components/DataCard.tsx
+6
-2
src/service/models/user.ts
+9
-3
src/types/mongoSchema.d.ts
+3
-0
No files found.
src/pages/api/plugins/kb/data/exportModelData.ts
View file @
1c8db69a
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
User
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
PgClient
}
from
'@/service/pg'
;
...
...
@@ -14,10 +14,28 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
throw
new
Error
(
'缺少参数'
);
}
await
connectToDatabase
();
// 凭证校验
const
{
userId
}
=
await
authUser
({
req
,
authToken
:
true
});
await
connectToDatabase
();
const
thirtyMinutesAgo
=
new
Date
(
Date
.
now
()
-
30
*
60
*
1000
);
// auth export times
const
authTimes
=
await
User
.
findOne
(
{
_id
:
userId
,
$or
:
[
{
'limit.exportKbTime'
:
{
$exists
:
false
}
},
{
'limit.exportKbTime'
:
{
$lte
:
thirtyMinutesAgo
}
}
]
},
'_id limit'
);
if
(
!
authTimes
)
{
throw
new
Error
(
'上次导出未到半小时,每半小时仅可导出一次。'
);
}
// 统计数据
const
count
=
await
PgClient
.
count
(
'modelData'
,
{
...
...
@@ -36,6 +54,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
item
.
a
.
replace
(
/
\n
/g
,
'\\n'
)
]);
// update export time
await
User
.
findByIdAndUpdate
(
userId
,
{
'limit.exportKbTime'
:
new
Date
()
});
jsonRes
(
res
,
{
data
});
...
...
src/pages/kb/components/DataCard.tsx
View file @
1c8db69a
...
...
@@ -131,6 +131,10 @@ const DataCard = ({ kbId }: { kbId: string }) => {
type
:
'text/csv'
,
filename
:
'data.csv'
});
toast
({
title
:
'导出成功,下次导出需要半小时后'
,
status
:
'success'
});
}
catch
(
error
)
{
error
;
}
...
...
@@ -164,10 +168,10 @@ const DataCard = ({ kbId }: { kbId: string }) => {
mr=
{
2
}
size=
{
'sm'
}
isLoading=
{
isLoadingExport
}
title=
{
'
换行数据导出时,会进行格式转换
'
}
title=
{
'
半小时仅能导出1次
'
}
onClick=
{
()
=>
onclickExport
()
}
>
导出
导出
csv
</
Button
>
<
Menu
autoSelect=
{
false
}
>
<
MenuButton
as=
{
Button
}
size=
{
'sm'
}
>
...
...
src/service/models/user.ts
View file @
1c8db69a
...
...
@@ -16,6 +16,10 @@ const UserSchema = new Schema({
get
:
(
val
:
string
)
=>
hashPassword
(
val
),
select
:
false
},
createTime
:
{
type
:
Date
,
default
:
()
=>
new
Date
()
},
avatar
:
{
type
:
String
,
default
:
'/icon/human.png'
...
...
@@ -41,9 +45,11 @@ const UserSchema = new Schema({
type
:
String
,
default
:
''
},
createTime
:
{
type
:
Date
,
default
:
()
=>
new
Date
()
limit
:
{
exportKbTime
:
{
// Every half hour
type
:
Date
}
}
});
...
...
src/types/mongoSchema.d.ts
View file @
1c8db69a
...
...
@@ -22,6 +22,9 @@ export interface UserModelSchema {
promotion
:
{
rate
:
number
;
};
limit
:
{
exportKbTime
?:
Date
;
};
}
export
interface
AuthCodeSchema
{
...
...
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