fix(notification+vlog upload)
This commit is contained in:
@@ -13,6 +13,7 @@ from schemas.vlog import VlogCreate, VlogUpdate, VlogResponse, VlogCommentCreate
|
||||
from utils.security import get_current_active_user
|
||||
from utils.video_utils import generate_video_thumbnail, get_video_duration
|
||||
from utils.settings_service import SettingsService
|
||||
from utils.push_service import send_push_to_user
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -254,12 +255,15 @@ async def upload_vlog_video(
|
||||
"""Upload a vlog video."""
|
||||
# Validate video file
|
||||
if not SettingsService.is_file_type_allowed(db, video.content_type or "unknown"):
|
||||
allowed_types = SettingsService.get_setting(db, "allowed_video_types",
|
||||
["video/mp4", "video/mpeg", "video/quicktime", "video/webm"])
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"Invalid video type. Allowed types: {', '.join(allowed_types)}"
|
||||
)
|
||||
# Fallback check for common video types if content_type is generic application/octet-stream
|
||||
filename = video.filename.lower()
|
||||
if not (filename.endswith('.mp4') or filename.endswith('.mov') or filename.endswith('.webm') or filename.endswith('.mkv')):
|
||||
allowed_types = SettingsService.get_setting(db, "allowed_video_types",
|
||||
["video/mp4", "video/mpeg", "video/quicktime", "video/webm"])
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"Invalid video type. Allowed types: {', '.join(allowed_types)}"
|
||||
)
|
||||
|
||||
# Check file size
|
||||
video_content = await video.read()
|
||||
@@ -335,17 +339,24 @@ async def upload_vlog_video(
|
||||
|
||||
# Create notifications for all active users (except the creator)
|
||||
users = db.query(User).filter(User.is_active == True).all()
|
||||
notif_title = "Nouveau vlog"
|
||||
notif_message = f"{current_user.full_name} a publié un nouveau vlog : {vlog.title}"
|
||||
notif_link = f"/vlogs/{vlog.id}"
|
||||
|
||||
for user in users:
|
||||
if user.id != current_user.id:
|
||||
notification = Notification(
|
||||
user_id=user.id,
|
||||
type=NotificationType.NEW_VLOG,
|
||||
title="Nouveau vlog",
|
||||
message=f"{current_user.full_name} a publié un nouveau vlog : {vlog.title}",
|
||||
link=f"/vlogs/{vlog.id}",
|
||||
title=notif_title,
|
||||
message=notif_message,
|
||||
link=notif_link,
|
||||
is_read=False
|
||||
)
|
||||
db.add(notification)
|
||||
|
||||
# Envoyer la notification push
|
||||
send_push_to_user(db, user.id, notif_title, notif_message, notif_link)
|
||||
|
||||
db.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user