Add video attachments to chat messages

- browser uploads the source straight to MinIO via presigned PUT (type and
  exact size are signed, up to 100 MB); upload is confirmed once by its owner
- message is created with a PROCESSING video, transcoded in the background
  (chatVideoExecutor): H.264/AAC, short side up to 720px, faststart,
  metadata (incl. location) stripped, poster frame; up to 60 s
- the updated message is re-broadcast over WebSocket when READY or FAILED;
  stuck processing is failed after 30 min
- message_attachments: status, poster_key, duration_ms, processing_started_at
- chat deletion and orphan cleanup handle video posters; rate limit chat-video

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-28 23:00:11 +03:00
parent 648886c25e
commit 871b16a038
25 changed files with 1151 additions and 52 deletions

View File

@@ -1,12 +1,15 @@
package com.krylov.refound.controller;
import com.krylov.refound.dto.ChatDto;
import com.krylov.refound.dto.MessageAttachmentDto;
import com.krylov.refound.dto.MessageDto;
import com.krylov.refound.dto.SendVideoRequest;
import com.krylov.refound.dto.StartChatRequest;
import com.krylov.refound.dto.VideoUploadRequest;
import com.krylov.refound.service.ChatService;
import com.krylov.refound.service.ChatVideoUploadService;
import com.krylov.refound.service.UserService;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
@@ -82,11 +85,37 @@ public class ChatController {
return chatService.sendMessageWithPhotos(currentUserId, chatId, content, files);
}
/** Свежая временная ссылка на вложение (выданная с сообщением живёт несколько часов). */
/**
* Свежие временные ссылки на вложение (выданные с сообщением живут несколько
* часов): url и, у видео, posterUrl.
*/
@GetMapping("/{chatId}/attachments/{attachmentId}/url")
public Map<String, String> getAttachmentUrl(@PathVariable Long chatId, @PathVariable Long attachmentId, Authentication auth) {
public MessageAttachmentDto getAttachmentUrl(@PathVariable Long chatId, @PathVariable Long attachmentId, Authentication auth) {
Long currentUserId = extractUserId(auth);
return Map.of("url", chatService.getAttachmentUrl(chatId, attachmentId, currentUserId));
return chatService.getAttachment(chatId, attachmentId, currentUserId);
}
/**
* Видео, шаг 1: ссылка для загрузки исходника прямо в MinIO (PUT с тем же
* Content-Type и размером, что указаны в запросе).
*/
@PostMapping("/{chatId}/videos/upload-url")
public ChatVideoUploadService.UploadTicket requestVideoUpload(@PathVariable Long chatId,
@RequestBody VideoUploadRequest request, Authentication auth) {
Long currentUserId = extractUserId(auth);
log.info("requestVideoUpload chatId {} by user {}, {} bytes", chatId, currentUserId, request.sizeBytes());
return chatService.requestVideoUpload(currentUserId, chatId, request.contentType(), request.sizeBytes());
}
/**
* Видео, шаг 2: исходник загружен — создаётся сообщение с видео в обработке.
* Готовое видео придёт по /topic/chat/{chatId} тем же сообщением (тот же id).
*/
@PostMapping("/{chatId}/videos")
public MessageDto sendVideoMessage(@PathVariable Long chatId, @RequestBody SendVideoRequest request, Authentication auth) {
Long currentUserId = extractUserId(auth);
log.info("sendVideoMessage chatId {} by user {}", chatId, currentUserId);
return chatService.sendVideoMessage(currentUserId, chatId, request.content(), request.sourceKey());
}
@DeleteMapping("/{chatId}")