feat(main): commit

This commit is contained in:
2026-03-08 16:48:58 -04:00
parent 567766eaed
commit f37382d2b8
29 changed files with 3735 additions and 223 deletions

View File

@@ -1,24 +1,63 @@
import axios from 'axios';
// The base URL relies on the Vite proxy in development,
// and same-origin in production.
const apiClient = axios.create({
baseURL: '/api',
headers: {
'Content-Type': 'application/json',
},
headers: { 'Content-Type': 'application/json' },
});
export const fetchChannels = async () => {
const response = await apiClient.get('/channel/');
return response.data;
// ── 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}`);
};
// If a channel is selected, we can load its upcoming airings
export const fetchScheduleGenerations = async (channelId) => {
// We can trigger an immediate generation for the day to ensure there's data
const response = await apiClient.post(`/schedule/generate/${channelId}`);
return response.data;
};
// ── 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;
// Future logic can query specific lists of Airings here...
// 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;
};
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;
// ── 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}`); };