Fix image URLs: handle paths with or without leading slash
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:
Claw AI
2026-03-30 01:35:20 +00:00
parent 9d671f1985
commit 722d69cc92
4 changed files with 4 additions and 4 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {