Files
modstagram-back/models/StoryModel.js
payacom 3f416a7a60 full
2026-08-31 20:45:41 +03:30

86 lines
2.2 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 timestamp = require('mongoose-timestamp')
// متن‌ها و لینک‌های روی استوری با مختصات نسبی (۰ تا ۱) تا در هر ابعادی درست رندر شوند —
// type مشخص می‌کنه اورلی متنیه یا لینکِ یکی از موارد قابل‌لینک (پکیج/پروژه/بیلبورد/فروشگاه/
// کالا/رزرو، همون‌هایی که توی ثبت پست هم قابل‌لینک‌ان)
const overlaySchema = new mongoose.Schema({
type: { type: String, enum: ['text', 'link'], default: 'text' },
text: { type: String, default: '' },
x: { type: Number, default: 0.5 },
y: { type: Number, default: 0.5 },
font_size: { type: Number, default: 0.06 },
color: { type: String, default: '#ffffff' },
background: { type: String, default: '' },
rotation: { type: Number, default: 0 },
align: { type: String, default: 'center' },
// فقط برای type:'link'
link_kind: { type: String, default: null },
link_id: { type: String, default: null },
link_title: { type: String, default: null }
}, { _id: false })
const storySchema = new mongoose.Schema({
user_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true,
index: true
},
media_path: {
type: String,
required: true
},
media_type: {
type: String,
enum: ['image', 'video'],
required: true
},
overlays: {
type: [overlaySchema],
default: []
},
linked_post_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Post',
default: null
},
expires_at: {
type: Date,
required: true,
index: true
},
viewers: [{
user_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
viewed_at: {
type: Date,
default: Date.now
}
}],
likes: [{
user_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
liked_at: {
type: Date,
default: Date.now
}
}],
admin_status: {
type: String,
enum: ['active', 'inactive'],
default: 'active',
index: true,
},
})
storySchema.index({ expires_at: 1 }, { expireAfterSeconds: 0 })
storySchema.plugin(timestamp)
module.exports = mongoose.model('Story', storySchema)