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
This commit is contained in:
parent
78b5327e59
commit
756a77ca57
@ -57,19 +57,19 @@ export default function BunnyAdminPage() {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
// Fetch videos from Bunny.net
|
// Fetch videos from Bunny.net
|
||||||
const { data: videosData, isLoading } = useQuery<{ videos: Video[], total: number }>({
|
const { data: videosData, isLoading } = useQuery({
|
||||||
queryKey: ['/api/videos', searchTerm],
|
queryKey: ['/api/videos', searchTerm],
|
||||||
queryFn: () => apiRequest('GET', `/api/videos?search=${searchTerm}&limit=100`),
|
queryFn: () => apiRequest('GET', `/api/videos?search=${searchTerm}&limit=100`),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch Bunny.net statistics
|
// Fetch Bunny.net statistics
|
||||||
const { data: statsData } = useQuery<BunnyStats>({
|
const { data: statsData } = useQuery({
|
||||||
queryKey: ['/api/bunny/stats'],
|
queryKey: ['/api/bunny/stats'],
|
||||||
queryFn: () => apiRequest('GET', '/api/bunny/stats'),
|
queryFn: () => apiRequest('GET', '/api/bunny/stats'),
|
||||||
});
|
});
|
||||||
|
|
||||||
const videos: Video[] = videosData?.videos || [];
|
const videos: Video[] = (videosData as any)?.videos || [];
|
||||||
const stats: BunnyStats = statsData || {
|
const stats: BunnyStats = (statsData as any) || {
|
||||||
totalVideos: videos.length,
|
totalVideos: videos.length,
|
||||||
totalViews: videos.reduce((sum: number, v: Video) => sum + v.views, 0),
|
totalViews: videos.reduce((sum: number, v: Video) => sum + v.views, 0),
|
||||||
totalStorage: 0,
|
totalStorage: 0,
|
||||||
|
|||||||
@ -132,8 +132,9 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
// Bunny.net administration routes
|
// Bunny.net administration routes
|
||||||
app.get("/api/bunny/stats", async (req, res) => {
|
app.get("/api/bunny/stats", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { videos } = await storage.getVideos(1, 1000);
|
const result = await storage.getVideos(1, 1000);
|
||||||
const totalViews = videos.reduce((sum, video) => sum + video.views, 0);
|
const videos = result?.videos || [];
|
||||||
|
const totalViews = videos.length > 0 ? videos.reduce((sum, video) => sum + video.views, 0) : 0;
|
||||||
|
|
||||||
const stats = {
|
const stats = {
|
||||||
totalVideos: videos.length,
|
totalVideos: videos.length,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user