Files
FastGPT/packages/service/support/user/utils.ts
Archer 3c97757e4d 4.8.19-feature (#3636)
* feat: sync org from wecom, pref: member list pagination (#3549)

* feat: sync org

* chore: fe

* chore: loading

* chore: type

* pref: team member list change to pagination. Edit a sort of list apis.

* feat: member update avatar

* chore: user avatar move to tmb

* chore: init scripts move user avatar

* chore: sourceMember

* fix: list api sourceMember

* fix: member sync

* fix: pagination

* chore: adjust code

* chore: move changeOwner to pro

* chore: init v4819 script

* chore: adjust code

* chore: UserBox

* perf: scroll page code

* perf: list data

* docs:更新用户答疑 (#3576)

* docs: add custom uid docs (#3572)

* fix: pagination bug (#3577)

* 4.8.19 test (#3584)

* faet: dataset search filter

* fix: scroll page

* fix: collection list api old version (#3591)

* fix: collection list api format

* fix: type error of addSourceMemeber

* fix: scroll fetch (#3592)

* fix: yuque dataset file folder can enter (#3593)

* perf: load members;perf: yuque load;fix: workflow llm params cannot close (#3594)

* chat openapi doc

* feat: dataset openapi doc

* perf: load members

* perf: member load code

* perf: yuque load

* fix: workflow llm params cannot close

* fix: api dataset reference tag preview (#3600)

* perf: doc

* feat: chat page config

* fix: http parse (#3634)

* update doc

* fix: http parse

* fix code run node reset template (#3633)

Co-authored-by: Archer <545436317@qq.com>

* docs:faq (#3627)

* docs:faq

* docsFix

* perf: sleep plugin

* fix: selector

---------

Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com>
Co-authored-by: Jiangween <145003935+Jiangween@users.noreply.github.com>
Co-authored-by: heheer <heheer@sealos.io>
2025-01-20 19:42:33 +08:00

111 lines
2.9 KiB
TypeScript

import { SourceMemberType } from '@fastgpt/global/support/user/type';
import { MongoTeam } from './team/teamSchema';
import { MongoTeamMember } from './team/teamMemberSchema';
import { ClientSession } from '../../common/mongo';
/* 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} 分钟仅使用一次同步功能。`);
}
};
/**
* This function will add a property named sourceMember to the list passed in.
* @param list The list to add the sourceMember property to. [TmbId] property is required.
* @error If member is not found, this item will be skipped.
* @returns The list with the sourceMember property added.
*/
export async function addSourceMember<T extends { tmbId: string }>({
list,
session
}: {
list: T[];
session?: ClientSession;
}): Promise<Array<T & { sourceMember: SourceMemberType }>> {
if (!Array.isArray(list)) return [];
const tmbList = await MongoTeamMember.find(
{
_id: { $in: list.map((item) => String(item.tmbId)) }
},
'tmbId name avatar status',
{
session
}
).lean();
return list
.map((item) => {
const tmb = tmbList.find((tmb) => String(tmb._id) === String(item.tmbId));
if (!tmb) return;
return {
...item,
sourceMember: { name: tmb.name, avatar: tmb.avatar, status: tmb.status }
};
})
.filter(Boolean) as Array<T & { sourceMember: SourceMemberType }>;
}