Skip to content

Commit

Permalink
Use auth for both versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kikugie committed Oct 6, 2024
1 parent 3e0ae4d commit 8bfd8b3
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/main/kotlin/dev/kikugie/soundboard/audio/download/CobaltAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ abstract class CobaltAPI {
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.post(body.toRequestBody())
buildHeader(request)
Soundboard.config.cobaltToken.takeUnless { it.isBlank() }?.let {
request.header("Authorization", "Api-Key $it")
}
try {
CLIENT.newCall(request.build()).execute().use {
if (it.body == null) throw Exception("${it.code} - '${it.message}'")
Expand All @@ -95,7 +97,6 @@ abstract class CobaltAPI {
}
}

protected abstract fun buildHeader(builder: Request.Builder)
protected abstract fun createMetadata(url: URI): List<Pair<String, Any>>
protected abstract fun decodeResponse(contents: String): CobaltResponse
}
Expand Down Expand Up @@ -123,10 +124,6 @@ object CobaltAPIV10 : CobaltAPI() {
override val ENDPOINT: String
get() = "${Soundboard.config.cobaltEndpoint}/"

override fun buildHeader(builder: Request.Builder) {
builder.header("Authorization", "Api-Key ${Soundboard.config.cobaltToken}")
}

override fun createMetadata(url: URI) = listOf(
"url" to url,
"audioFormat" to "wav",
Expand Down Expand Up @@ -169,10 +166,6 @@ object CobaltAPIV7 : CobaltAPI() {
override val ENDPOINT: String
get() = "${Soundboard.config.cobaltEndpoint}/api/json"

override fun buildHeader(builder: Request.Builder) {
// Nothing to do in V7
}

override fun createMetadata(url: URI) = listOf(
"url" to url,
"aFormat" to "wav",
Expand Down

0 comments on commit 8bfd8b3

Please sign in to comment.