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.
This commit is contained in:
@@ -21,11 +21,24 @@ public sealed class StreamTokenService(
|
||||
private readonly TimeSpan _ttl = TimeSpan.FromMinutes(
|
||||
Math.Max(1, streamingOptions.Value.StreamTokenMinutes)
|
||||
);
|
||||
private readonly TimeSpan _iptvTtl = TimeSpan.FromDays(
|
||||
Math.Max(1, streamingOptions.Value.IptvTokenDays)
|
||||
);
|
||||
private readonly byte[] _key = Encoding.UTF8.GetBytes(jwtOptions.Value.SigningKey);
|
||||
|
||||
public (string Token, DateTimeOffset ExpiresAt) Issue(Guid userId)
|
||||
public (string Token, DateTimeOffset ExpiresAt) Issue(Guid userId) => Issue(userId, _ttl);
|
||||
|
||||
/// <summary>
|
||||
/// Долгий токен для IPTV-плейлиста. Отдельного вида у него нет намеренно: он попадает в те же
|
||||
/// ссылки на плейлист и сегменты, что и cookie, и проверяется тем же <see cref="Validate"/>.
|
||||
/// Отличается только сроком — внешний плеер перевыпустить пропуск не может.
|
||||
/// </summary>
|
||||
public (string Token, DateTimeOffset ExpiresAt) IssueForIptv(Guid userId) =>
|
||||
Issue(userId, _iptvTtl);
|
||||
|
||||
private (string Token, DateTimeOffset ExpiresAt) Issue(Guid userId, TimeSpan ttl)
|
||||
{
|
||||
var expiresAt = DateTimeOffset.UtcNow.Add(_ttl);
|
||||
var expiresAt = DateTimeOffset.UtcNow.Add(ttl);
|
||||
var payload = $"{userId:N}.{expiresAt.ToUnixTimeSeconds()}";
|
||||
var token = $"{Base64Url(Encoding.UTF8.GetBytes(payload))}.{Base64Url(Sign(payload))}";
|
||||
return (token, expiresAt);
|
||||
|
||||
Reference in New Issue
Block a user