Files
modstagram-back/models/StoryModel.js
payacom c302aea177 4.1.3
2026-09-13 21:32:36 +03:30

99 lines
3.1 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', 'mention', 'hashtag', 'location', 'sticker'], default: 'text' },
// text: متن آزاد (type:'text') | متن تگ بدون # (type:'hashtag') | نام مکان (type:'location') |
// خودِ ایموجی (type:'sticker')
text: { type: String, default: '' },
x: { type: Number, default: 0.5 },
y: { type: Number, default: 0.5 },
font_size: { type: Number, default: 0.06 },
// فقط برای type:'text' — کدوم واریانت فونتِ برندِ اپ (Vazir/IRANSansX) استفاده بشه؛
// چون اپ فعلاً فقط یک خانواده‌فونت با وزن‌های مختلف داره (نه چند تایپ‌فیس واقعیِ جدا مثل
// اینستاگرام)، این همون گزینه‌های واقعاً موجودیه
font_family: {
type: String,
enum: ['light', 'regular', 'medium', 'bold', 'black'],
default: 'bold'
},
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 },
// فقط برای type:'mention'
mention_user_id: { type: String, default: null },
mention_username: { 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)