commit 23/10/2025
This commit is contained in:
11
src/Main.kt
11
src/Main.kt
@@ -97,7 +97,7 @@ fun files_preparation(){
|
||||
|
||||
}
|
||||
|
||||
lateinit var config : configFile;
|
||||
lateinit var config : configFile
|
||||
|
||||
// Application start here
|
||||
fun main() {
|
||||
@@ -135,6 +135,7 @@ fun main() {
|
||||
subcode01.Read_Queue_Soundbank()
|
||||
}
|
||||
}
|
||||
|
||||
// Coroutine untuk cek Schedulebank tiap menit saat detik 00
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
while (isActive) {
|
||||
@@ -144,11 +145,11 @@ fun main() {
|
||||
}
|
||||
|
||||
val web = WebApp(
|
||||
3030,
|
||||
config.Get(configKeys.WEBAPP_PORT.key).toInt(),
|
||||
listOf(
|
||||
Pair("admin", "password"),
|
||||
Pair("user", "password")
|
||||
))
|
||||
Pair(config.Get(configKeys.WEBAPP_ADMIN_USERNAME.key), config.Get(configKeys.WEBAPP_ADMIN_PASSWORD.key)),
|
||||
Pair(config.Get(configKeys.WEBAPP_VIEWER_USERNAME.key), config.Get(configKeys.WEBAPP_VIEWER_PASSWORD.key))
|
||||
), config)
|
||||
web.Start()
|
||||
|
||||
udpreceiver = UDPReceiver()
|
||||
|
||||
@@ -12,6 +12,7 @@ import codes.Somecodes.Companion.ValidString
|
||||
import codes.Somecodes.Companion.dateformat1
|
||||
import codes.Somecodes.Companion.datetimeformat1
|
||||
import codes.Somecodes.Companion.timeformat2
|
||||
import codes.configKeys
|
||||
import content.Category
|
||||
import content.Language
|
||||
import content.ScheduleDay
|
||||
@@ -892,23 +893,31 @@ class MainExtension01 {
|
||||
val variables = Get_Soundbank_Data(qa.SB_TAGS)
|
||||
val languages = qa.Language.split(";")
|
||||
// cek apakah ANN_ID ada di SB_TAGS
|
||||
val ann_id = variables?.get("ANN_ID")?.toIntOrNull() ?: 0
|
||||
var ann_id = variables?.get("ANN_ID")?.toIntOrNull() ?: 0
|
||||
if (ann_id==0){
|
||||
// not available from variables, try to get from Message column
|
||||
// ada ini, karena protokol FIS dulu tidak ada ANN_ID tapi pake Remark
|
||||
val remark = variables?.get("REMARK").orEmpty()
|
||||
when(remark){
|
||||
"GOP" -> {
|
||||
//TODO Combobox First_Call_Message_Chooser
|
||||
//TODO Combobox First_Call_Message_Chooser.
|
||||
val remarkMsg = config.Get(configKeys.REMARK_GOP.toString())
|
||||
ann_id = Regex("\\[(\\d+)]").find(remarkMsg)?.value?.toIntOrNull() ?: 0
|
||||
}
|
||||
"GBD" ->{
|
||||
// TODO Combobox Second_Call_Message_Chooser
|
||||
val remarkMsg = config.Get(configKeys.REMARK_GBD.toString())
|
||||
ann_id = Regex("\\[(\\d+)]").find(remarkMsg)?.value?.toIntOrNull() ?: 0
|
||||
}
|
||||
"GFC" ->{
|
||||
// TODO Combobox Final_Call_Message_Chooser
|
||||
val remarkMsg = config.Get(configKeys.REMARK_GFC.toString())
|
||||
ann_id = Regex("\\[(\\d+)]").find(remarkMsg)?.value?.toIntOrNull() ?: 0
|
||||
}
|
||||
"FLD" ->{
|
||||
// TODO Combobox Landed_Message_Chooser
|
||||
val remarkMsg = config.Get(configKeys.REMARK_FLD.toString())
|
||||
ann_id = Regex("\\[(\\d+)]").find(remarkMsg)?.value?.toIntOrNull() ?: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class configFile {
|
||||
}
|
||||
|
||||
private fun HaveAllKeys() : Boolean{
|
||||
return configKeys.values().all { config.containsKey(it.key) }
|
||||
return configKeys.entries.all { config.containsKey(it.key) }
|
||||
|
||||
}
|
||||
|
||||
@@ -61,6 +61,11 @@ class configFile {
|
||||
config[configKeys.REMARK_GBD.key] = ""
|
||||
config[configKeys.REMARK_GFC.key] = ""
|
||||
config[configKeys.REMARK_FLD.key] = ""
|
||||
config[configKeys.WEBAPP_ADMIN_USERNAME.key] = "admin"
|
||||
config[configKeys.WEBAPP_ADMIN_PASSWORD.key] = "password"
|
||||
config[configKeys.WEBAPP_VIEWER_USERNAME.key] = "viewer"
|
||||
config[configKeys.WEBAPP_VIEWER_PASSWORD.key] = "password"
|
||||
config[configKeys.WEBAPP_PORT.key] = "3030"
|
||||
Save()
|
||||
}
|
||||
}
|
||||
@@ -10,5 +10,10 @@ enum class configKeys(val key: String) {
|
||||
REMARK_GOP("remark.GOP"),
|
||||
REMARK_GBD("remark.GBD"),
|
||||
REMARK_GFC("remark.GFC"),
|
||||
REMARK_FLD("remark.FLD")
|
||||
REMARK_FLD("remark.FLD"),
|
||||
WEBAPP_ADMIN_USERNAME("webapp.admin.username"),
|
||||
WEBAPP_ADMIN_PASSWORD("webapp.admin.password"),
|
||||
WEBAPP_VIEWER_USERNAME("webapp.viewer.username"),
|
||||
WEBAPP_VIEWER_PASSWORD("webapp.viewer.password"),
|
||||
WEBAPP_PORT("webapp.port")
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import codes.Somecodes.Companion.ValidScheduleDay
|
||||
import codes.Somecodes.Companion.ValidScheduleTime
|
||||
import codes.Somecodes.Companion.ValidString
|
||||
import codes.Somecodes.Companion.ValidStrings
|
||||
import codes.configFile
|
||||
import com.fasterxml.jackson.databind.JsonNode
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import content.Category
|
||||
@@ -41,9 +42,13 @@ import io.javalin.websocket.WsMessageContext
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook
|
||||
import java.nio.file.Files
|
||||
import java.time.LocalDateTime
|
||||
import codes.configKeys
|
||||
import org.tinylog.Logger
|
||||
//import com.sun.security.auth.login.ConfigFile
|
||||
|
||||
|
||||
@Suppress("unused")
|
||||
class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
|
||||
class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val _config: configFile) {
|
||||
|
||||
var app: Javalin? = null
|
||||
val objectmapper = jacksonObjectMapper()
|
||||
@@ -1448,7 +1453,6 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
path("QueueTable"){
|
||||
get("List"){
|
||||
it.result(MariaDB.ArrayListtoString(db.queuetableDB.List))
|
||||
@@ -1472,6 +1476,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
|
||||
db.queuetableDB.Resort()
|
||||
it.result(objectmapper.writeValueAsString(resultMessage("OK")))
|
||||
db.Add_Log("AAS", "Deleted queue sound with index $index")
|
||||
|
||||
} else {
|
||||
it.status(500).result(objectmapper.writeValueAsString(resultMessage("Failed to delete queue sound with index $index")))
|
||||
}
|
||||
@@ -1480,12 +1485,107 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
|
||||
}
|
||||
path("Settings"){
|
||||
|
||||
get("SoundbankDirectory"){
|
||||
val dir = _config.Get(configKeys.SOUNDBANK_DIRECTORY.key)
|
||||
it.result(objectmapper.writeValueAsString(resultMessage(dir)))
|
||||
}
|
||||
post("SoundbankDirectory"){
|
||||
val json : JsonNode = objectmapper.readTree(it.body())
|
||||
val newdir = json.get("directory").asText("")
|
||||
if (ValidString(newdir)){
|
||||
_config.Set(configKeys.SOUNDBANK_DIRECTORY.key, newdir)
|
||||
_config.Save()
|
||||
Logger.info { "Changed Soundbank Directory to $newdir" }
|
||||
it.result(objectmapper.writeValueAsString(resultMessage("OK")))
|
||||
} else {
|
||||
it.status(400)
|
||||
.result(objectmapper.writeValueAsString(resultMessage("Invalid directory value")))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
get("SoundbankResultList"){
|
||||
it.result(objectmapper.writeValueAsString(ListAudioFiles(Somecodes.SoundbankResult_directory)))
|
||||
}
|
||||
|
||||
get("SoundbankResultFile/{filename}"){
|
||||
|
||||
//TODO recheck bener/gak cara downloadnya
|
||||
val filename = it.pathParam("filename")
|
||||
|
||||
val filepath = Somecodes.SoundbankResult_directory.resolve(filename)
|
||||
if (ValidFile(filename) && Files.isRegularFile(filepath)){
|
||||
it.header(
|
||||
"Content-Disposition",
|
||||
"attachment; filename=\"$filename\"")
|
||||
it.outputStream().use { out ->
|
||||
Files.newInputStream(filepath).use { inp ->
|
||||
inp.copyTo(out)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
it.status(404).result(objectmapper.writeValueAsString(resultMessage("File not found")))
|
||||
}
|
||||
}
|
||||
|
||||
get("PagingResultList"){
|
||||
it.result(objectmapper.writeValueAsString(ListAudioFiles(Somecodes.PagingResult_directory)))
|
||||
}
|
||||
|
||||
get ("PagingResultFile/{filename}"){
|
||||
val filename = it.pathParam("filename")
|
||||
val filepath = Somecodes.PagingResult_directory.resolve(filename)
|
||||
if (ValidFile(filename) && Files.isRegularFile(filepath)){
|
||||
it.header("Content-Disposition", "attachment; filename=\"$filename\"")
|
||||
it.outputStream().use { out ->
|
||||
Files.newInputStream(filepath).use { inp ->
|
||||
inp.copyTo(out)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
it.status(404).result(objectmapper.writeValueAsString(resultMessage("File not found")))
|
||||
}
|
||||
}
|
||||
|
||||
get("Messages"){
|
||||
val messages = db.messageDB.List
|
||||
it.result(objectmapper.writeValueAsString(messages))
|
||||
}
|
||||
|
||||
get("FISCode"){
|
||||
//TODO get FIS code
|
||||
val value = object {
|
||||
//get from config file
|
||||
val GOP = _config.Get(configKeys.REMARK_GOP.key)
|
||||
val GBD = _config.Get(configKeys.REMARK_GBD.key)
|
||||
val GFC = _config.Get(configKeys.REMARK_GFC.key)
|
||||
val FLD = _config.Get(configKeys.REMARK_FLD.key)
|
||||
}
|
||||
|
||||
it.result(objectmapper.writeValueAsString(value))
|
||||
}
|
||||
|
||||
post ("FISCode") {
|
||||
//TODO set FIS code
|
||||
|
||||
val json : JsonNode = objectmapper.readTree(it.body())
|
||||
val _gop = json.get("GOP").asText("")
|
||||
val _gbd = json.get("GBD").asText("")
|
||||
val _gfc = json.get("GFC").asText("")
|
||||
val _fld = json.get("FLD").asText("")
|
||||
if (ValidString(_gop) && ValidString(_gbd) && ValidString(_gfc) && ValidString(_fld)){
|
||||
// save to config file
|
||||
_config.Set(configKeys.REMARK_GOP.key, _gop)
|
||||
_config.Set(configKeys.REMARK_GBD.key, _gbd)
|
||||
_config.Set(configKeys.REMARK_GFC.key, _gfc)
|
||||
_config.Set(configKeys.REMARK_FLD.key, _fld)
|
||||
_config.Save()
|
||||
Logger.info { "Changed FIS Codes" }
|
||||
it.result(objectmapper.writeValueAsString(resultMessage("OK")))
|
||||
} else {
|
||||
it.status(400)
|
||||
.result(objectmapper.writeValueAsString(resultMessage("Invalid FIS code value")))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user