Makes CORS config global. Revamps and adds exceptions.
This commit is contained in:
parent
1acd3058bb
commit
da8a8f94d2
@ -0,0 +1,14 @@
|
||||
package net.halfbinary.prettyplayerapi.config
|
||||
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
class WebConfig: WebMvcConfigurer {
|
||||
override fun addCorsMappings(registry: CorsRegistry) {
|
||||
registry.addMapping("/**")
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,14 @@
|
||||
package net.halfbinary.prettyplayerapi.controller
|
||||
|
||||
import net.halfbinary.prettyplayerapi.service.AlbumCacheService
|
||||
import org.springframework.web.bind.annotation.CrossOrigin
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("cache")
|
||||
class CacheController(private val albumCacheService: AlbumCacheService) {
|
||||
@GetMapping("cache")
|
||||
@GetMapping
|
||||
suspend fun refreshAlbumCache() {
|
||||
albumCacheService.refreshAlbumCache()
|
||||
}
|
||||
|
||||
@ -2,15 +2,12 @@ package net.halfbinary.prettyplayerapi.controller
|
||||
|
||||
import net.halfbinary.prettyplayerapi.service.ImageService
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.web.bind.annotation.CrossOrigin
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("image")
|
||||
class ImageController(private val imageService: ImageService) {
|
||||
@GetMapping(value = ["image/{id}"], produces = [MediaType.IMAGE_JPEG_VALUE])
|
||||
@GetMapping(value = ["/{id}"], produces = [MediaType.IMAGE_JPEG_VALUE])
|
||||
fun getImage(@PathVariable("id") id: String): ByteArray {
|
||||
return imageService.getImage(id).readBytes()
|
||||
}
|
||||
|
||||
@ -7,10 +7,9 @@ import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBo
|
||||
|
||||
@RestController
|
||||
@RequestMapping("music")
|
||||
@CrossOrigin
|
||||
class MusicController(private val musicService: MusicService) {
|
||||
|
||||
@GetMapping(value = ["/album/{albumHash}/{trackNumber}"], produces = ["audio/mpeg3"])
|
||||
@GetMapping(value = ["/album/{albumHash}/track/{trackNumber}"], produces = ["audio/mpeg3"])
|
||||
fun getAlbum(@PathVariable albumHash: String, @PathVariable trackNumber: Int): ResponseEntity<StreamingResponseBody> {
|
||||
val track = musicService.getMusic(albumHash, trackNumber)
|
||||
val responseBody = StreamingResponseBody { stream -> stream.write(track.readBytes()) }
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
package net.halfbinary.prettyplayerapi.exception
|
||||
|
||||
class AlbumFolderNotFoundException(folder: String) : RuntimeException("Album folder $folder does not exist") {
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package net.halfbinary.prettyplayerapi.exception
|
||||
|
||||
class AlbumHashNotFoundException(message: String) : RuntimeException(message) {
|
||||
class AlbumHashNotFoundException(hash: String) : RuntimeException("Album hash $hash not found") {
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package net.halfbinary.prettyplayerapi.exception
|
||||
|
||||
class EnvironmentVariableNotFoundException(message: String) : RuntimeException(message) {
|
||||
class EnvironmentVariableNotFoundException(envVar: String) : RuntimeException("Environment variable $envVar does not exist, please specify") {
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user