Validate image signatures, stream ad media with Range, keep live files in MinIO
- Uploaded images are checked by magic bytes; the key extension and stored Content-Type come from the detected format, not from the client's filename (an .html file sent as image/png was stored as <uuid>.html). - /api/v1/ads-media streams from MinIO instead of loading whole videos into the heap, answers Range requests with 206 (iOS Safari needs it for video) and sets a long public Cache-Control for immutable keys. - The bucket lifecycle rule expired every object after 180 days, including avatars and images of live posts; now only noncurrent versions expire. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,9 +3,12 @@ package com.krylov.refound.controller.advertising;
|
||||
import com.krylov.refound.service.advertising.AdvertisingMediaService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -23,9 +26,10 @@ public class AdvertisingMediaController {
|
||||
private final AdvertisingMediaService mediaService;
|
||||
|
||||
@GetMapping("/{*key}")
|
||||
public ResponseEntity<byte[]> getMedia(@PathVariable String key) {
|
||||
public ResponseEntity<Resource> getMedia(@PathVariable String key,
|
||||
@RequestHeader(value = HttpHeaders.RANGE, required = false) String range) {
|
||||
String mediaKey = key.startsWith("/") ? key.substring(1) : key;
|
||||
log.info("GET ads-media: key={} -> mediaKey={}", key, mediaKey);
|
||||
return mediaService.downloadMedia(mediaKey);
|
||||
log.debug("GET ads-media: key={} -> mediaKey={}, range={}", key, mediaKey, range);
|
||||
return mediaService.downloadMedia(mediaKey, range);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user