mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-03-28 17:43:05 +01:00
Always have Public channel available
This commit is contained in:
@@ -187,18 +187,21 @@ async def ensure_default_channels() -> None:
|
||||
"""
|
||||
Ensure default channels exist in the database.
|
||||
These will be configured on the radio when needed for sending.
|
||||
|
||||
The Public channel is protected - it always exists with the canonical name.
|
||||
"""
|
||||
# Public channel - no hashtag, specific key
|
||||
# Public channel - no hashtag, specific well-known key
|
||||
PUBLIC_CHANNEL_KEY_HEX = "8B3387E9C5CDEA6AC9E5EDBAA115CD72"
|
||||
|
||||
existing = await ChannelRepository.get_by_name("Public")
|
||||
if not existing:
|
||||
logger.info("Creating default Public channel")
|
||||
# Check by KEY (not name) since that's what's fixed
|
||||
existing = await ChannelRepository.get_by_key(PUBLIC_CHANNEL_KEY_HEX)
|
||||
if not existing or existing.name != "Public":
|
||||
logger.info("Ensuring default Public channel exists with correct name")
|
||||
await ChannelRepository.upsert(
|
||||
key=PUBLIC_CHANNEL_KEY_HEX,
|
||||
name="Public",
|
||||
is_hashtag=False,
|
||||
on_radio=False,
|
||||
on_radio=existing.on_radio if existing else False,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ from pydantic import BaseModel, Field
|
||||
|
||||
from app.dependencies import require_connected
|
||||
from app.models import Channel
|
||||
from app.radio_sync import ensure_default_channels
|
||||
from app.repository import ChannelRepository
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -24,6 +25,8 @@ class CreateChannelRequest(BaseModel):
|
||||
@router.get("", response_model=list[Channel])
|
||||
async def list_channels() -> list[Channel]:
|
||||
"""List all channels from the database."""
|
||||
# Ensure Public channel always exists (self-healing)
|
||||
await ensure_default_channels()
|
||||
return await ChannelRepository.get_all()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user