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.
48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
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}`)
|
||
}
|