Fix image CORS loader and Supabase credentials
This commit is contained in:
@@ -300,14 +300,14 @@ async function resolveProductUrl(input) {
|
|||||||
try {
|
try {
|
||||||
const res = await fetch(`https://fmcltrjnuvuooarkvufn.supabase.co/rest/v1/products?id=eq.${productId}&select=*`, {
|
const res = await fetch(`https://fmcltrjnuvuooarkvufn.supabase.co/rest/v1/products?id=eq.${productId}&select=*`, {
|
||||||
headers: {
|
headers: {
|
||||||
'apikey': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZtY2x0cmpudXZ1b29hcmt2dWZuIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjY3MjEzNzgsImV4cCI6MjA0MjI5NzM3OH0.528YkG1V7c8UoK5QvW_V1hS0W1oQ5W_V1hS0W1oQ5W8',
|
'apikey': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZtY2x0cmpudXZ1b29hcmt2dWZuIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzUxMzY3MDQsImV4cCI6MjA5MDcxMjcwNH0.PkSgBAZx41X4sZurfyOdxCVa01hkKTkyBhVkGzx_4y4',
|
||||||
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZtY2x0cmpudXZ1b29hcmt2dWZuIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjY3MjEzNzgsImV4cCI6MjA0MjI5NzM3OH0.528YkG1V7c8UoK5QvW_V1hS0W1oQ5W_V1hS0W1oQ5W8'
|
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZtY2x0cmpudXZ1b29hcmt2dWZuIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzUxMzY3MDQsImV4cCI6MjA5MDcxMjcwNH0.PkSgBAZx41X4sZurfyOdxCVa01hkKTkyBhVkGzx_4y4'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data && data.length > 0) {
|
if (data && data.length > 0) {
|
||||||
const p = data[0];
|
const p = data[0];
|
||||||
let imgUrl = p.image_url || '';
|
let imgUrl = p.image || p.image_url || '';
|
||||||
if (p.images && p.images.length > 0) imgUrl = p.images[0];
|
if (p.images && p.images.length > 0) imgUrl = p.images[0];
|
||||||
return {
|
return {
|
||||||
title: p.name || 'Authentic Korean Skincare',
|
title: p.name || 'Authentic Korean Skincare',
|
||||||
@@ -324,11 +324,22 @@ async function resolveProductUrl(input) {
|
|||||||
|
|
||||||
function loadImage(src) {
|
function loadImage(src) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
let loadUrl = src;
|
||||||
|
if (src.startsWith('http://') || src.startsWith('https://')) {
|
||||||
|
loadUrl = 'https://images.weserv.nl/?url=' + encodeURIComponent(src) + '&output=jpg&q=95';
|
||||||
|
}
|
||||||
|
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.crossOrigin = 'anonymous';
|
img.crossOrigin = 'anonymous';
|
||||||
img.onload = () => resolve(img);
|
img.onload = () => resolve(img);
|
||||||
img.onerror = (e) => reject(new Error('Could not load image across CORS'));
|
img.onerror = () => {
|
||||||
img.src = src;
|
const fallbackImg = new Image();
|
||||||
|
fallbackImg.crossOrigin = 'anonymous';
|
||||||
|
fallbackImg.onload = () => resolve(fallbackImg);
|
||||||
|
fallbackImg.onerror = () => reject(new Error('Could not load image across CORS'));
|
||||||
|
fallbackImg.src = src;
|
||||||
|
};
|
||||||
|
img.src = loadUrl;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user