Serve public icon files
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s

This commit is contained in:
androidlover5842
2026-01-27 22:37:52 +05:30
parent 8b430cbbcf
commit 58b7e57821
3 changed files with 24 additions and 0 deletions

View File

@@ -1,7 +1,12 @@
package com.android.trisolarisserver.controller
import org.springframework.beans.factory.annotation.Value
import org.springframework.core.io.FileSystemResource
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
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.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.nio.file.Files
@@ -29,4 +34,21 @@ class IconFiles(
.toList()
}
}
@GetMapping("/png/{filename}")
fun getPng(@PathVariable filename: String): ResponseEntity<FileSystemResource> {
if (filename.contains("..") || filename.contains("/") || filename.contains("\\")) {
return ResponseEntity.badRequest().build()
}
val file = Paths.get(pngRoot, filename)
if (!Files.exists(file) || !Files.isRegularFile(file)) {
return ResponseEntity.notFound().build()
}
val resource = FileSystemResource(file)
return ResponseEntity.ok()
.contentType(MediaType.IMAGE_PNG)
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"${file.fileName}\"")
.contentLength(resource.contentLength())
.body(resource)
}
}