mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: fix #45
This commit is contained in:
parent
ba8322dc55
commit
f2dc3bc9fd
@ -98,16 +98,16 @@ internal abstract class IActionHandler {
|
||||
return failed(Status.BadParam, why, echo)
|
||||
}
|
||||
|
||||
protected fun error(why: String, echo: JsonElement): String {
|
||||
return failed(Status.InternalHandlerError, why, echo)
|
||||
protected fun error(why: String, echo: JsonElement, arrayResult: Boolean = false): String {
|
||||
return failed(Status.InternalHandlerError, why, echo, arrayResult)
|
||||
}
|
||||
|
||||
protected fun logic(why: String, echo: JsonElement): String {
|
||||
return failed(Status.LogicError, why, echo)
|
||||
protected fun logic(why: String, echo: JsonElement, arraayResult: Boolean = false): String {
|
||||
return failed(Status.LogicError, why, echo, arraayResult)
|
||||
}
|
||||
|
||||
protected fun failed(status: Status, msg: String, echo: JsonElement): String {
|
||||
return resultToString(false, status, EmptyObject, msg, echo = echo)
|
||||
protected fun failed(status: Status, msg: String, echo: JsonElement, arrResult: Boolean = false): String {
|
||||
return resultToString(false, status, if (arrResult) EmptyJsonArray else EmptyJsonObject, msg, echo = echo)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ internal object GetFriendList: IActionHandler() {
|
||||
|
||||
suspend operator fun invoke(refresh: Boolean, echo: JsonElement = EmptyJsonString): String {
|
||||
val friendList = FriendSvc.getFriendList(refresh).onFailure {
|
||||
return error(it.message ?: "unknown error", echo)
|
||||
return error(it.message ?: "unknown error", echo, arrayResult = true)
|
||||
}.getOrThrow()
|
||||
return ok(friendList.map { friend ->
|
||||
FriendEntry(
|
||||
|
@ -15,7 +15,7 @@ internal object GetOnlineClients: IActionHandler() {
|
||||
|
||||
suspend operator fun invoke(echo: JsonElement = EmptyJsonString): String {
|
||||
val clients = QSafeSvc.getOnlineClients()
|
||||
?: return logic("获取在线设备信息失败", echo)
|
||||
?: return logic("获取在线设备信息失败", echo, arraayResult = true)
|
||||
return ok(clients.map {
|
||||
DevInfo(it.iAppId, it.strDeviceName, it.strDeviceTypeInfo, it.iLoginTime,
|
||||
it.iLoginPlatform, it.strLoginLocation
|
||||
|
@ -16,7 +16,7 @@ internal object GetTroopList : IActionHandler() {
|
||||
suspend operator fun invoke(refresh: Boolean, echo: JsonElement = EmptyJsonString): String {
|
||||
val troopList = arrayListOf<SimpleTroopInfo>()
|
||||
GroupSvc.getGroupList(refresh).onFailure {
|
||||
return error(it.message ?: "unknown error", echo)
|
||||
return error(it.message ?: "unknown error", echo, arrayResult = true)
|
||||
}.onSuccess { troops ->
|
||||
troops.forEach { groupInfo ->
|
||||
if (groupInfo.troopcode.isNullOrEmpty()) return@forEach
|
||||
|
@ -23,7 +23,7 @@ internal object GetTroopMemberList : IActionHandler() {
|
||||
echo: JsonElement = EmptyJsonString
|
||||
): String {
|
||||
val memberList = GroupSvc.getGroupMemberList(groupId, refresh).onFailure {
|
||||
return error(it.message ?: "unknown error", echo)
|
||||
return error(it.message ?: "unknown error", echo, arrayResult = true)
|
||||
}.getOrThrow()
|
||||
|
||||
return ok(arrayListOf<SimpleTroopMemberInfo>().apply {
|
||||
|
@ -14,7 +14,8 @@ import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import kotlinx.serialization.json.long
|
||||
|
||||
val EmptyJsonObject = JsonObject(mapOf())
|
||||
val EmptyJsonObject = JsonObject(emptyMap())
|
||||
val EmptyJsonArray = JsonArray(emptyList())
|
||||
val EmptyJsonString = "".json
|
||||
|
||||
val GlobalJson = Json {
|
||||
|
Loading…
x
Reference in New Issue
Block a user