2af04e1db3
- Content model: add url column + is_weblink() for web page content items - Player model: add deployment tracking fields (status, timestamps, message) - Content blueprint: add add_weblink and add_weblink_to_playlist routes; weblinks auto-deleted when removed from playlist - Players blueprint: add SSH deploy mode in add_player; weblink-aware playlist - API blueprint: weblink URL served directly in playlist response; add /api/deploy/test-ssh and /api/deploy/player endpoints - Admin blueprint: add build-player page (clone from Gitea, write base config); replace nginx status card with Caddy status on HTTPS config page - caddy_manager: rewritten to generate proper HTTPS/internal-CA Caddyfiles and reload Caddy via admin API (/load) for live config updates - ssh_deploy, background_tasks, player_build: new utils for SSH deployment - background_tasks: push Flask app context into background thread so DB updates after deployment complete correctly - ssh_deploy: robust install script detection with passwordless sudo injection (uses SSH credentials, cleaned up after install) - Dockerfile: add git, sshpass, openssh-client, rsync - docker-compose: switch nginx to Caddy on ports 80/443; add port 5000 for dev - Templates: add_player deploy mode UI, weblink form in playlist/upload pages, build_player admin page, Caddy status on HTTPS config page - Migrations: add_url_to_content, add_deployment_fields_to_player - app.py: call db.create_all() on startup for schema bootstrap - config.py: add PLAYER_CODE_DIR and PLAYER_REPO_URL settings
71 lines
2.6 KiB
Python
71 lines
2.6 KiB
Python
"""Content model for media files."""
|
|
from datetime import datetime
|
|
from typing import Optional, List
|
|
|
|
from app.extensions import db
|
|
|
|
|
|
class Content(db.Model):
|
|
"""Content model representing media files for display.
|
|
|
|
Attributes:
|
|
id: Primary key
|
|
filename: Original filename
|
|
content_type: Type of content (image, video, pdf, presentation, other)
|
|
duration: Default display duration in seconds
|
|
file_size: File size in bytes
|
|
description: Optional content description
|
|
uploaded_at: Upload timestamp
|
|
"""
|
|
__tablename__ = 'content'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
filename = db.Column(db.String(255), nullable=False, unique=True, index=True)
|
|
content_type = db.Column(db.String(50), nullable=False, index=True)
|
|
duration = db.Column(db.Integer, default=10, nullable=True)
|
|
file_size = db.Column(db.BigInteger, nullable=True)
|
|
# For 'weblink' content this holds the web page URL to display on the player.
|
|
# NULL for file-based content (image/video/pdf).
|
|
url = db.Column(db.String(2048), nullable=True)
|
|
description = db.Column(db.Text, nullable=True)
|
|
uploaded_at = db.Column(db.DateTime, default=datetime.utcnow,
|
|
nullable=False, index=True)
|
|
|
|
# Relationships - many-to-many with playlists
|
|
playlists = db.relationship('Playlist', secondary='playlist_content',
|
|
back_populates='contents', lazy='dynamic')
|
|
groups = db.relationship('Group', secondary='group_content',
|
|
back_populates='contents', lazy='dynamic')
|
|
|
|
def __repr__(self) -> str:
|
|
"""String representation of Content."""
|
|
return f'<Content {self.filename} (Type={self.content_type})>'
|
|
|
|
@property
|
|
def file_size_mb(self) -> float:
|
|
"""Get file size in megabytes."""
|
|
if self.file_size:
|
|
return round(self.file_size / (1024 * 1024), 2)
|
|
return 0.0
|
|
|
|
@property
|
|
def group_count(self) -> int:
|
|
"""Get number of groups containing this content."""
|
|
return self.groups.count()
|
|
|
|
def is_image(self) -> bool:
|
|
"""Check if content is an image."""
|
|
return self.content_type == 'image'
|
|
|
|
def is_video(self) -> bool:
|
|
"""Check if content is a video."""
|
|
return self.content_type == 'video'
|
|
|
|
def is_pdf(self) -> bool:
|
|
"""Check if content is a PDF."""
|
|
return self.content_type == 'pdf'
|
|
|
|
def is_weblink(self) -> bool:
|
|
"""Check if content is a web link (URL) rather than an uploaded file."""
|
|
return self.content_type == 'weblink'
|