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
+44 -9
View File
@@ -118,19 +118,54 @@ const bucketGetFiles = async (bucketName) => {
return listOfObjects(bucketName)
}
const getSignedUrl = async (fileName, bucketName) => {
if (!fileName) {
return
const parseFileAndBucket = (input, defaultBucket = 'properties') => {
if (!input) return { fileName: '', bucketName: defaultBucket }
const raw = typeof input === 'object' && input !== null
? (input.fileName || input.name || input.url || '')
: String(input || '')
const clean = raw.split('?')[0]
const match = clean.match(/(?:^|\/)(properties|documents|temp|belongings|belonging-images|belonging-documents|property-images|property-documents)\/([^/]+)$/i)
if (match) {
let b = match[1]
if (b === 'property-images' || b === 'belonging-images') b = 'properties'
if (b === 'property-documents' || b === 'belonging-documents') b = 'documents'
return { bucketName: b, fileName: decodeURIComponent(match[2]) }
}
return signedUrl(bucketName, fileName)
const parts = clean.split('/')
const fileName = decodeURIComponent(parts.pop() || '')
return { bucketName: defaultBucket, fileName }
}
const getMultipleSignedUrls = async (fileNameArray, bucketName) => {
const urls = []
for (let fileName of fileNameArray) {
urls.push({ url: await getSignedUrl(fileName, bucketName), fileName: fileName})
const getSignedUrl = async (input, defaultBucket = 'properties') => {
if (!input) {
return null
}
return urls
const { fileName, bucketName } = parseFileAndBucket(input, defaultBucket)
if (!fileName) {
return null
}
try {
return await signedUrl(bucketName, fileName)
} catch (err) {
console.error(`Error generating signed URL for ${bucketName}/${fileName}:`, err.message)
return null
}
}
const getMultipleSignedUrls = async (fileNameArray, defaultBucket = 'properties') => {
if (!fileNameArray || !Array.isArray(fileNameArray)) {
return []
}
const results = await Promise.all(
fileNameArray.map(async (item) => {
const { fileName, bucketName } = parseFileAndBucket(item, defaultBucket)
if (!fileName) return null
const url = await getSignedUrl(item, bucketName)
return url ? { url, fileName, bucketName } : null
})
)
return results.filter(Boolean)
}
const moveFromTempToMain = async (files, targetBucket) => {