commit 10/09/2025
This commit is contained in:
@@ -208,7 +208,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
if (!exists) {
|
||||
if (ValidFile(addvalue.Path)) {
|
||||
if (db.Add_Soundbank(addvalue)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500)
|
||||
.result("Failed to add soundbank to database")
|
||||
} else it.status(400)
|
||||
@@ -216,10 +216,10 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
} else it.status(400)
|
||||
.result("TAG=${addvalue.TAG} already exists for the same Language=${addvalue.Language} and Category=${addvalue.Category}")
|
||||
} else it.status(400).result("Invalid Path")
|
||||
} else it.status(400).result("Invalid Language")
|
||||
} else it.status(400).result("Invalid Category")
|
||||
} else it.status(400).result("Invalid TAG")
|
||||
} else it.status(400).result("Invalid Description")
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Language")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Category")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid TAG")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Description")))
|
||||
} catch (_: Exception) {
|
||||
it.status(400).result("Invalid request body")
|
||||
}
|
||||
@@ -227,7 +227,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
delete("List") {
|
||||
// truncate soundbank table
|
||||
if (db.Clear_Soundbank()) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to truncate soundbank table")
|
||||
}
|
||||
@@ -236,10 +236,10 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
// delete by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
if (db.Delete_Soundbank_by_index(index)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to delete soundbank with index $index")
|
||||
}
|
||||
@@ -250,7 +250,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
// tidak ada path param index
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
val sb = db.SoundbankList.find { xx -> xx.index == index }
|
||||
if (sb == null) {
|
||||
@@ -260,7 +260,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
// soundbank dengan index tersebut ditemukan, sekarang update
|
||||
val json: JsonNode = objectmapper.readTree(it.body())
|
||||
if (json.isEmpty) {
|
||||
it.status(400).result("UpdateByIndex with index=$index has empty body")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "UpdateByIndex with index=$index has empty body")))
|
||||
} else {
|
||||
val _description = json.get("Description").asText()
|
||||
val _tag = json.get("TAG").asText()
|
||||
@@ -283,7 +283,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
sb.Category = _category
|
||||
changed = true
|
||||
} else {
|
||||
it.status(400).result("Invalid Category")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Category")))
|
||||
return@patch
|
||||
}
|
||||
}
|
||||
@@ -302,7 +302,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
}
|
||||
if (changed) {
|
||||
if (db.Update_Soundbank_by_index(index, sb)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500).result("Failed to update soundbank with index $index")
|
||||
} else it.status(400)
|
||||
.result("Nothing has changed for soundbank with index $index")
|
||||
@@ -328,18 +328,18 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
post("ImportXLSX") {
|
||||
val uploaded = it.uploadedFile("file")
|
||||
if (uploaded == null) {
|
||||
it.status(400).result("No file uploaded")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "No file uploaded")))
|
||||
return@post
|
||||
}
|
||||
try {
|
||||
val xlsx = XSSFWorkbook(uploaded.content())
|
||||
if (db.Import_Soundbank_XLSX(xlsx)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to import soundbank from XLSX")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
it.status(400).result("Invalid XLSX file")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid XLSX file")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,21 +354,21 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
delete("List") {
|
||||
// truncate messagebank table
|
||||
if (db.Clear_Messagebank()) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to truncate messagebank table")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to truncate messagebank table")))
|
||||
}
|
||||
}
|
||||
delete("DeleteByIndex/{index}") {
|
||||
// delete by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
if (db.Delete_Messagebank_by_index(index)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to delete messagebank with index $index")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to delete messagebank with index $index")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -376,15 +376,15 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
// update messagebank by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
val mb = db.MessagebankList.find { xx -> xx.index == index }
|
||||
if (mb == null) {
|
||||
it.status(404).result("Messagebank with index $index not found")
|
||||
it.status(404).result(objectmapper.writeValueAsString(mapOf("message" to "Messagebank with index $index not found")))
|
||||
} else {
|
||||
val json: JsonNode = objectmapper.readTree(it.body())
|
||||
if (json.isEmpty) {
|
||||
it.status(400).result("UpdateByIndex with index=$index has empty body")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "UpdateByIndex with index=$index has empty body")))
|
||||
} else {
|
||||
val _description = json.get("Description").asText()
|
||||
val _language = json.get("Language").asText()
|
||||
@@ -411,7 +411,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
mb.Voice_Type = _voice_type
|
||||
changed = true
|
||||
} else {
|
||||
it.status(400).result("Invalid Voice_Type")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Voice_Type")))
|
||||
return@patch
|
||||
}
|
||||
}
|
||||
@@ -425,11 +425,11 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
}
|
||||
if (changed) {
|
||||
if (db.Update_Messagebank_by_index(index, mb)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500)
|
||||
.result("Failed to update messagebank with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Failed to update messagebank with index $index")))
|
||||
} else it.status(400)
|
||||
.result("Nothing has changed for messagebank with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Nothing has changed for messagebank with index $index")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,24 +446,24 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
xlsxdata.write(out)
|
||||
}
|
||||
} else {
|
||||
it.status(500).result("Failed to export messagebank to XLSX")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to export messagebank to XLSX")))
|
||||
}
|
||||
}
|
||||
post("ImportXLSX") {
|
||||
val uploaded = it.uploadedFile("file")
|
||||
if (uploaded == null) {
|
||||
it.status(400).result("No file uploaded")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "No file uploaded")))
|
||||
return@post
|
||||
}
|
||||
try {
|
||||
val xlsx = XSSFWorkbook(uploaded.content())
|
||||
if (db.Import_Messagebank_XLSX(xlsx)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to import messagebank from XLSX")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to import messagebank from XLSX")))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
it.status(400).result("Invalid XLSX file")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid XLSX file")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -482,30 +482,30 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
if (db.LanguageLinkList.any { ll -> ll.TAG==tag }){
|
||||
val newvalue = LanguageLink(0u, tag, languages.joinToString(";"))
|
||||
if (db.Add_LanguageLink(newvalue)){
|
||||
it.result("OK")
|
||||
} else it.status(500).result("Failed to add language link to database")
|
||||
} else it.status(400).result("TAG=$tag already exists" )
|
||||
} else it.status(400).result("Contains unsupported language" )
|
||||
} else it.status(400).result("Invalid tag or language")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to add language link to database")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "TAG=$tag already exists")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Contains unsupported language")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid tag or language")))
|
||||
}
|
||||
delete("List") {
|
||||
// truncate language link table
|
||||
if (db.Clear_LanguageLink()) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to truncate language link table")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to truncate language link table")))
|
||||
}
|
||||
}
|
||||
delete("DeleteByIndex/{index}") {
|
||||
// delete by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
if (db.Delete_LanguageLink_by_index(index)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to delete language link with index $index")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to delete language link with index $index")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -513,18 +513,18 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
// update by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
val ll = db.LanguageLinkList.find { xx -> xx.index == index }
|
||||
if (ll == null) {
|
||||
it.status(404).result("Language link with index $index not found")
|
||||
it.status(404).result(objectmapper.writeValueAsString(mapOf("message" to "Language link with index $index not found")))
|
||||
} else {
|
||||
val json: JsonNode = objectmapper.readTree(it.body())
|
||||
if (json.isEmpty) {
|
||||
it.status(400).result("UpdateByIndex with index=$index has empty body")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "UpdateByIndex with index=$index has empty body")))
|
||||
} else {
|
||||
val _tag = json.get("TAG").asText()
|
||||
val _language = json.get("Language").asText()
|
||||
val _tag = json.get("tag").asText()
|
||||
val _language = json.get("language").asText()
|
||||
var changed = false
|
||||
if (ValidString(_language) && _language != ll.Language) {
|
||||
ll.Language = _language
|
||||
@@ -536,11 +536,11 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
}
|
||||
if (changed) {
|
||||
if (db.Update_LanguageLink_by_index(index, ll)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500)
|
||||
.result("Failed to update language link with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Failed to update language link with index $index")))
|
||||
} else it.status(400)
|
||||
.result("Nothing has changed for language link with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Nothing has changed for language link with index $index")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -557,24 +557,24 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
xlsxdata.write(out)
|
||||
}
|
||||
} else {
|
||||
it.status(500).result("Failed to export language link to XLSX")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to export language link to XLSX")))
|
||||
}
|
||||
}
|
||||
post("ImportXLSX") {
|
||||
val uploaded = it.uploadedFile("file")
|
||||
if (uploaded == null) {
|
||||
it.status(400).result("No file uploaded")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "No file uploaded")))
|
||||
return@post
|
||||
}
|
||||
try {
|
||||
val xlsx = XSSFWorkbook(uploaded.content())
|
||||
if (db.Import_LanguageLink_XLSX(xlsx)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to import language link from XLSX")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to import language link from XLSX")))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
it.status(400).result("Invalid XLSX file")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid XLSX file")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -586,19 +586,19 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
delete("List") {
|
||||
// truncate timer table
|
||||
if (db.Clear_Schedulebank()) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to truncate schedulebank table")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to truncate schedulebank table")))
|
||||
}
|
||||
}
|
||||
delete("DeleteByIndex/{index}") {
|
||||
// delete by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
if (db.Delete_Schedulebank_by_index(index)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to delete schedule with index $index")
|
||||
}
|
||||
@@ -608,7 +608,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
// update by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
val sb = db.SchedulebankList.find { xx -> xx.index == index }
|
||||
if (sb == null) {
|
||||
@@ -616,7 +616,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
} else {
|
||||
val json: JsonNode = objectmapper.readTree(it.body())
|
||||
if (json.isEmpty) {
|
||||
it.status(400).result("UpdateByIndex with index=$index has empty body")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "UpdateByIndex with index=$index has empty body")))
|
||||
} else {
|
||||
val _description = json.get("Description").asText()
|
||||
val _time = json.get("Time").asText()
|
||||
@@ -670,17 +670,17 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
sb.Language = _language
|
||||
changed = true
|
||||
} else {
|
||||
it.status(400).result("Invalid Language")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Language")))
|
||||
return@patch
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
if (db.Update_Schedulebank_by_index(index, sb)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500)
|
||||
.result("Failed to update schedule with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Failed to update schedule with index $index")))
|
||||
} else it.status(400)
|
||||
.result("Nothing has changed for schedule with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Nothing has changed for schedule with index $index")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -697,24 +697,24 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
xlsxdata.write(out)
|
||||
}
|
||||
} else {
|
||||
it.status(500).result("Failed to export schedulebank to XLSX")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to export schedulebank to XLSX")))
|
||||
}
|
||||
}
|
||||
post("ImportXLSX") {
|
||||
val uploaded = it.uploadedFile("file")
|
||||
if (uploaded == null) {
|
||||
it.status(400).result("No file uploaded")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "No file uploaded")))
|
||||
return@post
|
||||
}
|
||||
try {
|
||||
val xlsx = XSSFWorkbook(uploaded.content())
|
||||
if (db.Import_Schedulebank_XLSX(xlsx)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to import schedulebank from XLSX")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
it.status(400).result("Invalid XLSX file")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid XLSX file")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -738,14 +738,15 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
get1.status(400).result("Invalid logdate")
|
||||
}
|
||||
}
|
||||
get("ExportXLSX/<logdate>/<logfilter>") { get1 ->
|
||||
val logdate = get1.pathParam("logdate")
|
||||
val logfilter = get1.pathParam("logfilter")
|
||||
if (ValidDate(logdate)) {
|
||||
get("ExportXLSX") { get1 ->
|
||||
val logdate = get1.queryParam("date") ?: ""
|
||||
val logfilter = get1.queryParam("filter") ?: ""
|
||||
println("Export log to XLSX, date=$logdate, filter=$logfilter")
|
||||
if (ValiDateForLogHtml(logdate)) {
|
||||
val xlsxdata = if (ValidString(logfilter)) {
|
||||
db.Export_Log_XLSX(logdate, logfilter)
|
||||
db.Export_Log_XLSX(logdate.replace('-','/'), logfilter)
|
||||
} else {
|
||||
db.Export_Log_XLSX(logdate, "")
|
||||
db.Export_Log_XLSX(logdate.replace('-','/'), "")
|
||||
}
|
||||
if (xlsxdata != null) {
|
||||
get1.header(
|
||||
|
||||
Reference in New Issue
Block a user