mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
Maa HTTP Server
This commit is contained in:
@@ -13,7 +13,9 @@ data class ConnectRequest(
|
||||
@SerialName("adbPath")
|
||||
val adbPath: String,
|
||||
@SerialName("host")
|
||||
val host: String
|
||||
val host: String,
|
||||
@SerialName("detailJson")
|
||||
val detailJson: String = ""
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
||||
@@ -10,7 +10,7 @@ import kotlinx.serialization.json.jsonObject
|
||||
|
||||
@Serializable
|
||||
data class HttpResponse(
|
||||
@SerialName("version")
|
||||
@SerialName("data")
|
||||
val data: JsonElement = EmptyBaseData.toJsonElement(),
|
||||
@SerialName("code")
|
||||
val code: Int = 0,
|
||||
@@ -42,7 +42,9 @@ data class GetVersion(
|
||||
@Serializable
|
||||
data class ConnectResponse(
|
||||
@SerialName("id")
|
||||
val id: String
|
||||
val id: String,
|
||||
@SerialName("result")
|
||||
val result: Boolean
|
||||
) : BaseData()
|
||||
|
||||
|
||||
@@ -84,8 +86,6 @@ data class CallBackLog(
|
||||
) : BaseData()
|
||||
|
||||
|
||||
|
||||
|
||||
object EmptyBaseData : BaseData()
|
||||
|
||||
fun BaseData.toJsonElement() =
|
||||
|
||||
@@ -18,9 +18,10 @@ fun Application.httpRouting() {
|
||||
call.respond(GetVersion(version).wapperToResponse())
|
||||
}
|
||||
post("/connect") {
|
||||
val connect = call.receive<ConnectRequest>()
|
||||
val id = MaaService.connect(connect.adbPath, connect.host, "")
|
||||
call.respond(HttpResponse(ConnectResponse(id).toJsonElement()))
|
||||
with(call.receive<ConnectRequest>()) {
|
||||
val connect = MaaService.connect(adbPath, host, detailJson)
|
||||
call.respond(HttpResponse(connect.toJsonElement()))
|
||||
}
|
||||
}
|
||||
post("/appendTask") {
|
||||
with(call.receive<AppendTaskRequest>()) {
|
||||
|
||||
@@ -11,7 +11,13 @@ import java.util.concurrent.LinkedBlockingQueue
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
|
||||
class MaaInstance(private val instance: MeoAssistant, val id: String, val adbPath: String, val host: String) :
|
||||
class MaaInstance(
|
||||
private val instance: MeoAssistant,
|
||||
val id: String,
|
||||
val adbPath: String,
|
||||
val host: String,
|
||||
val detailJson: String
|
||||
) :
|
||||
MeoAssistant.AsstApiCallback {
|
||||
|
||||
constructor(
|
||||
@@ -19,12 +25,14 @@ class MaaInstance(private val instance: MeoAssistant, val id: String, val adbPat
|
||||
id: String,
|
||||
adbPath: String,
|
||||
host: String,
|
||||
pointer: Pointer
|
||||
pointer: Pointer,
|
||||
detailJson: String
|
||||
) : this(
|
||||
instance,
|
||||
id,
|
||||
adbPath,
|
||||
host
|
||||
host,
|
||||
detailJson
|
||||
) {
|
||||
this.pointer = pointer
|
||||
}
|
||||
@@ -43,7 +51,7 @@ class MaaInstance(private val instance: MeoAssistant, val id: String, val adbPat
|
||||
logQueue.offer(CallBackLog(id, msgId.getAndIncrement(), msg, Json.parseToJsonElement(detail_json)))
|
||||
}
|
||||
|
||||
fun connect(): Boolean = instance.AsstConnect(pointer, adbPath, host, "");
|
||||
fun connect(): Boolean = instance.AsstConnect(pointer, adbPath, host, detailJson)
|
||||
|
||||
fun appendTask(type: String, params: String) = instance.AsstAppendTask(pointer, type, params)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.iguigui.maaj.service
|
||||
|
||||
import com.iguigui.maaj.dto.ConnectResponse
|
||||
import com.iguigui.maaj.dto.MaaInstanceInfo
|
||||
import com.iguigui.maaj.easySample.MeoAssistant
|
||||
import com.sun.jna.Native
|
||||
@@ -23,15 +24,19 @@ object MaaService {
|
||||
load
|
||||
}
|
||||
|
||||
fun connect(adbPath: String, host: String, detailJson: String): String {
|
||||
if (instancePool.containsKey(host)) {
|
||||
return sha1(host)
|
||||
fun connect(adbPath: String, host: String, detailJson: String): ConnectResponse {
|
||||
val id = sha1(host)
|
||||
if (instancePool.containsKey(id)) {
|
||||
return ConnectResponse(id,true)
|
||||
}
|
||||
val maaInstance = MaaInstance(meoAssistant, host, adbPath, host)
|
||||
val maaInstance = MaaInstance(meoAssistant, host, adbPath, host, detailJson)
|
||||
maaInstance.pointer = meoAssistant.AsstCreateEx(maaInstance, maaInstance.id)
|
||||
maaInstance.connect()
|
||||
instancePool.putIfAbsent(host, maaInstance)
|
||||
return sha1(host)
|
||||
val connect = maaInstance.connect()
|
||||
if (!connect) {
|
||||
return ConnectResponse("",false)
|
||||
}
|
||||
instancePool.putIfAbsent(id, maaInstance)
|
||||
return ConnectResponse(id,true)
|
||||
}
|
||||
|
||||
fun appendTask(host: String, type: String, detailJson: String) =
|
||||
|
||||
Reference in New Issue
Block a user