fix(s3): generate and use seaweedfs signed urls for properties and documents
deploy-chabokan / deploy (push) Canceled after 0s

This commit is contained in:
2026-08-19 06:30:00 +03:30
parent acb2e5d623
commit 982b9e759f
4 changed files with 56 additions and 17 deletions
+2 -2
View File
@@ -68,11 +68,11 @@ const belongingSchema = new mongoose.Schema(
belongingSchema.plugin(AutoIncrement, { inc_field: 'belongingCode' })
belongingSchema.methods.getDocumentsSignedUrls = function () {
return getMultipleSignedUrls(this.documentUrls, 'belonging-documents')
return getMultipleSignedUrls(this.documentUrls, 'documents')
}
belongingSchema.methods.getMainImagedSignedUrl = function () {
return getMultipleSignedUrls(this.mainImageUrls, 'belonging-images')
return getMultipleSignedUrls(this.mainImageUrls, 'properties')
}
belongingSchema.index({ location: '2dsphere' }) // Enable geospatial queries
+2 -2
View File
@@ -116,11 +116,11 @@ const propertySchema = new mongoose.Schema(
propertySchema.plugin(AutoIncrement, { inc_field: 'propertyCode' })
propertySchema.methods.getDocumentsSignedUrls = function () {
return getMultipleSignedUrls(this.documentUrls, 'property-documents')
return getMultipleSignedUrls(this.documentUrls, 'documents')
}
propertySchema.methods.getMainImagedSignedUrl = function () {
return getMultipleSignedUrls(this.mainImageUrls, 'property-images')
return getMultipleSignedUrls(this.mainImageUrls, 'properties')
}
propertySchema.index({ location: '2dsphere' })
+8 -4
View File
@@ -4,7 +4,7 @@ const Building = require('./buildingModel')
const AppError = require('../../globalErrorHandler/AppError')
const { client } = require('../../setup/typesense')
const TsApiFeatures = require('../../utils/TsApiFeatures')
const { moveFromTempToMain } = require('../file/fileService')
const { moveFromTempToMain, getSignedUrl } = require('../file/fileService')
const getAllProperties = async () => {
return Property.find({}, null, null).populate('category').populate('status')
@@ -153,8 +153,12 @@ const searchPropertiesMongo = async (inputQuery = {}) => {
.skip((page - 1) * per_page)
.limit(per_page)
const items = properties.map((prop) => {
const items = await Promise.all(properties.map(async (prop) => {
const combinedTags = Array.isArray(prop.tags) ? prop.tags.join(' ') : (prop.tags || '')
let signedThumb = null
if (prop.mainImageUrls && prop.mainImageUrls.length > 0) {
signedThumb = await getSignedUrl(prop.mainImageUrls[0], 'properties').catch(() => null)
}
return {
_id: prop._id.toString(),
id: prop.propertyCode ? prop.propertyCode.toString() : prop._id.toString(),
@@ -164,7 +168,7 @@ const searchPropertiesMongo = async (inputQuery = {}) => {
nativeCategory: prop.category?.nativeName || '',
categoryObj: prop.category,
status: prop.status,
imageUrl: prop.mainImageUrls?.[0] || 'https://cloud.mbmanager.ir/images/item-no-image.png',
imageUrl: signedThumb || 'https://cloud.mbmanager.ir/images/item-no-image.png',
mainImageUrls: prop.mainImageUrls || [],
documents: prop.documentUrls || [],
documentUrls: prop.documentUrls || [],
@@ -183,7 +187,7 @@ const searchPropertiesMongo = async (inputQuery = {}) => {
isActive: prop.isActive !== false,
features: prop.features || [],
}
})
}))
const pagesCount = Math.ceil(totalCount / per_page) || 1