S3 for other controolers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const mongoose = require("mongoose");
|
||||
const s3Storage = require("../plugins/s3Storage");
|
||||
|
||||
function autoPopulateSubs(next) {
|
||||
this.populate({
|
||||
@@ -14,12 +15,21 @@ function autoPopulateSubs(next) {
|
||||
}
|
||||
|
||||
function file(file) {
|
||||
return "/uploads/files/terms/" + file;
|
||||
if (!file) return null;
|
||||
if (file.startsWith("http://") || file.startsWith("https://")) return file;
|
||||
return s3Storage.getPublicUrl(`uploads/files/terms/${file}`);
|
||||
}
|
||||
|
||||
function image(img) {
|
||||
if (img) return "/uploads/images/category/" + img;
|
||||
else return "/img/no-cover.jpg";
|
||||
if (!img) return "/img/no-cover.jpg";
|
||||
if (img.startsWith("http://") || img.startsWith("https://")) return img;
|
||||
return s3Storage.getPublicUrl(`uploads/images/category/${img}`);
|
||||
}
|
||||
|
||||
function shafafiatIcon(icon) {
|
||||
if (!icon) return null;
|
||||
if (icon.startsWith("http://") || icon.startsWith("https://")) return icon;
|
||||
return s3Storage.getPublicUrl(`uploads/images/category/shafafiat/${icon}`);
|
||||
}
|
||||
|
||||
const CategoryTermsFile = mongoose.Schema({
|
||||
@@ -71,7 +81,7 @@ const CategorySchema = mongoose.Schema({
|
||||
managerName: String,
|
||||
managerDescription: String,
|
||||
/** if category was shafafiat this icon is for that */
|
||||
icon: String,
|
||||
icon: { type: String, get: shafafiatIcon, default: null },
|
||||
});
|
||||
|
||||
CategorySchema.index({ parent: 1, childs: 1 });
|
||||
|
||||
Reference in New Issue
Block a user