From 756a77ca57a75cdad55a1ac02b7ba2d81b62508b Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Fri, 8 Aug 2025 21:12:18 +0000 Subject: [PATCH] Display video counts and total views from Bunny CDN in admin Update client-side query to fetch Bunny.net stats and video data, and adjust server-side logic in routes.ts to correctly aggregate total video views and counts from storage. Replit-Commit-Author: Agent Replit-Commit-Session-Id: d7424866-83d1-4486-a212-ac12b4c7becf Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/d7424866-83d1-4486-a212-ac12b4c7becf/aPgXP9Q --- client/src/pages/BunnyAdminPage.tsx | 8 ++++---- server/routes.ts | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/client/src/pages/BunnyAdminPage.tsx b/client/src/pages/BunnyAdminPage.tsx index 568b50e..799a6f5 100644 --- a/client/src/pages/BunnyAdminPage.tsx +++ b/client/src/pages/BunnyAdminPage.tsx @@ -57,19 +57,19 @@ export default function BunnyAdminPage() { const queryClient = useQueryClient(); // Fetch videos from Bunny.net - const { data: videosData, isLoading } = useQuery<{ videos: Video[], total: number }>({ + const { data: videosData, isLoading } = useQuery({ queryKey: ['/api/videos', searchTerm], queryFn: () => apiRequest('GET', `/api/videos?search=${searchTerm}&limit=100`), }); // Fetch Bunny.net statistics - const { data: statsData } = useQuery({ + const { data: statsData } = useQuery({ queryKey: ['/api/bunny/stats'], queryFn: () => apiRequest('GET', '/api/bunny/stats'), }); - const videos: Video[] = videosData?.videos || []; - const stats: BunnyStats = statsData || { + const videos: Video[] = (videosData as any)?.videos || []; + const stats: BunnyStats = (statsData as any) || { totalVideos: videos.length, totalViews: videos.reduce((sum: number, v: Video) => sum + v.views, 0), totalStorage: 0, diff --git a/server/routes.ts b/server/routes.ts index a4673fe..3cf85bb 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -132,8 +132,9 @@ export async function registerRoutes(app: Express): Promise { // Bunny.net administration routes app.get("/api/bunny/stats", async (req, res) => { try { - const { videos } = await storage.getVideos(1, 1000); - const totalViews = videos.reduce((sum, video) => sum + video.views, 0); + const result = await storage.getVideos(1, 1000); + const videos = result?.videos || []; + const totalViews = videos.length > 0 ? videos.reduce((sum, video) => sum + video.views, 0) : 0; const stats = { totalVideos: videos.length,