fix(torob): sanitize imageLink in Torob API and feed to always use frontend domain and proxy path
This commit is contained in:
1 parent
376fea356f
commit
88060431bb
14 files changed
+9023
-8720
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { productService } from '../../../../lib/services/productService';
|
||||
import { PRODUCTS } from '../../../../lib/data/products';
|
||||
import { getMediaUrl } from '../../../../lib/media';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const revalidate = 3600;
|
||||
@@ -39,11 +40,13 @@ export async function GET(request: NextRequest) {
|
||||
const nameEn = product.nameEn || '';
|
||||
const title = nameEn ? `${nameFa} (${nameEn})` : nameFa;
|
||||
const primaryImg = product.ogImage || product.image || product.imageUrl || '';
|
||||
const imageLink = primaryImg
|
||||
? primaryImg.startsWith('http')
|
||||
? primaryImg
|
||||
: `${baseUrl}${primaryImg.startsWith('/') ? primaryImg : `/${primaryImg}`}`
|
||||
: '';
|
||||
let imageLink = '';
|
||||
if (primaryImg) {
|
||||
const proxied = getMediaUrl(primaryImg);
|
||||
imageLink = proxied.startsWith('http')
|
||||
? proxied
|
||||
: `${baseUrl}${proxied.startsWith('/') ? proxied : `/${proxied}`}`;
|
||||
}
|
||||
|
||||
const isInStock =
|
||||
product.stockStatus !== 'OUT_OF_STOCK' &&
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { productService } from '../../../lib/services/productService';
|
||||
import { PRODUCTS } from '../../../lib/data/products';
|
||||
import { getMediaUrl } from '../../../lib/media';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const revalidate = 3600; // Revalidate every hour
|
||||
@@ -27,7 +28,11 @@ export async function GET() {
|
||||
const description = product.metaDescription || product.shortDescription || product.description || 'مکمل درمانی اصل کنینا آلمان';
|
||||
|
||||
const primaryImg = product.ogImage || product.image;
|
||||
const imageLink = primaryImg ? (primaryImg.startsWith('http') ? primaryImg : `${baseUrl}${primaryImg}`) : '';
|
||||
let imageLink = '';
|
||||
if (primaryImg) {
|
||||
const proxied = getMediaUrl(primaryImg);
|
||||
imageLink = proxied.startsWith('http') ? proxied : `${baseUrl}${proxied.startsWith('/') ? proxied : `/${proxied}`}`;
|
||||
}
|
||||
|
||||
let availability = 'in_stock';
|
||||
if (product.stockStatus === 'OUT_OF_STOCK') availability = 'out_of_stock';
|
||||
@@ -38,7 +43,11 @@ export async function GET() {
|
||||
const additionalImages = (product.images || [])
|
||||
.filter((img: string) => img && img !== primaryImg)
|
||||
.slice(0, 5)
|
||||
.map((img: string) => `<g:additional_image_link>${img.startsWith('http') ? img : `${baseUrl}${img}`}</g:additional_image_link>`)
|
||||
.map((img: string) => {
|
||||
const proxied = getMediaUrl(img);
|
||||
const full = proxied.startsWith('http') ? proxied : `${baseUrl}${proxied.startsWith('/') ? proxied : `/${proxied}`}`;
|
||||
return `<g:additional_image_link>${full}</g:additional_image_link>`;
|
||||
})
|
||||
.join('\n ');
|
||||
|
||||
return ` <item>
|
||||
|
||||
Reference in new issue
Block a user