Shamrock: fix #45

This commit is contained in:
WhiteChi 2023-11-16 11:23:31 +08:00
parent ba8322dc55
commit f2dc3bc9fd
6 changed files with 12 additions and 11 deletions

View File

@ -98,16 +98,16 @@ internal abstract class IActionHandler {
return failed(Status.BadParam, why, echo) return failed(Status.BadParam, why, echo)
} }
protected fun error(why: String, echo: JsonElement): String { protected fun error(why: String, echo: JsonElement, arrayResult: Boolean = false): String {
return failed(Status.InternalHandlerError, why, echo) return failed(Status.InternalHandlerError, why, echo, arrayResult)
} }
protected fun logic(why: String, echo: JsonElement): String { protected fun logic(why: String, echo: JsonElement, arraayResult: Boolean = false): String {
return failed(Status.LogicError, why, echo) return failed(Status.LogicError, why, echo, arraayResult)
} }
protected fun failed(status: Status, msg: String, echo: JsonElement): String { protected fun failed(status: Status, msg: String, echo: JsonElement, arrResult: Boolean = false): String {
return resultToString(false, status, EmptyObject, msg, echo = echo) return resultToString(false, status, if (arrResult) EmptyJsonArray else EmptyJsonObject, msg, echo = echo)
} }
} }

View File

@ -16,7 +16,7 @@ internal object GetFriendList: IActionHandler() {
suspend operator fun invoke(refresh: Boolean, echo: JsonElement = EmptyJsonString): String { suspend operator fun invoke(refresh: Boolean, echo: JsonElement = EmptyJsonString): String {
val friendList = FriendSvc.getFriendList(refresh).onFailure { val friendList = FriendSvc.getFriendList(refresh).onFailure {
return error(it.message ?: "unknown error", echo) return error(it.message ?: "unknown error", echo, arrayResult = true)
}.getOrThrow() }.getOrThrow()
return ok(friendList.map { friend -> return ok(friendList.map { friend ->
FriendEntry( FriendEntry(

View File

@ -15,7 +15,7 @@ internal object GetOnlineClients: IActionHandler() {
suspend operator fun invoke(echo: JsonElement = EmptyJsonString): String { suspend operator fun invoke(echo: JsonElement = EmptyJsonString): String {
val clients = QSafeSvc.getOnlineClients() val clients = QSafeSvc.getOnlineClients()
?: return logic("获取在线设备信息失败", echo) ?: return logic("获取在线设备信息失败", echo, arraayResult = true)
return ok(clients.map { return ok(clients.map {
DevInfo(it.iAppId, it.strDeviceName, it.strDeviceTypeInfo, it.iLoginTime, DevInfo(it.iAppId, it.strDeviceName, it.strDeviceTypeInfo, it.iLoginTime,
it.iLoginPlatform, it.strLoginLocation it.iLoginPlatform, it.strLoginLocation

View File

@ -16,7 +16,7 @@ internal object GetTroopList : IActionHandler() {
suspend operator fun invoke(refresh: Boolean, echo: JsonElement = EmptyJsonString): String { suspend operator fun invoke(refresh: Boolean, echo: JsonElement = EmptyJsonString): String {
val troopList = arrayListOf<SimpleTroopInfo>() val troopList = arrayListOf<SimpleTroopInfo>()
GroupSvc.getGroupList(refresh).onFailure { GroupSvc.getGroupList(refresh).onFailure {
return error(it.message ?: "unknown error", echo) return error(it.message ?: "unknown error", echo, arrayResult = true)
}.onSuccess { troops -> }.onSuccess { troops ->
troops.forEach { groupInfo -> troops.forEach { groupInfo ->
if (groupInfo.troopcode.isNullOrEmpty()) return@forEach if (groupInfo.troopcode.isNullOrEmpty()) return@forEach

View File

@ -23,7 +23,7 @@ internal object GetTroopMemberList : IActionHandler() {
echo: JsonElement = EmptyJsonString echo: JsonElement = EmptyJsonString
): String { ): String {
val memberList = GroupSvc.getGroupMemberList(groupId, refresh).onFailure { val memberList = GroupSvc.getGroupMemberList(groupId, refresh).onFailure {
return error(it.message ?: "unknown error", echo) return error(it.message ?: "unknown error", echo, arrayResult = true)
}.getOrThrow() }.getOrThrow()
return ok(arrayListOf<SimpleTroopMemberInfo>().apply { return ok(arrayListOf<SimpleTroopMemberInfo>().apply {

View File

@ -14,7 +14,8 @@ import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive import kotlinx.serialization.json.jsonPrimitive
import kotlinx.serialization.json.long import kotlinx.serialization.json.long
val EmptyJsonObject = JsonObject(mapOf()) val EmptyJsonObject = JsonObject(emptyMap())
val EmptyJsonArray = JsonArray(emptyList())
val EmptyJsonString = "".json val EmptyJsonString = "".json
val GlobalJson = Json { val GlobalJson = Json {