Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import team.darkmoderap.aikon.domain.exchange.service.ExchangeFileService
class ExchangeController(
private val exchangeFileService: ExchangeFileService,
) {
@PostMapping("/upload", consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
@PostMapping("/avatar", consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
@ResponseStatus(HttpStatus.NO_CONTENT)
fun uploadIncoming(
fun uploadAvatar(
@RequestPart("file") file: MultipartFile,
) {
exchangeFileService.uploadIncoming(file)
exchangeFileService.uploadAvatar(file)
}

@GetMapping("/outgoing", produces = [MediaType.IMAGE_PNG_VALUE])
fun downloadOutgoing(): ByteArray = exchangeFileService.downloadOutgoing()
@GetMapping("/report", produces = [MediaType.IMAGE_PNG_VALUE])
fun downloadReport(): ByteArray = exchangeFileService.downloadReport()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ class ExchangeFileService(
@Qualifier("exchangeS3Client") private val s3Client: S3Client,
@Value("\${exchange.minio.bucket}") private val bucket: String,
) {
fun uploadIncoming(
fun uploadAvatar(
file: MultipartFile,
fileName: String = "Aikon500.png",
) {
val request =
PutObjectRequest
.builder()
.bucket(bucket)
.key("incoming/$fileName")
.key("avatar/$fileName")
.contentType(file.contentType ?: MediaType.APPLICATION_OCTET_STREAM_VALUE)
.build()

file.inputStream.use { s3Client.putObject(request, RequestBody.fromInputStream(it, file.size)) }
}

fun downloadOutgoing(fileName: String = "report500.png"): ByteArray {
fun downloadReport(fileName: String = "report500.png"): ByteArray {
val request =
GetObjectRequest
.builder()
.bucket(bucket)
.key("outgoing/$fileName")
.key("report/$fileName")
.build()

return s3Client.getObjectAsBytes(request).asByteArray()
Expand Down
Loading