fix(video-player): fix the video player to permit the nagivation through the video (it was because de fast api server refused range request)
Some checks failed
Deploy to Development / build-and-deploy (push) Failing after 2m15s
Some checks failed
Deploy to Development / build-and-deploy (push) Failing after 2m15s
This commit is contained in:
@@ -1,49 +1,53 @@
|
||||
import os
|
||||
from typing import Any, Dict, List
|
||||
from sqlalchemy.orm import Session
|
||||
from models.settings import SystemSettings
|
||||
from typing import Optional, Dict, Any
|
||||
import json
|
||||
|
||||
class SettingsService:
|
||||
"""Service for managing system settings."""
|
||||
|
||||
@staticmethod
|
||||
def get_setting(db: Session, key: str, default: Any = None) -> Any:
|
||||
"""Get a setting value by key."""
|
||||
"""Get a setting value by key, return default if not found."""
|
||||
setting = db.query(SystemSettings).filter(SystemSettings.key == key).first()
|
||||
if not setting:
|
||||
return default
|
||||
|
||||
# Essayer de convertir en type approprié
|
||||
value = setting.value
|
||||
|
||||
# Booléens
|
||||
if value.lower() in ['true', 'false']:
|
||||
return value.lower() == 'true'
|
||||
|
||||
# Nombres entiers
|
||||
try:
|
||||
return int(value)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# Nombres flottants
|
||||
try:
|
||||
return float(value)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# JSON
|
||||
if value.startswith('{') or value.startswith('['):
|
||||
|
||||
# Convert value based on expected type (basic handling)
|
||||
if isinstance(default, int):
|
||||
try:
|
||||
return json.loads(value)
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
return int(setting.value)
|
||||
except ValueError:
|
||||
return default
|
||||
elif isinstance(default, bool):
|
||||
return setting.value.lower() == "true"
|
||||
elif isinstance(default, list):
|
||||
return setting.value.split(",")
|
||||
|
||||
return setting.value
|
||||
|
||||
@staticmethod
|
||||
def set_setting(db: Session, key: str, value: str, description: str = None, category: str = "general") -> SystemSettings:
|
||||
"""Set a setting value."""
|
||||
setting = db.query(SystemSettings).filter(SystemSettings.key == key).first()
|
||||
if setting:
|
||||
setting.value = str(value)
|
||||
if description:
|
||||
setting.description = description
|
||||
if category:
|
||||
setting.category = category
|
||||
else:
|
||||
setting = SystemSettings(
|
||||
key=key,
|
||||
value=str(value),
|
||||
description=description,
|
||||
category=category
|
||||
)
|
||||
db.add(setting)
|
||||
|
||||
# Liste séparée par des virgules
|
||||
if ',' in value and not value.startswith('{') and not value.startswith('['):
|
||||
return [item.strip() for item in value.split(',')]
|
||||
|
||||
return value
|
||||
db.commit()
|
||||
db.refresh(setting)
|
||||
return setting
|
||||
|
||||
@staticmethod
|
||||
def get_upload_limits(db: Session) -> Dict[str, Any]:
|
||||
@@ -60,7 +64,7 @@ class SettingsService:
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def get_max_upload_size(db: Session, content_type: str) -> int:
|
||||
def get_max_upload_size(db: Session, content_type: str, is_vlog: bool = False) -> int:
|
||||
"""Get max upload size for a specific content type."""
|
||||
if content_type.startswith('image/'):
|
||||
max_size_mb = SettingsService.get_setting(db, "max_image_size_mb", 10)
|
||||
@@ -68,9 +72,14 @@ class SettingsService:
|
||||
print(f"DEBUG - Image upload limit: {max_size_mb}MB = {max_size_bytes} bytes")
|
||||
return max_size_bytes
|
||||
elif content_type.startswith('video/'):
|
||||
max_size_mb = SettingsService.get_setting(db, "max_video_size_mb", 100)
|
||||
if is_vlog:
|
||||
max_size_mb = SettingsService.get_setting(db, "max_vlog_size_mb", 500)
|
||||
print(f"DEBUG - Vlog upload limit: {max_size_mb}MB")
|
||||
else:
|
||||
max_size_mb = SettingsService.get_setting(db, "max_video_size_mb", 100)
|
||||
print(f"DEBUG - Video upload limit: {max_size_mb}MB")
|
||||
|
||||
max_size_bytes = max_size_mb * 1024 * 1024
|
||||
print(f"DEBUG - Video upload limit: {max_size_mb}MB = {max_size_bytes} bytes")
|
||||
return max_size_bytes
|
||||
else:
|
||||
default_size = 10 * 1024 * 1024 # 10MB par défaut
|
||||
@@ -79,14 +88,17 @@ class SettingsService:
|
||||
|
||||
@staticmethod
|
||||
def is_file_type_allowed(db: Session, content_type: str) -> bool:
|
||||
"""Check if a file type is allowed."""
|
||||
"""Check if file type is allowed."""
|
||||
if content_type.startswith('image/'):
|
||||
allowed_types = SettingsService.get_setting(db, "allowed_image_types",
|
||||
allowed = SettingsService.get_setting(db, "allowed_image_types",
|
||||
["image/jpeg", "image/png", "image/gif", "image/webp"])
|
||||
if isinstance(allowed, str):
|
||||
allowed = allowed.split(",")
|
||||
return content_type in allowed
|
||||
elif content_type.startswith('video/'):
|
||||
allowed_types = SettingsService.get_setting(db, "allowed_video_types",
|
||||
allowed = SettingsService.get_setting(db, "allowed_video_types",
|
||||
["video/mp4", "video/mpeg", "video/quicktime", "video/webm"])
|
||||
else:
|
||||
return False
|
||||
|
||||
return content_type in allowed_types
|
||||
if isinstance(allowed, str):
|
||||
allowed = allowed.split(",")
|
||||
return content_type in allowed
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user