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/.jpg"), поэтому используем wildcard {*key}, * как в FileStorageController для картинок постов. */ @Slf4j @RestController @RequestMapping("/api/v1/ads-media") @RequiredArgsConstructor public class AdvertisingMediaController { private final AdvertisingMediaService mediaService; @GetMapping("/{*key}") public ResponseEntity 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); } }