Files
TeleWave/frontend/src/features/streaming/api.ts
T
Leonid Pershin c4a94443f7
ci / build-backend (push) Successful in 1m47s
ci / build-frontend (push) Successful in 52s
ci / tests (push) Successful in 1m36s
ci / sonar (push) Successful in 4m26s
Add IPTV playlist functionality and enhance streaming endpoints
Implemented a new endpoint for downloading the IPTV playlist, allowing users to access a comprehensive M3U file containing all channels and program guides. Updated the StreamingEndpoints to support token validation for both cookie and query parameters, ensuring secure access for external IPTV players. Enhanced the AirPage component to include a download button for the IPTV playlist, with appropriate user feedback on success or failure. Updated localization strings to reflect new features and instructions for users.
2026-07-29 18:14:01 +03:00

48 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { apiDownload, apiRequest } from '@/shared/api/client'
import type { PublicChannelDto, PublicEpgEntryDto } from '@/shared/api/types'
/** Ссылка на изображение общего реестра (постеры/кадры) — по id из публичных DTO. */
export function imageUrl(imageId: string) {
return `/api/images/${imageId}`
}
export function listChannels() {
return apiRequest<PublicChannelDto[]>('/channels')
}
/** Что включено глобально на стороне зрителя (сейчас — переключение по номерам). */
export function getViewerFeatures() {
return apiRequest<{ channelNumbersEnabled: boolean }>('/channels/features')
}
/** Выдаёт httpOnly-cookie tw_stream — после этого <video> сможет грузить плейлист и сегменты. */
export function watchChannel(slug: string) {
return apiRequest<void>(`/channels/${slug}/watch`, { method: 'POST' })
}
/**
* Скачивает M3U для внешнего плеера. Ссылка на файл не годится: эндпоинт закрыт Bearer'ом, а
* `<a href>` заголовок не отправит — поэтому тянем через fetch и сохраняем как blob.
*/
export async function downloadIptvPlaylist() {
const { blob, fileName } = await apiDownload('/iptv/playlist.m3u', 'telewave.m3u')
const url = URL.createObjectURL(blob)
try {
const link = document.createElement('a')
link.href = url
link.download = fileName
link.click()
} finally {
URL.revokeObjectURL(url)
}
}
export function getEpg(slug: string, from?: Date, to?: Date) {
const query = new URLSearchParams()
if (from) query.set('from', from.toISOString())
if (to) query.set('to', to.toISOString())
const qs = query.toString()
const suffix = qs ? `?${qs}` : ''
return apiRequest<PublicEpgEntryDto[]>(`/channels/${slug}/epg${suffix}`)
}