itembox images et cache

This commit is contained in:
2024-05-09 18:39:06 +02:00
parent 83291c246b
commit 6602bfd408
11 changed files with 275 additions and 176 deletions

24
src/api/image-request.js Normal file
View File

@@ -0,0 +1,24 @@
const API_KEY = 'AIzaSyA_w7wmOAibpiDF5H3mXuL9AhcN-KVkFg4';
const CSE_ID = '611cd62b5f315445c';
export async function searchAndResizeImage(query) {
try {
const response = await fetch(`https://www.googleapis.com/customsearch/v1?key=${API_KEY}&cx=${CSE_ID}&q=${query}&searchType=image&num=1&imgSize=medium`);
const data = await response.json();
if (data.items && data.items.length > 0) {
const imageUrl = data.items[0].link;
console.log('Image URL:', imageUrl);
return imageUrl;
} else {
console.error('No image found.');
return "";
}
} catch (error) {
console.error('Error fetching image:', error);
return "";
}
}