canina/frontend/application/lib/services/videoService.ts
parsa aghaei bea0488efb
All checks were successful
Deploy Canina / deploy (push) Successful in 1m49s
fix(admin): enhance media manager with all file types and progress, fix videos sync and home display
2026-08-17 15:18:34 +03:30

49 lines
1.2 KiB
TypeScript

import api from './api';
export interface Video {
id: string;
title: string;
doctor: string;
duration: string;
thumbnail: string;
videoUrl: string;
description: string;
viewsCount?: number;
isFeatured?: boolean;
}
export const videoService = {
getVideos: async (params?: { featured?: boolean; limit?: number; search?: string }) => {
try {
const res = await api.get('/videos', { params });
const raw = res.data;
if (Array.isArray(raw?.videos)) return raw.videos;
if (Array.isArray(raw?.data?.videos)) return raw.data.videos;
if (Array.isArray(raw?.data)) return raw.data;
if (Array.isArray(raw)) return raw;
return [];
} catch (error) {
console.error('Failed to fetch videos from API:', error);
return [];
}
},
getVideoById: async (id: string) => {
try {
const res = await api.get(`/videos/${id}`);
return res.data;
} catch (error) {
console.error('Failed to fetch video details:', error);
return null;
}
},
incrementViews: async (id: string) => {
try {
await api.patch(`/videos/${id}/view`);
} catch (error) {
console.warn('Failed to increment video views:', error);
}
}
};