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
@@ -42,15 +42,20 @@ export class TorobController {
|
||||
const nameEn = product.nameEn || '';
|
||||
const title = nameEn ? `${nameFa} (${nameEn})` : nameFa;
|
||||
|
||||
const rawImage = product.ogImage || product.imageUrl || '';
|
||||
let imageLink = '';
|
||||
if (product.ogImage) {
|
||||
imageLink = product.ogImage.startsWith('http')
|
||||
? product.ogImage
|
||||
: `${baseUrl}${product.ogImage.startsWith('/') ? product.ogImage : `/${product.ogImage}`}`;
|
||||
} else if (product.imageUrl) {
|
||||
imageLink = product.imageUrl.startsWith('http')
|
||||
? product.imageUrl
|
||||
: `${baseUrl}/uploads/${product.imageUrl.replace(/^\/?(uploads\/)?/, '')}`;
|
||||
if (rawImage) {
|
||||
const cleanImage = rawImage.trim()
|
||||
.replace(/^https?:\/\/api\.canina\.ir/i, '')
|
||||
.replace(/^https?:\/\/localhost:\d+/i, '')
|
||||
.replace(/^https?:\/\/127\.0\.0\.1:\d+/i, '');
|
||||
|
||||
if (cleanImage.startsWith('http://') || cleanImage.startsWith('https://')) {
|
||||
imageLink = cleanImage;
|
||||
} else {
|
||||
const cleanPath = cleanImage.replace(/^\/?(api\/)?(uploads\/)?/, '');
|
||||
imageLink = `${baseUrl}/api/uploads/${cleanPath}`;
|
||||
}
|
||||
}
|
||||
|
||||
const isInStock = product.stockStatus !== 'DISCONTINUED' && String(product.stockStatus || '').toLowerCase().includes('in');
|
||||
|
||||
Reference in new issue
Block a user