mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
v4.5.2 (#439)
This commit is contained in:
1
packages/service/common/file/image/constant.ts
Normal file
1
packages/service/common/file/image/constant.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const imageBaseUrl = '/api/system/img/';
|
25
packages/service/common/file/image/controller.ts
Normal file
25
packages/service/common/file/image/controller.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { imageBaseUrl } from './constant';
|
||||
import { MongoImage } from './schema';
|
||||
|
||||
export function getMongoImgUrl(id: string) {
|
||||
return `${imageBaseUrl}${id}`;
|
||||
}
|
||||
|
||||
export async function uploadMongoImg({ base64Img, userId }: { base64Img: string; userId: string }) {
|
||||
const base64Data = base64Img.split(',')[1];
|
||||
|
||||
const { _id } = await MongoImage.create({
|
||||
userId,
|
||||
binary: Buffer.from(base64Data, 'base64')
|
||||
});
|
||||
|
||||
return getMongoImgUrl(String(_id));
|
||||
}
|
||||
|
||||
export async function readMongoImg({ id }: { id: string }) {
|
||||
const data = await MongoImage.findById(id);
|
||||
if (!data) {
|
||||
return Promise.reject('Image not found');
|
||||
}
|
||||
return data?.binary;
|
||||
}
|
16
packages/service/common/file/image/schema.ts
Normal file
16
packages/service/common/file/image/schema.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { connectionMongo, type Model } from '../../mongo';
|
||||
const { Schema, model, models } = connectionMongo;
|
||||
|
||||
const ImageSchema = new Schema({
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: true
|
||||
},
|
||||
binary: {
|
||||
type: Buffer
|
||||
}
|
||||
});
|
||||
|
||||
export const MongoImage: Model<{ userId: string; binary: Buffer }> =
|
||||
models['image'] || model('image', ImageSchema);
|
@@ -63,6 +63,7 @@ const TrainingDataSchema = new Schema({
|
||||
try {
|
||||
TrainingDataSchema.index({ lockTime: 1 });
|
||||
TrainingDataSchema.index({ userId: 1 });
|
||||
TrainingDataSchema.index({ datasetCollectionId: 1 });
|
||||
TrainingDataSchema.index({ expireAt: 1 }, { expireAfterSeconds: 7 * 24 * 60 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
63
packages/service/core/plugin/controller.ts
Normal file
63
packages/service/core/plugin/controller.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { CreateOnePluginParams, UpdatePluginParams } from '@fastgpt/global/core/plugin/controller';
|
||||
import { MongoPlugin } from './schema';
|
||||
import { FlowModuleTemplateType } from '@fastgpt/global/core/module/type';
|
||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant';
|
||||
import { formatPluginIOModules } from '@fastgpt/global/core/module/utils';
|
||||
|
||||
export async function createOnePlugin(data: CreateOnePluginParams & { userId: string }) {
|
||||
const { _id } = await MongoPlugin.create(data);
|
||||
return _id;
|
||||
}
|
||||
|
||||
export async function updateOnePlugin({
|
||||
id,
|
||||
userId,
|
||||
...data
|
||||
}: UpdatePluginParams & { userId: string }) {
|
||||
await MongoPlugin.findOneAndUpdate({ _id: id, userId }, data);
|
||||
}
|
||||
|
||||
export async function deleteOnePlugin({ id, userId }: { id: string; userId: string }) {
|
||||
await MongoPlugin.findOneAndDelete({ _id: id, userId });
|
||||
}
|
||||
export async function getUserPlugins({ userId }: { userId: string }) {
|
||||
return MongoPlugin.find({ userId }, 'name avatar intro');
|
||||
}
|
||||
export async function getOnePluginDetail({ id, userId }: { userId: string; id: string }) {
|
||||
return MongoPlugin.findOne({ _id: id, userId });
|
||||
}
|
||||
/* plugin templates */
|
||||
export async function getUserPlugins2Templates({
|
||||
userId
|
||||
}: {
|
||||
userId: string;
|
||||
}): Promise<FlowModuleTemplateType[]> {
|
||||
const plugins = await MongoPlugin.find({ userId }).lean();
|
||||
|
||||
return plugins.map((plugin) => ({
|
||||
id: String(plugin._id),
|
||||
flowType: FlowNodeTypeEnum.pluginModule,
|
||||
logo: plugin.avatar,
|
||||
name: plugin.name,
|
||||
description: plugin.intro,
|
||||
intro: plugin.intro,
|
||||
showStatus: false,
|
||||
inputs: [],
|
||||
outputs: []
|
||||
}));
|
||||
}
|
||||
/* one plugin 2 module detail */
|
||||
export async function getPluginModuleDetail({ id, userId }: { userId: string; id: string }) {
|
||||
const plugin = await getOnePluginDetail({ id, userId });
|
||||
if (!plugin) return Promise.reject('plugin not found');
|
||||
return {
|
||||
id: String(plugin._id),
|
||||
flowType: FlowNodeTypeEnum.pluginModule,
|
||||
logo: plugin.avatar,
|
||||
name: plugin.name,
|
||||
description: plugin.intro,
|
||||
intro: plugin.intro,
|
||||
showStatus: false,
|
||||
...formatPluginIOModules(String(plugin._id), plugin.modules)
|
||||
};
|
||||
}
|
42
packages/service/core/plugin/schema.ts
Normal file
42
packages/service/core/plugin/schema.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { connectionMongo, type Model } from '../../common/mongo';
|
||||
const { Schema, model, models } = connectionMongo;
|
||||
import type { PluginItemSchema } from '@fastgpt/global/core/plugin/type.d';
|
||||
|
||||
export const ModuleCollectionName = 'plugins';
|
||||
|
||||
const PluginSchema = new Schema({
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: true
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
avatar: {
|
||||
type: String,
|
||||
default: '/icon/logo.svg'
|
||||
},
|
||||
intro: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
updateTime: {
|
||||
type: Date,
|
||||
default: () => new Date()
|
||||
},
|
||||
modules: {
|
||||
type: Array,
|
||||
default: []
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
PluginSchema.index({ userId: 1 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
export const MongoPlugin: Model<PluginItemSchema> =
|
||||
models[ModuleCollectionName] || model(ModuleCollectionName, PluginSchema);
|
32
packages/service/support/activity/promotion/schema.ts
Normal file
32
packages/service/support/activity/promotion/schema.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { connectionMongo, type Model } from '../../../common/mongo';
|
||||
const { Schema, model, models } = connectionMongo;
|
||||
import { PromotionRecordSchema as PromotionRecordType } from '@fastgpt/global/support/activity/type.d';
|
||||
|
||||
const PromotionRecordSchema = new Schema({
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: true
|
||||
},
|
||||
objUId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: false
|
||||
},
|
||||
createTime: {
|
||||
type: Date,
|
||||
default: () => new Date()
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: ['pay', 'register']
|
||||
},
|
||||
amount: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
export const MongoPromotionRecord: Model<PromotionRecordType> =
|
||||
models['promotionRecord'] || model('promotionRecord', PromotionRecordSchema);
|
45
packages/service/support/user/inform/controller.ts
Normal file
45
packages/service/support/user/inform/controller.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { MongoUserInform } from './schema';
|
||||
import { MongoUser } from '../schema';
|
||||
import { InformTypeEnum } from '@fastgpt/global/support/user/constant';
|
||||
|
||||
export type SendInformProps = {
|
||||
type: `${InformTypeEnum}`;
|
||||
title: string;
|
||||
content: string;
|
||||
};
|
||||
|
||||
export async function sendInform2AllUser({ type, title, content }: SendInformProps) {
|
||||
const users = await MongoUser.find({}, '_id');
|
||||
await MongoUserInform.insertMany(
|
||||
users.map(({ _id }) => ({
|
||||
type,
|
||||
title,
|
||||
content,
|
||||
userId: _id
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
export async function sendInform2OneUser({
|
||||
type,
|
||||
title,
|
||||
content,
|
||||
userId
|
||||
}: SendInformProps & { userId: string }) {
|
||||
const inform = await MongoUserInform.findOne({
|
||||
type,
|
||||
title,
|
||||
content,
|
||||
userId,
|
||||
time: { $gte: new Date(Date.now() - 5 * 60 * 1000) }
|
||||
});
|
||||
|
||||
if (inform) return;
|
||||
|
||||
await MongoUserInform.create({
|
||||
type,
|
||||
title,
|
||||
content,
|
||||
userId
|
||||
});
|
||||
}
|
42
packages/service/support/user/inform/schema.ts
Normal file
42
packages/service/support/user/inform/schema.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { connectionMongo, type Model } from '../../../common/mongo';
|
||||
const { Schema, model, models } = connectionMongo;
|
||||
import type { UserInformSchema } from '@fastgpt/global/support/user/type.d';
|
||||
import { InformTypeMap } from '@fastgpt/global/support/user/constant';
|
||||
|
||||
const InformSchema = new Schema({
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: true
|
||||
},
|
||||
time: {
|
||||
type: Date,
|
||||
default: () => new Date()
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
enum: Object.keys(InformTypeMap)
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
read: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
InformSchema.index({ time: -1 });
|
||||
InformSchema.index({ userId: 1 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
export const MongoUserInform: Model<UserInformSchema> =
|
||||
models['inform'] || model('inform', InformSchema);
|
31
packages/service/support/wallet/pay/schema.ts
Normal file
31
packages/service/support/wallet/pay/schema.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { connectionMongo, type Model } from '../../../common/mongo';
|
||||
const { Schema, model, models } = connectionMongo;
|
||||
import { PaySchema as PayType } from '@fastgpt/global/support/wallet/type.d';
|
||||
|
||||
const PaySchema = new Schema({
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: true
|
||||
},
|
||||
createTime: {
|
||||
type: Date,
|
||||
default: () => new Date()
|
||||
},
|
||||
price: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
orderId: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
status: {
|
||||
// 支付的状态
|
||||
type: String,
|
||||
default: 'NOTPAY',
|
||||
enum: ['SUCCESS', 'REFUND', 'NOTPAY', 'CLOSED']
|
||||
}
|
||||
});
|
||||
|
||||
export const MongoPay: Model<PayType> = models['pay'] || model('pay', PaySchema);
|
Reference in New Issue
Block a user