mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-10 06:27:26 +08:00
[F] Wacca: Fix handle
This commit is contained in:
@@ -60,24 +60,26 @@ class WaccaServer(val rp: WaccaRepos, val cardRepo: CardRepository) {
|
|||||||
|
|
||||||
/** Handle all requests */
|
/** Handle all requests */
|
||||||
@API("/api/**")
|
@API("/api/**")
|
||||||
fun handle(req: HttpServletRequest, @RB body: String) = try {
|
fun handle(req: HttpServletRequest, @RB body: String): Any {
|
||||||
val path = req.requestURI.removePrefix("/g/wacca").removePrefix("/api").removePrefix("/").lowercase()
|
return try {
|
||||||
if (path in cacheMap) return resp(cacheMap[path]!!)
|
val path = req.requestURI.removePrefix("/g/wacca").removePrefix("/api").removePrefix("/").lowercase()
|
||||||
if (path !in handlerMap) return resp("[]", 1, "Not Found")
|
if (path in cacheMap) return resp(cacheMap[path]!!)
|
||||||
|
if (path !in handlerMap) return resp("[]", 1, "Not Found")
|
||||||
|
|
||||||
log.info("Wacca < $path : $body")
|
log.info("Wacca < $path : $body")
|
||||||
|
|
||||||
val br = JACKSON.parse<BaseRequest>(body)
|
val br = JACKSON.parse<BaseRequest>(body)
|
||||||
handlerMap[path]!!(br, br.params).let { when (it) {
|
handlerMap[path]!!(br, br.params).let { when (it) {
|
||||||
is String -> return resp(it)
|
is String -> return resp(it)
|
||||||
is List<*> -> return resp(it.toJson())
|
is List<*> -> return resp(it.toJson())
|
||||||
else -> Error("Invalid response type ${it.javaClass}")
|
else -> Error("Invalid response type ${it.javaClass}")
|
||||||
} }.let { log.info("Wacca > $path : $it") }
|
} }.let { log.info("Wacca > $path : $it") }
|
||||||
}
|
}
|
||||||
catch (e: ApiException) { resp("[]", e.code, e.message ?: "") }
|
catch (e: ApiException) { resp("[]", e.code, e.message ?: "") }
|
||||||
catch (e: Exception) {
|
catch (e: Exception) {
|
||||||
log.error("Wacca > Error", e)
|
log.error("Wacca > Error", e)
|
||||||
resp("[]", 500, e.message ?: "")
|
resp("[]", 500, e.message ?: "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user