updates
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { API_CONFIG } from '../config/api';
|
||||
import { API_CONFIG, getApiHeaders } from '../config/api';
|
||||
|
||||
// Types for Service API
|
||||
export interface ServiceFeature {
|
||||
@@ -104,9 +104,7 @@ export const serviceService = {
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: getApiHeaders(),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -134,9 +132,7 @@ export const serviceService = {
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: getApiHeaders(),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -164,9 +160,7 @@ export const serviceService = {
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: getApiHeaders(),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -194,9 +188,7 @@ export const serviceService = {
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: getApiHeaders(),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -224,9 +216,7 @@ export const serviceService = {
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: getApiHeaders(),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -254,9 +244,7 @@ export const serviceService = {
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: getApiHeaders(),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -284,9 +272,7 @@ export const serviceService = {
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: getApiHeaders(),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -441,23 +427,48 @@ export const serviceUtils = {
|
||||
}).format(numPrice);
|
||||
},
|
||||
|
||||
// Get service image URL
|
||||
// Get service image URL with cache-busting
|
||||
// Use relative URLs for same-domain images (Next.js can optimize via rewrites)
|
||||
// Use absolute URLs only for external images
|
||||
// Adds updated_at timestamp as query parameter for cache-busting when images change
|
||||
getServiceImageUrl: (service: Service): string => {
|
||||
let imageUrl: string = '';
|
||||
|
||||
// If service has an uploaded image
|
||||
if (service.image && typeof service.image === 'string' && service.image.startsWith('/media/')) {
|
||||
return `${API_CONFIG.BASE_URL}${service.image}`;
|
||||
imageUrl = service.image;
|
||||
}
|
||||
|
||||
// If service has an image_url
|
||||
if (service.image_url) {
|
||||
else if (service.image_url) {
|
||||
if (service.image_url.startsWith('http')) {
|
||||
return service.image_url;
|
||||
// External URL - keep as absolute
|
||||
imageUrl = service.image_url;
|
||||
} else if (service.image_url.startsWith('/media/')) {
|
||||
// Same domain media - use relative URL
|
||||
imageUrl = service.image_url;
|
||||
} else {
|
||||
// Other relative URLs
|
||||
imageUrl = service.image_url;
|
||||
}
|
||||
return `${API_CONFIG.BASE_URL}${service.image_url}`;
|
||||
} else {
|
||||
// Fallback to default image (relative is fine for public images)
|
||||
imageUrl = '/images/service/default.png';
|
||||
}
|
||||
|
||||
// Fallback to default image
|
||||
return '/images/service/default.png';
|
||||
// Add cache-busting query parameter using updated_at timestamp
|
||||
// This ensures images refresh when service is updated
|
||||
if (service.updated_at && imageUrl && !imageUrl.includes('?')) {
|
||||
try {
|
||||
const timestamp = new Date(service.updated_at).getTime();
|
||||
const separator = imageUrl.includes('?') ? '&' : '?';
|
||||
imageUrl = `${imageUrl}${separator}v=${timestamp}`;
|
||||
} catch (error) {
|
||||
// If date parsing fails, just return the URL without cache-busting
|
||||
console.warn('Failed to parse updated_at for cache-busting:', error);
|
||||
}
|
||||
}
|
||||
|
||||
return imageUrl;
|
||||
},
|
||||
|
||||
// Generate service slug from title
|
||||
|
||||
Reference in New Issue
Block a user