-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up Kotlin code and add GET history and GET available
- Loading branch information
1 parent
adb4acf
commit d5915b0
Showing
20 changed files
with
208 additions
and
36 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module version="4"> | ||
<component name="AdditionalModuleElements"> | ||
<content url="file://$MODULE_DIR$" dumb="true"> | ||
<excludeFolder url="file://$MODULE_DIR$/data/generations" /> | ||
</content> | ||
</component> | ||
</module> |
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
21 changes: 21 additions & 0 deletions
21
serverkt/src/main/kotlin/fi/floo/voice/routing/api/v2/available.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,21 @@ | ||
package fi.floo.voice.routing.api.v2 | ||
|
||
import fi.floo.voice.getAuthenticationData | ||
import fi.floo.voice.types.* | ||
import io.ktor.http.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.response.* | ||
|
||
suspend fun apiV2Available(call: ApplicationCall) { | ||
val auth = getAuthenticationData(call, AuthenticationMode.Enforced) | ||
if (!auth.authenticated || auth.userData == null) return | ||
|
||
val list: GenerationList = Generation.forUser(auth.userData) | ||
val items = list.inner | ||
.map { it.data.status == "generating" || it.data.status == "queued" } | ||
|
||
call.respond(HttpStatusCode.OK, APIResponse( | ||
error = null, | ||
output = APIResponseAvailable(!items.contains(true)) | ||
)) | ||
} |
10 changes: 1 addition & 9 deletions
10
serverkt/src/main/kotlin/fi/floo/voice/routing/api/v2/handoff.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
23 changes: 23 additions & 0 deletions
23
serverkt/src/main/kotlin/fi/floo/voice/routing/api/v2/history.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,23 @@ | ||
package fi.floo.voice.routing.api.v2 | ||
|
||
import fi.floo.voice.getAuthenticationData | ||
import fi.floo.voice.types.* | ||
import io.ktor.http.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.response.* | ||
|
||
suspend fun apiV2History(call: ApplicationCall) { | ||
val auth = getAuthenticationData(call, AuthenticationMode.Enforced) | ||
if (!auth.authenticated || auth.userData == null) return | ||
|
||
val list: GenerationList = Generation.forUser(auth.userData) | ||
list.inner = list.inner | ||
.filter { it.data.status != "blocked" } | ||
.filter { it.data.status != "removed" } | ||
.toMutableList() | ||
|
||
call.respond(HttpStatusCode.OK, APIResponse( | ||
error = null, | ||
output = list.flatten() | ||
)) | ||
} |
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
3 changes: 0 additions & 3 deletions
3
serverkt/src/main/kotlin/fi/floo/voice/routing/api/v2/status.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
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
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
8 changes: 8 additions & 0 deletions
8
serverkt/src/main/kotlin/fi/floo/voice/types/APIResponseAvailable.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,8 @@ | ||
package fi.floo.voice.types | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class APIResponseAvailable( | ||
val available: Boolean | ||
) |
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
86 changes: 86 additions & 0 deletions
86
serverkt/src/main/kotlin/fi/floo/voice/types/Generation.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,86 @@ | ||
package fi.floo.voice.types | ||
|
||
import java.io.File | ||
import java.time.Instant | ||
import java.time.format.DateTimeFormatter | ||
import java.util.* | ||
|
||
class Generation(val data: GenerationData) { | ||
val time = Date(data.timeTs) | ||
|
||
companion object { | ||
fun forUser(user: UserData): GenerationList { | ||
val list = GenerationList(mutableListOf()) | ||
val directory = File("data/generations") | ||
val files = directory.listFiles()?.filter { it.isDirectory } | ||
|
||
if (files != null) { | ||
for (file in files) { | ||
list.inner.add(fromDirectory(file)) | ||
list.inner.sortBy { it.time } | ||
list.inner = list.inner | ||
.filter { it.data.version != "0" } | ||
.filter { it.data.model != "" } | ||
.filter { it.data.author == user.id } | ||
.toMutableList() | ||
} | ||
} | ||
|
||
return list | ||
} | ||
|
||
private fun fromDirectory(directory: File): Generation { | ||
val author = File("${directory.absolutePath}/author.txt").readText() | ||
val complete = File("${directory.absolutePath}/complete.txt").exists() | ||
val blocked = File("${directory.absolutePath}/blocked.txt").exists() | ||
val input = File("${directory.absolutePath}/input_orig.txt").readText() | ||
val process = File("${directory.absolutePath}/process.txt").exists() | ||
val removed = File("${directory.absolutePath}/removed.txt").exists() | ||
val timestamp = File("${directory.absolutePath}/timestamp.txt").readText() | ||
|
||
val versionFile = File("${directory.absolutePath}/version.txt") | ||
val version = if (versionFile.exists()) { | ||
versionFile.readText() | ||
} else { | ||
"0" | ||
} | ||
|
||
val modelFile = File("${directory.absolutePath}/model.txt") | ||
val model = if (modelFile.exists()) { | ||
modelFile.readText() | ||
} else { | ||
"" | ||
} | ||
|
||
val timeTs = timestamp.toLong() | ||
val timeInstant = Instant.ofEpochSecond(timeTs) | ||
val dateIso = DateTimeFormatter.ISO_INSTANT.format(timeInstant) | ||
|
||
val status = if (blocked) { | ||
"blocked" | ||
} else if (removed) { | ||
"removed" | ||
} else if (complete) { | ||
"processed" | ||
} else if (process) { | ||
"generating" | ||
} else { | ||
"queued" | ||
} | ||
|
||
val data = GenerationData( | ||
id = directory.name, | ||
model = model, | ||
version = version, | ||
author = author, | ||
time = dateIso, | ||
timeTs = timeTs, | ||
audioUrl = "", | ||
input = input, | ||
status = status | ||
) | ||
|
||
return Generation(data) | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
serverkt/src/main/kotlin/fi/floo/voice/types/GenerationData.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,16 @@ | ||
package fi.floo.voice.types | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class GenerationData( | ||
val id: String, | ||
val model: String, | ||
val version: String, | ||
val author: String, | ||
val time: String, | ||
val timeTs: Long, | ||
val audioUrl: String, | ||
val input: String, | ||
var status: String | ||
) |
Oops, something went wrong.