mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-13 22:56:28 +00:00
add user active tracks (#5754)
* add user active tracks * remove console * perf: track active * perf: track active --------- Co-authored-by: archer <545436317@qq.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
export enum TrackEnum {
|
||||
login = 'login',
|
||||
dailyUserActive = 'dailyUserActive',
|
||||
createApp = 'createApp',
|
||||
useAppTemplate = 'useAppTemplate',
|
||||
createDataset = 'createDataset',
|
||||
|
@@ -7,6 +7,7 @@ import type { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||
import type { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constants';
|
||||
import { getAppLatestVersion } from '../../../core/app/version/controller';
|
||||
import { type ShortUrlParams } from '@fastgpt/global/support/marketing/type';
|
||||
import { getRedisCache, setRedisCache } from '../../redis/cache';
|
||||
|
||||
const createTrack = ({ event, data }: { event: TrackEnum; data: Record<string, any> }) => {
|
||||
if (!global.feConfigs?.isPlus) return;
|
||||
@@ -66,8 +67,31 @@ export const pushTrack = {
|
||||
return createTrack({
|
||||
event: TrackEnum.login,
|
||||
data
|
||||
})?.then(() => {
|
||||
pushTrack.dailyUserActive({
|
||||
uid: data.uid,
|
||||
teamId: data.teamId,
|
||||
tmbId: data.tmbId
|
||||
});
|
||||
});
|
||||
},
|
||||
dailyUserActive: async (data: PushTrackCommonType) => {
|
||||
try {
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
const key = `dailyUserActive:${data.uid}_${today}`;
|
||||
const cache = await getRedisCache(key);
|
||||
if (cache) return;
|
||||
|
||||
await setRedisCache(key, '1', 24 * 60 * 60);
|
||||
|
||||
return createTrack({
|
||||
event: TrackEnum.dailyUserActive,
|
||||
data
|
||||
});
|
||||
} catch (error) {
|
||||
addLog.error('Failed to track daily user active:', error);
|
||||
}
|
||||
},
|
||||
createApp: (
|
||||
data: PushTrackCommonType &
|
||||
ShortUrlParams & {
|
||||
|
@@ -3,6 +3,8 @@ import { getUserDetail } from '@fastgpt/service/support/user/controller';
|
||||
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { type UserType } from '@fastgpt/global/support/user/type';
|
||||
import { pushTrack } from '@fastgpt/service/common/middle/tracks/utils';
|
||||
import { getGlobalRedisConnection } from '@fastgpt/service/common/redis';
|
||||
|
||||
export type TokenLoginQuery = {};
|
||||
export type TokenLoginBody = {};
|
||||
@@ -12,9 +14,15 @@ async function handler(
|
||||
req: ApiRequestProps<TokenLoginBody, TokenLoginQuery>,
|
||||
_res: ApiResponseType<any>
|
||||
): Promise<TokenLoginResponse> {
|
||||
const { tmbId } = await authCert({ req, authToken: true });
|
||||
const { tmbId, userId, teamId } = await authCert({ req, authToken: true });
|
||||
const user = await getUserDetail({ tmbId });
|
||||
|
||||
pushTrack.dailyUserActive({
|
||||
uid: userId,
|
||||
teamId: teamId,
|
||||
tmbId: tmbId
|
||||
});
|
||||
|
||||
// Remove sensitive information
|
||||
// if (user.team.lafAccount) {
|
||||
// user.team.lafAccount = {
|
||||
|
Reference in New Issue
Block a user