mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-08-13 19:28:40 +00:00
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:
@ -45,22 +45,14 @@ async function performImageSearch(query: string) {
|
||||
switch (searchEngine) {
|
||||
case 'google': {
|
||||
const googleResult = await searchGooglePSE(query);
|
||||
images = googleResult.originalres
|
||||
.map((result) => {
|
||||
// Extract image URL from multiple possible locations in Google's response
|
||||
const imageSrc = result.pagemap?.cse_image?.[0]?.src ||
|
||||
result.pagemap?.cse_thumbnail?.[0]?.src ||
|
||||
result.image?.thumbnailLink;
|
||||
|
||||
if (imageSrc && result.link && result.title) {
|
||||
images.push({
|
||||
img_src: imageSrc,
|
||||
url: result.link,
|
||||
images = googleResult.results.map((result) => {
|
||||
if (result.img_src && result.url && result.title) {
|
||||
return {
|
||||
img_src: result.img_src,
|
||||
url: result.url,
|
||||
title: result.title,
|
||||
// Add additional metadata if needed
|
||||
source: result.displayLink,
|
||||
fileFormat: result.fileFormat,
|
||||
});
|
||||
source: result.displayLink
|
||||
};
|
||||
}
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
@ -40,12 +40,6 @@ type VideoSearchChainInput = {
|
||||
|
||||
const strParser = new StringOutputParser();
|
||||
|
||||
function extractYouTubeVideoId(url: string): string | null {
|
||||
const regex = /(?:v=|\/embed\/|\.be\/)([a-zA-Z0-9_-]{11})/;
|
||||
const match = url.match(regex);
|
||||
return match ? match[1] : null;
|
||||
}
|
||||
|
||||
async function performVideoSearch(query: string) {
|
||||
const searchEngine = getSearchEngineBackend();
|
||||
const youtubeQuery = `${query} site:youtube.com`;
|
||||
@ -54,20 +48,14 @@ async function performVideoSearch(query: string) {
|
||||
switch (searchEngine) {
|
||||
case 'google': {
|
||||
const googleResult = await searchGooglePSE(youtubeQuery);
|
||||
googleResult.originalres.results.forEach((result) => {
|
||||
// Extract video metadata from Google PSE results
|
||||
const thumbnail = result.pagemap?.cse_thumbnail?.[0]?.src
|
||||
|| result.pagemap?.videoobject?.[0]?.thumbnailurl;
|
||||
|
||||
if (thumbnail && result.link && result.title) {
|
||||
googleResult.results.forEach((result) => { // Use .results instead of .originalres
|
||||
if (result.img_src && result.url && result.title) {
|
||||
const videoId = new URL(result.url).searchParams.get('v');
|
||||
videos.push({
|
||||
img_src: thumbnail,
|
||||
url: result.link,
|
||||
img_src: result.img_src,
|
||||
url: result.url,
|
||||
title: result.title,
|
||||
// Construct iframe URL from YouTube video ID
|
||||
iframe_src: result.link.includes('youtube.com/watch?v=')
|
||||
? `https://www.youtube.com/embed/${result.link.split('v=')[1].split('&')[0]}`
|
||||
: null,
|
||||
iframe_src: videoId ? `https://www.youtube.com/embed/${videoId}` : null
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user