-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52fc12c
commit 26d7b4d
Showing
9 changed files
with
60 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/server/FileServer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
package dev.schlaubi.tonbrett.bot.server | ||
|
||
import dev.schlaubi.tonbrett.bot.config.Config | ||
import dev.schlaubi.tonbrett.bot.io.SoundBoardDatabase | ||
import dev.schlaubi.tonbrett.bot.util.soundNotFound | ||
import dev.schlaubi.tonbrett.common.Route.Sounds | ||
import io.ktor.server.application.* | ||
import io.ktor.server.resources.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import org.bson.types.ObjectId | ||
import kotlin.io.path.div | ||
|
||
fun Route.files() { | ||
get<Sounds.Sound.Audio> { (id) -> | ||
val sound = SoundBoardDatabase.sounds.findOneById(ObjectId(id)) | ||
?: soundNotFound() | ||
|
||
val path = Config.SOUNDS_FOLDER / sound.fileName | ||
|
||
call.respondFile(path.toFile()) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/server/Ktor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dev.schlaubi.tonbrett.bot.server | ||
|
||
import dev.schlaubi.mikbot.util_plugins.ktor.api.KtorExtensionPoint | ||
import io.ktor.server.application.* | ||
import io.ktor.server.routing.* | ||
import org.pf4j.Extension | ||
|
||
@Extension | ||
class Ktor : KtorExtensionPoint { | ||
override fun Application.apply() { | ||
routing { | ||
files() | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/util/KtorUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.schlaubi.tonbrett.bot.util | ||
|
||
import io.ktor.server.plugins.* | ||
|
||
fun notFound(message: String): Nothing = throw NotFoundException(message) | ||
fun soundNotFound(): Nothing = notFound("Sound not found") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters