const mongoose = require('mongoose'); const mongoosePaginate = require('mongoose-paginate-v2'); const s3Storage = require('../plugins/s3Storage'); function galleryUrl(img, prefix) { if (!img) return null; if (img.startsWith('http://') || img.startsWith('https://')) return img; return s3Storage.getPublicUrl(`${prefix}/${img}`); } function image(img) { return galleryUrl(img, 'uploads/images/gallery'); } function graphic(img) { return galleryUrl(img, 'uploads/graphics/gallery'); } function video(vdo) { return galleryUrl(vdo, 'uploads/videos/gallery'); } const GallerySchema = mongoose.Schema({ title: String, shortTitlePanel: String, shortTitleFront: String, summaryTitle: String, shortSummaryTitle: String, leadTitle: String, catId: {type: mongoose.Schema.Types.ObjectId, ref: 'Category'}, rootParent: {type: mongoose.Schema.Types.ObjectId, ref: 'Category'}, allCat: [{type: mongoose.Schema.Types.ObjectId, ref: 'Category'}], newsFileId: {type: mongoose.Schema.Types.ObjectId, ref: 'NewsFile'}, // priority: {type : Number , default : 0}, publish: {type: Boolean, default: false}, showInHome: {type: Boolean, default: true}, graphic: {type: String, get: graphic, default: null}, thumbGraphic: {type: String, get: graphic, default: null}, cover: {type: String, get: image, default: null}, thumbCover: {type: String, get: image, default: null}, uidImage:[{type:String , get:image , default:null}], images: [{type: String, get: image, default: null}], thumbImages: [{type: String, get: image, default: null}], video: {type: String, get: video, default: null}, isEmbedded: {type: Boolean, default: false}, embeddedCode: String, userViews: {type: Number, default: 0}, special: {type: Boolean, default: false}, _creator: {type: mongoose.Schema.Types.ObjectId, ref: 'User'}, _updatedBy: {type: mongoose.Schema.Types.ObjectId, ref: 'User'}, siteMap: {type: Boolean, default: true}, modelType: String, keywords: {type: Array, default: []}, metaTagDesc: {type: String, default: null}, galleryType: {type: String, enum: ['image', 'video', 'graphic']}, galleryStatus: {type: Boolean, default: false}, customDate: {type: Date, default: Date.now}, customDateHistory: Array, favorite: {type: Boolean, default: false} }, {toJson: {getters: false}}); GallerySchema.plugin(mongoosePaginate); module.exports = mongoose.model('Gallery', GallerySchema);