develop #22

Merged
william merged 44 commits from develop into master 2021-12-14 23:59:36 -05:00
2 changed files with 6 additions and 16 deletions
Showing only changes of commit e1ca6a8d83 - Show all commits

View File

@ -3,8 +3,6 @@ package dev.fyloz.colorrecipesexplorer.rest
import dev.fyloz.colorrecipesexplorer.model.ConfigurationType
import dev.fyloz.colorrecipesexplorer.service.config.ConfigurationService
import dev.fyloz.colorrecipesexplorer.service.files.WriteableFileService
import org.springframework.core.io.ByteArrayResource
import org.springframework.core.io.Resource
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.security.access.prepost.PreAuthorize
@ -24,14 +22,7 @@ class FileController(
fun upload(
@RequestParam path: String,
@RequestParam(required = false) mediaType: String?
): ResponseEntity<Resource> {
val file = fileService.read(path)
return ResponseEntity.ok()
.header("Content-Disposition", "filename=${getFileNameFromPath(path)}")
.contentLength(file.contentLength())
.contentType(MediaType.parseMediaType(mediaType ?: DEFAULT_MEDIA_TYPE))
.body(file)
}
) = ok(fileService.read(path), mediaType)
@PutMapping(consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
@PreAuthorize("hasAnyAuthority('WRITE_FILE')")
@ -46,11 +37,10 @@ class FileController(
@DeleteMapping
@PreAuthorize("hasAnyAuthority('WRITE_FILE')")
fun delete(@RequestParam path: String): ResponseEntity<Void> {
return noContent {
fun delete(@RequestParam path: String): ResponseEntity<Void> =
noContent {
fileService.delete(path)
}
}
private fun created(path: String): ResponseEntity<Void> =
ResponseEntity

View File

@ -26,13 +26,13 @@ fun ok(action: () -> Unit): ResponseEntity<Void> {
return ResponseEntity.ok().build()
}
fun ok(file: Resource, mediaType: String? = null): ResponseEntity<Resource> {
return ResponseEntity.ok()
/** Creates a HTTP OK [ResponseEntity] for the given [file], with the given [mediaType]. */
fun ok(file: Resource, mediaType: String? = null): ResponseEntity<Resource> =
ResponseEntity.ok()
.header("Content-Disposition", "filename=${file.filename}")
.contentLength(file.contentLength())
.contentType(MediaType.parseMediaType(mediaType ?: DEFAULT_MEDIA_TYPE))
.body(file)
}
/** Creates a HTTP CREATED [ResponseEntity] from the given [body] with the location set to [controllerPath]/id. */
fun <T : Model> created(controllerPath: String, body: T): ResponseEntity<T> =