fix google pse

i tested everything, also tested if invalid api key and such and regression tested searxng which still works
This commit is contained in:
HadiCherkaoui 2025-02-28 09:13:11 +01:00
parent 4d41243108
commit 7a816efc04
4 changed files with 29 additions and 39 deletions

View file

@ -63,11 +63,22 @@ export const searchGooglePSE = async (query: string) => {
title: item.title,
url: item.link,
content: item.snippet,
img_src: item.pagemap?.cse_image?.[0]?.src,
img_src: item.pagemap?.cse_image?.[0]?.src
|| item.pagemap?.cse_thumbnail?.[0]?.src
|| item.image?.thumbnailLink,
...(item.pagemap?.videoobject?.[0] && {
videoData: {
duration: item.pagemap.videoobject[0].duration,
embedUrl: item.pagemap.videoobject[0].embedurl
}
})
}));
return { results, originalres };
} catch (error) {
throw new Error('Google PSE Error:', error.response?.data || error.message);
const errorMessage = error.response?.data
? JSON.stringify(error.response.data, null, 2)
: error.message || 'Unknown error';
throw new Error(`Google PSE Error: ${errorMessage}`);
}
};