22 lines
1.1 KiB
JavaScript
22 lines
1.1 KiB
JavaScript
// معادل سرور buildStorageUrl سمت RN (modstagram_front-main/src/shared/config/env.ts) —
|
|
// مسیر نسبی ذخیرهشده در دیتابیس (مثلاً "/profiles/xxx.jpg") رو به URL کامل قابلدسترس
|
|
// از بیرون (برای notification.image پوش FCM و مشابه) تبدیل میکنه
|
|
const STORAGE_BASE_URL = (process.env.APP_URL || 'https://api.modstagram.com/api/v1').replace(/\/api\/v1\/?$/, '') + '/storage'
|
|
|
|
function buildStorageUrl (path) {
|
|
if (!path) return ''
|
|
const value = String(path)
|
|
if (value.startsWith('http://') || value.startsWith('https://')) return value
|
|
let normalized = value.replace(/\\/g, '/')
|
|
normalized = normalized.replace('/root/modstagram-back/storage', '')
|
|
if (normalized.startsWith('/storage/')) {
|
|
normalized = normalized.slice('/storage'.length)
|
|
} else if (normalized.startsWith('storage/')) {
|
|
normalized = `/${normalized.slice('storage/'.length)}`
|
|
}
|
|
if (!normalized.startsWith('/')) normalized = `/${normalized}`
|
|
return `${STORAGE_BASE_URL}${normalized}`
|
|
}
|
|
|
|
module.exports = { buildStorageUrl, STORAGE_BASE_URL }
|