mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-26 07:06:33 +00:00
feat: Text check before synchronization (#689)
* fix: icon * fix: web selector * fix: web selector * perf: link sync * dev doc * chomd doc * perf: git intro * 466 intro * intro img * add json editor (#5) * team limit * websync limit * json editor * text editor * perf: search test * change cq value type * doc * intro img --------- Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
@@ -47,15 +47,6 @@ const UserSchema = new Schema({
|
||||
type: Number,
|
||||
default: 15
|
||||
},
|
||||
limit: {
|
||||
exportKbTime: {
|
||||
// Every half hour
|
||||
type: Date
|
||||
},
|
||||
datasetMaxCount: {
|
||||
type: Number
|
||||
}
|
||||
},
|
||||
openaiAccount: {
|
||||
type: {
|
||||
key: String,
|
||||
|
@@ -32,6 +32,14 @@ const TeamSchema = new Schema({
|
||||
},
|
||||
lastDatasetBillTime: {
|
||||
type: Date
|
||||
},
|
||||
limit: {
|
||||
lastExportDatasetTime: {
|
||||
type: Date
|
||||
},
|
||||
lastWebsiteSyncTime: {
|
||||
type: Date
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
69
packages/service/support/user/utils.ts
Normal file
69
packages/service/support/user/utils.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { MongoTeam } from './team/teamSchema';
|
||||
|
||||
/* export dataset limit */
|
||||
export const updateExportDatasetLimit = async (teamId: string) => {
|
||||
try {
|
||||
await MongoTeam.findByIdAndUpdate(teamId, {
|
||||
'limit.lastExportDatasetTime': new Date()
|
||||
});
|
||||
} catch (error) {}
|
||||
};
|
||||
export const checkExportDatasetLimit = async ({
|
||||
teamId,
|
||||
limitMinutes = 0
|
||||
}: {
|
||||
teamId: string;
|
||||
limitMinutes?: number;
|
||||
}) => {
|
||||
const limitMinutesAgo = new Date(Date.now() - limitMinutes * 60 * 1000);
|
||||
|
||||
// auth export times
|
||||
const authTimes = await MongoTeam.findOne(
|
||||
{
|
||||
_id: teamId,
|
||||
$or: [
|
||||
{ 'limit.lastExportDatasetTime': { $exists: false } },
|
||||
{ 'limit.lastExportDatasetTime': { $lte: limitMinutesAgo } }
|
||||
]
|
||||
},
|
||||
'_id limit'
|
||||
);
|
||||
|
||||
if (!authTimes) {
|
||||
return Promise.reject(`每个团队,每 ${limitMinutes} 分钟仅可导出一次。`);
|
||||
}
|
||||
};
|
||||
|
||||
/* web sync limit */
|
||||
export const updateWebSyncLimit = async (teamId: string) => {
|
||||
try {
|
||||
await MongoTeam.findByIdAndUpdate(teamId, {
|
||||
'limit.lastWebsiteSyncTime': new Date()
|
||||
});
|
||||
} catch (error) {}
|
||||
};
|
||||
export const checkWebSyncLimit = async ({
|
||||
teamId,
|
||||
limitMinutes = 0
|
||||
}: {
|
||||
teamId: string;
|
||||
limitMinutes?: number;
|
||||
}) => {
|
||||
const limitMinutesAgo = new Date(Date.now() - limitMinutes * 60 * 1000);
|
||||
|
||||
// auth export times
|
||||
const authTimes = await MongoTeam.findOne(
|
||||
{
|
||||
_id: teamId,
|
||||
$or: [
|
||||
{ 'limit.lastWebsiteSyncTime': { $exists: false } },
|
||||
{ 'limit.lastWebsiteSyncTime': { $lte: limitMinutesAgo } }
|
||||
]
|
||||
},
|
||||
'_id limit'
|
||||
);
|
||||
|
||||
if (!authTimes) {
|
||||
return Promise.reject(`每个团队,每 ${limitMinutes} 分钟仅使用一次同步功能。`);
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user