Fix image URLs: handle paths with or without leading slash
All checks were successful
Build frontend / build (push) Successful in 39s
All checks were successful
Build frontend / build (push) Successful in 39s
Some API paths have / (e.g. /Pictures/abc.jpg) and some don't (e.g. scaled_photo.jpg). Now always inserts / between API base and path.
This commit is contained in:
@ -749,7 +749,7 @@ export default function OwnerPropertiesPage() {
|
|||||||
images: (() => {
|
images: (() => {
|
||||||
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'http://45.93.137.91/api') : '';
|
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'http://45.93.137.91/api') : '';
|
||||||
const raw = Array.isArray(info.images) ? info.images : [];
|
const raw = Array.isArray(info.images) ? info.images : [];
|
||||||
return raw.length > 0 ? raw.map(img => img.startsWith('http') ? img : `${apiBase}${img}`) : ['/property-placeholder.jpg'];
|
return raw.length > 0 ? raw.map(img => img.startsWith('http') ? img : `${apiBase}${img.startsWith('/') ? '' : '/'}${img}`) : ['/property-placeholder.jpg'];
|
||||||
})(),
|
})(),
|
||||||
createdAt: item.createdAt || new Date().toISOString(),
|
createdAt: item.createdAt || new Date().toISOString(),
|
||||||
furnished: details.furnished || false,
|
furnished: details.furnished || false,
|
||||||
|
|||||||
@ -55,7 +55,7 @@ function mapApiProperty(item, index) {
|
|||||||
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'http://45.93.137.91/api') : '';
|
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'http://45.93.137.91/api') : '';
|
||||||
const rawImages = Array.isArray(info.images) ? info.images : [];
|
const rawImages = Array.isArray(info.images) ? info.images : [];
|
||||||
const images = rawImages.length > 0
|
const images = rawImages.length > 0
|
||||||
? rawImages.map(img => img.startsWith('http') ? img : `${apiBase}${img}`)
|
? rawImages.map(img => img.startsWith('http') ? img : `${apiBase}${img.startsWith('/') ? '' : '/'}${img}`)
|
||||||
: ['/property-placeholder.jpg'];
|
: ['/property-placeholder.jpg'];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -57,7 +57,7 @@ function mapApiProperty(item, index) {
|
|||||||
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'http://45.93.137.91/api') : '';
|
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'http://45.93.137.91/api') : '';
|
||||||
const rawImages = Array.isArray(info.images) ? info.images : [];
|
const rawImages = Array.isArray(info.images) ? info.images : [];
|
||||||
const images = rawImages.length > 0
|
const images = rawImages.length > 0
|
||||||
? rawImages.map(img => img.startsWith('http') ? img : `${apiBase}${img}`)
|
? rawImages.map(img => img.startsWith('http') ? img : `${apiBase}${img.startsWith('/') ? '' : '/'}${img}`)
|
||||||
: ['/property-placeholder.jpg'];
|
: ['/property-placeholder.jpg'];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -74,7 +74,7 @@ function mapApiDetail(item) {
|
|||||||
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'http://45.93.137.91/api') : '';
|
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'http://45.93.137.91/api') : '';
|
||||||
const rawImages = Array.isArray(info.images) ? info.images : [];
|
const rawImages = Array.isArray(info.images) ? info.images : [];
|
||||||
const images = rawImages.length > 0
|
const images = rawImages.length > 0
|
||||||
? rawImages.map(img => img.startsWith('http') ? img : `${apiBase}${img}`)
|
? rawImages.map(img => img.startsWith('http') ? img : `${apiBase}${img.startsWith('/') ? '' : '/'}${img}`)
|
||||||
: ['/property-placeholder.jpg', '/villa1.jpg', '/villa2.jpg'];
|
: ['/property-placeholder.jpg', '/villa1.jpg', '/villa2.jpg'];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user