This commit is contained in:
root
2025-12-05 01:16:16 +05:00
parent 0a37e9a681
commit 95ba34e7fa
2 changed files with 140 additions and 51 deletions
@@ -201,6 +201,45 @@ public class MarketingController {
}
}
/**
* Получает изображение поста по имени файла
*
* @param authHeader Authorization header с JWT токеном
* @param imageFilename Имя файла изображения
* @return Изображение в формате PNG
*/
@GetMapping("/images/{imageFilename}")
public ResponseEntity<byte[]> getPostImage(
@RequestHeader(value = "Authorization", required = false) String authHeader,
@PathVariable String imageFilename) {
String userId = extractUserIdFromHeader(authHeader);
if (userId == null) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
// Проверяем существование файла в MinIO
try {
if (!minIOService.fileExists(imageFilename)) {
logger.warn("Image file not found: {}", imageFilename);
return ResponseEntity.notFound().build();
}
// Загружаем изображение из MinIO
InputStream inputStream = minIOService.downloadFile(imageFilename);
byte[] bytes = inputStream.readAllBytes();
inputStream.close();
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.header(HttpHeaders.CACHE_CONTROL, "public, max-age=3600")
.body(bytes);
} catch (Exception e) {
logger.error("Error loading image {}: {}", imageFilename, e.getMessage(), e);
return ResponseEntity.internalServerError().build();
}
}
@PostMapping("/strategy/generate")
public ResponseEntity<?> generateStrategy(
@RequestHeader(value = "Authorization", required = false) String authHeader,