feat(main): main
This commit is contained in:
@@ -17,6 +17,7 @@ class ChannelSchema(Schema):
|
||||
library_id: int
|
||||
owner_user_id: int
|
||||
fallback_collection_id: Optional[int] = None
|
||||
requires_auth: bool
|
||||
|
||||
class ChannelCreateSchema(Schema):
|
||||
name: str
|
||||
@@ -26,6 +27,7 @@ class ChannelCreateSchema(Schema):
|
||||
library_id: int
|
||||
owner_user_id: int # Mock Auth User
|
||||
fallback_collection_id: Optional[int] = None
|
||||
requires_auth: bool = False
|
||||
|
||||
class ChannelUpdateSchema(Schema):
|
||||
name: Optional[str] = None
|
||||
@@ -35,6 +37,7 @@ class ChannelUpdateSchema(Schema):
|
||||
visibility: Optional[str] = None
|
||||
is_active: Optional[bool] = None
|
||||
fallback_collection_id: Optional[int] = None
|
||||
requires_auth: Optional[bool] = None
|
||||
|
||||
class ChannelSourceRuleSchema(Schema):
|
||||
id: int
|
||||
@@ -135,6 +138,10 @@ class ChannelStatusSchema(Schema):
|
||||
@router.get("/{channel_id}/status", response=ChannelStatusSchema)
|
||||
def get_channel_status(request, channel_id: int):
|
||||
channel = get_object_or_404(Channel, id=channel_id)
|
||||
if channel.requires_auth and not request.user.is_authenticated:
|
||||
from ninja.errors import HttpError
|
||||
raise HttpError(401, "Authentication required for this channel.")
|
||||
|
||||
now = timezone.now()
|
||||
window_end = now + timedelta(hours=24)
|
||||
|
||||
@@ -196,7 +203,8 @@ def create_channel(request, payload: ChannelCreateSchema):
|
||||
slug=payload.slug,
|
||||
channel_number=payload.channel_number,
|
||||
description=payload.description,
|
||||
fallback_collection_id=payload.fallback_collection_id
|
||||
fallback_collection_id=payload.fallback_collection_id,
|
||||
requires_auth=payload.requires_auth
|
||||
)
|
||||
return 201, channel
|
||||
|
||||
@@ -260,6 +268,10 @@ def remove_source_from_channel(request, channel_id: int, rule_id: int):
|
||||
def channel_now_playing(request, channel_id: int):
|
||||
"""Return the Airing currently on-air for this channel, or null."""
|
||||
channel = get_object_or_404(Channel, id=channel_id)
|
||||
if channel.requires_auth and not request.user.is_authenticated:
|
||||
from ninja.errors import HttpError
|
||||
raise HttpError(401, "Authentication required for this channel.")
|
||||
|
||||
# Using a 1-second buffer to handle boundary conditions smoothly
|
||||
now = timezone.now()
|
||||
airing = (
|
||||
@@ -279,6 +291,10 @@ def channel_airings(request, channel_id: int, hours: int = 4):
|
||||
[now - 2 hours, now + {hours} hours]
|
||||
"""
|
||||
channel = get_object_or_404(Channel, id=channel_id)
|
||||
if channel.requires_auth and not request.user.is_authenticated:
|
||||
from ninja.errors import HttpError
|
||||
raise HttpError(401, "Authentication required for this channel.")
|
||||
|
||||
now = timezone.now()
|
||||
window_start = now - timedelta(hours=2) # Look back 2h for context
|
||||
window_end = now + timedelta(hours=hours)
|
||||
|
||||
Reference in New Issue
Block a user