Improve search functionality to include videos and articles

Update the search endpoint to use the Bunny.net API's search parameter for more efficient video retrieval, and ensure caching for search results.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: ef13086e-ac61-4b8e-994b-83beeef8c3df
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/517dfa7b-26ac-463d-a6e1-a58c6df97188/jdAEdU5
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
sebastjanartic 2026-03-04 09:03:18 +00:00
parent 2be8b0b0d7
commit ff34633ea6
2 changed files with 542 additions and 552 deletions

File diff suppressed because it is too large Load Diff

View File

@ -103,30 +103,20 @@ export async function registerRoutes(
a.category.toLowerCase().includes(q)
).slice(0, 10);
const cacheKey = `videos_1_100_`;
let videos: any[] = [];
const cached = getCached<any>(cacheKey, 30 * 60 * 1000);
if (cached) {
videos = cached.items || [];
} else {
try {
const data = await bunnyFetch(`/library/${LIBRARY_ID}/videos?page=1&itemsPerPage=100&orderBy=date`);
videos = (data.items || []).map((v: any) => {
const descTag = (v.metaTags || []).find((t: any) => t.property === "description");
return {
guid: v.guid,
title: (v.title || "").replace(/\.mp4$/i, ""),
description: descTag?.value || v.description || "",
thumbnail: `https://${CDN_HOST}/${v.guid}/${v.thumbnailFileName || "thumbnail.jpg"}`,
embedUrl: `https://player.mediadelivery.net/embed/${LIBRARY_ID}/${v.guid}`,
};
});
} catch {}
}
const matchedVideos = videos.filter((v: any) =>
v.title.toLowerCase().includes(q) ||
(v.description || "").toLowerCase().includes(q)
).slice(0, 10);
let matchedVideos: any[] = [];
try {
const data = await bunnyFetch(`/library/${LIBRARY_ID}/videos?page=1&itemsPerPage=20&search=${encodeURIComponent(q)}`);
matchedVideos = (data.items || []).map((v: any) => {
const descTag = (v.metaTags || []).find((t: any) => t.property === "description");
return {
guid: v.guid,
title: (v.title || "").replace(/\.mp4$/i, ""),
description: descTag?.value || v.description || "",
thumbnail: `https://${CDN_HOST}/${v.guid}/${v.thumbnailFileName || "thumbnail.jpg"}`,
embedUrl: `https://player.mediadelivery.net/embed/${LIBRARY_ID}/${v.guid}`,
};
}).slice(0, 10);
} catch {}
res.json({ articles: matchedArticles, videos: matchedVideos });
} catch (err: any) {