新功能: - 创建AI聊天助手组件(AIChatWidget) - 支持文字+图片多模态对话 - 集成Gemini AI API - 支持图片编辑和内容生成 - 实时对话历史管理 - 优雅的UI设计,支持黑夜模式 技术实现: - 后端API代理Gemini API(/api/ai-chat) - 支持最多5张图片上传 - 流式响应处理 - 对话历史管理 - Base64图片处理 配置: - 在.env中添加Gemini API配置 - GEMINI_API_KEY - GEMINI_API_BASE_URL - GEMINI_MODEL 替换原弹幕功能,提供更强大的AI助手体验!
81 lines
1.7 KiB
JavaScript
Executable File
81 lines
1.7 KiB
JavaScript
Executable File
const mongoose = require('mongoose');
|
||
|
||
// 检查模型是否已经存在,如果存在则直接返回
|
||
if (mongoose.models.Notification) {
|
||
module.exports = mongoose.models.Notification;
|
||
return;
|
||
}
|
||
|
||
const notificationSchema = new mongoose.Schema({
|
||
title: {
|
||
type: String,
|
||
required: true,
|
||
trim: true,
|
||
maxlength: 100
|
||
},
|
||
content: {
|
||
type: String,
|
||
required: true,
|
||
trim: true,
|
||
maxlength: 5000
|
||
},
|
||
type: {
|
||
type: String,
|
||
enum: ['info', 'warning', 'success', 'error', 'announcement'],
|
||
default: 'info'
|
||
},
|
||
priority: {
|
||
type: String,
|
||
enum: ['low', 'medium', 'high', 'urgent'],
|
||
default: 'medium'
|
||
},
|
||
status: {
|
||
type: String,
|
||
enum: ['draft', 'published', 'archived'],
|
||
default: 'draft'
|
||
},
|
||
targetUsers: {
|
||
type: String,
|
||
enum: ['all', 'admin', 'vip', 'regular'],
|
||
default: 'all'
|
||
},
|
||
createdBy: {
|
||
type: mongoose.Schema.Types.ObjectId,
|
||
ref: 'User',
|
||
required: true
|
||
},
|
||
publishDate: {
|
||
type: Date,
|
||
default: Date.now
|
||
},
|
||
expiryDate: {
|
||
type: Date,
|
||
default: function() {
|
||
// 默认30天后过期
|
||
const date = new Date();
|
||
date.setDate(date.getDate() + 30);
|
||
return date;
|
||
}
|
||
},
|
||
readBy: [{
|
||
user: {
|
||
type: mongoose.Schema.Types.ObjectId,
|
||
ref: 'User'
|
||
},
|
||
readAt: {
|
||
type: Date,
|
||
default: Date.now
|
||
}
|
||
}]
|
||
}, {
|
||
timestamps: true
|
||
});
|
||
|
||
// 添加索引以提高查询性能
|
||
notificationSchema.index({ status: 1, publishDate: -1 });
|
||
notificationSchema.index({ targetUsers: 1, status: 1 });
|
||
notificationSchema.index({ expiryDate: 1 }, { expireAfterSeconds: 0 }); // TTL索引,过期自动删除
|
||
|
||
const Notification = mongoose.model('Notification', notificationSchema);
|
||
|
||
module.exports = Notification;
|