Files
PYTV/frontend/src/api.js

64 lines
4.1 KiB
JavaScript
Raw Normal View History

2026-03-08 11:28:59 -04:00
import axios from 'axios';
const apiClient = axios.create({
baseURL: '/api',
2026-03-08 16:48:58 -04:00
headers: { 'Content-Type': 'application/json' },
2026-03-08 11:28:59 -04:00
});
2026-03-08 16:48:58 -04:00
// ── Channels ──────────────────────────────────────────────────────────────
export const fetchChannels = async () => (await apiClient.get('/channel/')).data;
export const createChannel = async (payload) => (await apiClient.post('/channel/', payload)).data;
export const updateChannel = async (id, payload) => (await apiClient.patch(`/channel/${id}`, payload)).data;
export const deleteChannel = async (id) => { await apiClient.delete(`/channel/${id}`); };
// Channel program data
export const fetchChannelNow = async (channelId) =>
(await apiClient.get(`/channel/${channelId}/now`)).data;
export const fetchChannelAirings = async (channelId, hours = 4) =>
(await apiClient.get(`/channel/${channelId}/airings?hours=${hours}`)).data;
// Channel ↔ Source assignments
export const fetchChannelSources = async (channelId) =>
(await apiClient.get(`/channel/${channelId}/sources`)).data;
export const assignSourceToChannel = async (channelId, payload) =>
(await apiClient.post(`/channel/${channelId}/sources`, payload)).data;
export const removeSourceFromChannel = async (channelId, ruleId) => {
await apiClient.delete(`/channel/${channelId}/sources/${ruleId}`);
2026-03-08 11:28:59 -04:00
};
2026-03-08 16:48:58 -04:00
// ── Schedule ──────────────────────────────────────────────────────────────
export const fetchTemplates = async () => (await apiClient.get('/schedule/template/')).data;
export const createTemplate = async (payload) =>
(await apiClient.post('/schedule/template/', payload)).data;
export const deleteTemplate = async (id) => { await apiClient.delete(`/schedule/template/${id}`); };
export const generateScheduleToday = async (channelId) =>
(await apiClient.post(`/schedule/generate-today/${channelId}`)).data;
// Legacy used by guide
export const fetchScheduleGenerations = async (channelId) =>
(await apiClient.post(`/schedule/generate/${channelId}`)).data;
// ── Media Sources (YouTube / local) ───────────────────────────────────────
export const fetchSources = async () => (await apiClient.get('/sources/')).data;
export const createSource = async (payload) => (await apiClient.post('/sources/', payload)).data;
export const syncSource = async (sourceId, maxVideos) => {
const url = maxVideos ? `/sources/${sourceId}/sync?max_videos=${maxVideos}` : `/sources/${sourceId}/sync`;
return (await apiClient.post(url)).data;
2026-03-08 11:28:59 -04:00
};
2026-03-08 16:48:58 -04:00
export const deleteSource = async (sourceId) => { await apiClient.delete(`/sources/${sourceId}`); };
// Download controls
export const fetchDownloadStatus = async () => (await apiClient.get('/sources/download-status')).data;
export const triggerCacheUpcoming = async (hours = 24, pruneOnly = false) =>
(await apiClient.post(`/sources/cache-upcoming?hours=${hours}&prune_only=${pruneOnly}`)).data;
export const downloadItem = async (itemId) => (await apiClient.post(`/sources/${itemId}/download`)).data;
// ── Libraries ─────────────────────────────────────────────────────────────
export const fetchLibraries = async () => (await apiClient.get('/library/')).data;
2026-03-08 11:28:59 -04:00
2026-03-08 16:48:58 -04:00
// ── Users ─────────────────────────────────────────────────────────────────
export const fetchUsers = async () => (await apiClient.get('/user/')).data;
export const createUser = async (payload) => (await apiClient.post('/user/', payload)).data;
export const updateUser = async (id, payload) => (await apiClient.patch(`/user/${id}`, payload)).data;
export const deleteUser = async (id) => { await apiClient.delete(`/user/${id}`); };