- 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>
35 lines
1.5 KiB
Java
35 lines
1.5 KiB
Java
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;
|
|
|
|
/**
|
|
* Публичный прокси-эндпоинт медиа рекламы. Ключи объектов содержат слэши
|
|
* (например "images/<uuid>.jpg"), поэтому используем wildcard {*key},
|
|
* как в FileStorageController для картинок постов.
|
|
*/
|
|
@Slf4j
|
|
@RestController
|
|
@RequestMapping("/api/v1/ads-media")
|
|
@RequiredArgsConstructor
|
|
public class AdvertisingMediaController {
|
|
|
|
private final AdvertisingMediaService mediaService;
|
|
|
|
@GetMapping("/{*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.debug("GET ads-media: key={} -> mediaKey={}, range={}", key, mediaKey, range);
|
|
return mediaService.downloadMedia(mediaKey, range);
|
|
}
|
|
} |