mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00

* 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>
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
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} 分钟仅使用一次同步功能。`);
|
|
}
|
|
};
|