mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
parent
d398c9cd39
commit
5631ec781e
|
|
@ -1,7 +1,7 @@
|
||||||
import type { SourceMemberType } from '../user/type';
|
import type { SourceMemberType } from '../user/type';
|
||||||
import type { AuditEventEnum } from './constants';
|
import type { AuditEventEnum } from './constants';
|
||||||
|
|
||||||
export type OperationLogSchema = {
|
export type TeamAuditSchemaType = {
|
||||||
_id: string;
|
_id: string;
|
||||||
tmbId: string;
|
tmbId: string;
|
||||||
teamId: string;
|
teamId: string;
|
||||||
|
|
@ -10,7 +10,7 @@ export type OperationLogSchema = {
|
||||||
metadata?: Record<string, string>;
|
metadata?: Record<string, string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OperationListItemType = {
|
export type TeamAuditListItemType = {
|
||||||
_id: string;
|
_id: string;
|
||||||
sourceMember: SourceMemberType;
|
sourceMember: SourceMemberType;
|
||||||
event: `${AuditEventEnum}`;
|
event: `${AuditEventEnum}`;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { getQueue, getWorker, QueueNames } from '../bullmq';
|
import { getQueue, getWorker, QueueNames } from '../bullmq';
|
||||||
import pLimit from 'p-limit';
|
import pLimit from 'p-limit';
|
||||||
import { retryFn } from '@fastgpt/global/common/system/utils';
|
import { retryFn } from '@fastgpt/global/common/system/utils';
|
||||||
|
import { addLog } from '../system/log';
|
||||||
|
|
||||||
export type S3MQJobData = {
|
export type S3MQJobData = {
|
||||||
key?: string;
|
key?: string;
|
||||||
|
|
@ -38,17 +39,22 @@ export const startS3DelWorker = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key) {
|
if (key) {
|
||||||
|
addLog.info(`[S3 delete] delete key: ${key}`);
|
||||||
await bucket.delete(key);
|
await bucket.delete(key);
|
||||||
|
addLog.info(`[S3 delete] delete key: ${key} success`);
|
||||||
}
|
}
|
||||||
if (keys) {
|
if (keys) {
|
||||||
|
addLog.info(`[S3 delete] delete keys: ${keys.length}`);
|
||||||
const tasks: Promise<void>[] = [];
|
const tasks: Promise<void>[] = [];
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
const p = limit(() => retryFn(() => bucket.delete(key)));
|
const p = limit(() => retryFn(() => bucket.delete(key)));
|
||||||
tasks.push(p);
|
tasks.push(p);
|
||||||
}
|
}
|
||||||
await Promise.all(tasks);
|
await Promise.all(tasks);
|
||||||
|
addLog.info(`[S3 delete] delete keys: ${keys.length} success`);
|
||||||
}
|
}
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
|
addLog.info(`[S3 delete] delete prefix: ${prefix}`);
|
||||||
const tasks: Promise<void>[] = [];
|
const tasks: Promise<void>[] = [];
|
||||||
return new Promise<void>(async (resolve, reject) => {
|
return new Promise<void>(async (resolve, reject) => {
|
||||||
const stream = bucket.listObjectsV2(prefix, true);
|
const stream = bucket.listObjectsV2(prefix, true);
|
||||||
|
|
@ -67,16 +73,19 @@ export const startS3DelWorker = async () => {
|
||||||
const results = await Promise.allSettled(tasks);
|
const results = await Promise.allSettled(tasks);
|
||||||
const failed = results.filter((r) => r.status === 'rejected');
|
const failed = results.filter((r) => r.status === 'rejected');
|
||||||
if (failed.length > 0) {
|
if (failed.length > 0) {
|
||||||
|
addLog.error(`[S3 delete] delete prefix: ${prefix} failed`);
|
||||||
reject('Some deletes failed');
|
reject('Some deletes failed');
|
||||||
}
|
}
|
||||||
|
addLog.info(`[S3 delete] delete prefix: ${prefix} success`);
|
||||||
resolve();
|
resolve();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
addLog.error(`[S3 delete] delete prefix: ${prefix} error`, err);
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('error', (err) => {
|
stream.on('error', (err) => {
|
||||||
console.error('listObjects stream error', err);
|
addLog.error(`[S3 delete] delete prefix: ${prefix} error`, err);
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,9 @@ try {
|
||||||
ChatSchema.index({ chatId: 1 });
|
ChatSchema.index({ chatId: 1 });
|
||||||
// get user history
|
// get user history
|
||||||
ChatSchema.index({ tmbId: 1, appId: 1, deleteTime: 1, top: -1, updateTime: -1 });
|
ChatSchema.index({ tmbId: 1, appId: 1, deleteTime: 1, top: -1, updateTime: -1 });
|
||||||
|
// get share chat history
|
||||||
|
ChatSchema.index({ shareId: 1, outLinkUid: 1, updateTime: -1 });
|
||||||
|
|
||||||
// delete by appid; clear history; init chat; update chat; auth chat; get chat;
|
// delete by appid; clear history; init chat; update chat; auth chat; get chat;
|
||||||
ChatSchema.index({ appId: 1, chatId: 1 });
|
ChatSchema.index({ appId: 1, chatId: 1 });
|
||||||
|
|
||||||
|
|
@ -191,11 +194,8 @@ try {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// get share chat history
|
|
||||||
ChatSchema.index({ shareId: 1, outLinkUid: 1, updateTime: -1 });
|
|
||||||
|
|
||||||
// timer, clear history
|
// timer, clear history
|
||||||
ChatSchema.index({ teamId: 1, updateTime: -1 });
|
ChatSchema.index({ updateTime: -1, teamId: 1 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import { Schema, getMongoLogModel } from '../../../common/mongo';
|
import { Schema, getMongoLogModel } from '../../../common/mongo';
|
||||||
import { type OperationLogSchema } from '@fastgpt/global/support/user/audit/type';
|
import { type TeamAuditSchemaType } from '@fastgpt/global/support/user/audit/type';
|
||||||
import { AdminAuditEventEnum, AuditEventEnum } from '@fastgpt/global/support/user/audit/constants';
|
import { AdminAuditEventEnum, AuditEventEnum } from '@fastgpt/global/support/user/audit/constants';
|
||||||
import {
|
import {
|
||||||
TeamCollectionName,
|
TeamCollectionName,
|
||||||
TeamMemberCollectionName
|
TeamMemberCollectionName
|
||||||
} from '@fastgpt/global/support/user/team/constant';
|
} from '@fastgpt/global/support/user/team/constant';
|
||||||
|
|
||||||
export const OperationLogCollectionName = 'operationLogs';
|
export const TeamAuditCollectionName = 'operationLogs';
|
||||||
|
|
||||||
const OperationLogSchema = new Schema({
|
const TeamAuditSchema = new Schema({
|
||||||
tmbId: {
|
tmbId: {
|
||||||
type: Schema.Types.ObjectId,
|
type: Schema.Types.ObjectId,
|
||||||
ref: TeamMemberCollectionName,
|
ref: TeamMemberCollectionName,
|
||||||
|
|
@ -34,9 +34,10 @@ const OperationLogSchema = new Schema({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
OperationLogSchema.index({ teamId: 1, tmbId: 1, event: 1 });
|
TeamAuditSchema.index({ teamId: 1, tmbId: 1, event: 1 });
|
||||||
|
TeamAuditSchema.index({ timestamp: 1, teamId: 1 });
|
||||||
|
|
||||||
export const MongoOperationLog = getMongoLogModel<OperationLogSchema>(
|
export const MongoTeamAudit = getMongoLogModel<TeamAuditSchemaType>(
|
||||||
OperationLogCollectionName,
|
TeamAuditCollectionName,
|
||||||
OperationLogSchema
|
TeamAuditSchema
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||||
import { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constants';
|
import { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constants';
|
||||||
import { i18nT } from '../../../../web/i18n/utils';
|
import { i18nT } from '../../../../web/i18n/utils';
|
||||||
import { MongoOperationLog } from './schema';
|
import { MongoTeamAudit } from './schema';
|
||||||
import type {
|
import type {
|
||||||
AdminAuditEventEnum,
|
AdminAuditEventEnum,
|
||||||
AuditEventEnum,
|
AuditEventEnum,
|
||||||
|
|
@ -86,7 +86,7 @@ export function addAuditLog<T extends AuditEventEnum | AdminAuditEventEnum>({
|
||||||
params?: any;
|
params?: any;
|
||||||
}) {
|
}) {
|
||||||
retryFn(() =>
|
retryFn(() =>
|
||||||
MongoOperationLog.create({
|
MongoTeamAudit.create({
|
||||||
tmbId: tmbId,
|
tmbId: tmbId,
|
||||||
teamId: teamId,
|
teamId: teamId,
|
||||||
event,
|
event,
|
||||||
|
|
|
||||||
|
|
@ -67,18 +67,12 @@ const SubSchema = new Schema({
|
||||||
customDomain: Number,
|
customDomain: Number,
|
||||||
|
|
||||||
// stand sub and extra points sub. Plan total points
|
// stand sub and extra points sub. Plan total points
|
||||||
totalPoints: {
|
totalPoints: Number,
|
||||||
type: Number
|
// plan surplus points
|
||||||
},
|
surplusPoints: Number,
|
||||||
surplusPoints: {
|
|
||||||
// plan surplus points
|
|
||||||
type: Number
|
|
||||||
},
|
|
||||||
|
|
||||||
// extra dataset size
|
// extra dataset size
|
||||||
currentExtraDatasetSize: {
|
currentExtraDatasetSize: Number
|
||||||
type: Number
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { GET, POST, PUT } from '@/web/common/api/request';
|
import { GET, POST, PUT } from '@/web/common/api/request';
|
||||||
import type { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fetch/type';
|
import type { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fetch/type';
|
||||||
import type { OperationListItemType } from '@fastgpt/global/support/user/audit/type';
|
import type { TeamAuditListItemType } from '@fastgpt/global/support/user/audit/type';
|
||||||
import type { AuditEventEnum } from '@fastgpt/global/support/user/audit/constants';
|
import type { AuditEventEnum } from '@fastgpt/global/support/user/audit/constants';
|
||||||
|
|
||||||
export const getOperationLogs = (
|
export const getOperationLogs = (
|
||||||
|
|
@ -8,4 +8,4 @@ export const getOperationLogs = (
|
||||||
tmbIds?: string[];
|
tmbIds?: string[];
|
||||||
events?: AuditEventEnum[];
|
events?: AuditEventEnum[];
|
||||||
}
|
}
|
||||||
) => POST<PaginationResponse<OperationListItemType>>(`/proApi/support/user/audit/list`, props);
|
) => POST<PaginationResponse<TeamAuditListItemType>>(`/proApi/support/user/audit/list`, props);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue