nakama/backend/models/Post.js

93 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const mongoose = require('mongoose');
const CommentSchema = new mongoose.Schema({
author: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
content: {
type: String,
required: true,
maxlength: 500
},
editedAt: {
type: Date
},
createdAt: {
type: Date,
default: Date.now
}
});
const PostSchema = new mongoose.Schema({
author: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
content: {
type: String,
maxlength: 2000
},
hashtags: [{
type: String,
lowercase: true,
trim: true
}],
imageUrl: String, // Старое поле для совместимости
images: [String], // Новое поле - массив изображений
tags: [{
type: String,
enum: ['furry', 'anime', 'other'],
required: true
}],
mentionedUsers: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}],
isNSFW: {
type: Boolean,
default: false
},
// Отдельный флаг для гомосексуального контента
// Может отсутствовать у старых постов, поэтому фильтры должны учитывать isHomo === true
isHomo: {
type: Boolean,
default: false
},
likes: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}],
comments: [CommentSchema],
views: {
type: Number,
default: 0
},
// Поля для постов из канала
publishedToChannel: {
type: Boolean,
default: false
},
channelMessageId: {
type: Number
},
adminNumber: {
type: Number
},
editedAt: {
type: Date
},
createdAt: {
type: Date,
default: Date.now
}
});
// Текстовый индекс для поиска
PostSchema.index({ content: 'text', hashtags: 'text' });
module.exports = mongoose.model('Post', PostSchema);