mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 09:50:40 +08:00
Maa HTTP Server
This commit is contained in:
@@ -20,8 +20,8 @@ data class ConnectRequest(
|
||||
|
||||
@Serializable
|
||||
data class AppendTaskRequest(
|
||||
@SerialName("host")
|
||||
val host: String,
|
||||
@SerialName("id")
|
||||
val id: String,
|
||||
@SerialName("type")
|
||||
val type: String,
|
||||
@SerialName("params")
|
||||
@@ -30,8 +30,8 @@ data class AppendTaskRequest(
|
||||
|
||||
@Serializable
|
||||
data class SetTaskParamsRequest(
|
||||
@SerialName("host")
|
||||
val host: String,
|
||||
@SerialName("id")
|
||||
val id: String,
|
||||
@SerialName("type")
|
||||
val type: String,
|
||||
@SerialName("taskId")
|
||||
@@ -146,14 +146,14 @@ data class Copilot(
|
||||
|
||||
@Serializable
|
||||
data class Start(
|
||||
@SerialName("host")
|
||||
val host: String
|
||||
@SerialName("id")
|
||||
val id: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Stop(
|
||||
@SerialName("host")
|
||||
val host: String
|
||||
@SerialName("id")
|
||||
val id: String,
|
||||
)
|
||||
|
||||
@SerialName("connect")
|
||||
|
||||
@@ -86,6 +86,7 @@ data class CallBackLog(
|
||||
) : BaseData()
|
||||
|
||||
|
||||
@Serializable
|
||||
object EmptyBaseData : BaseData()
|
||||
|
||||
fun BaseData.toJsonElement() =
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.ktor.server.application.*
|
||||
import io.ktor.server.request.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
|
||||
@@ -26,9 +27,9 @@ fun Application.httpRouting() {
|
||||
post("/appendTask") {
|
||||
with(call.receive<AppendTaskRequest>()) {
|
||||
MaaService.appendTask(
|
||||
host,
|
||||
id,
|
||||
type,
|
||||
params.jsonPrimitive.content
|
||||
params.jsonObject.toString()
|
||||
)
|
||||
}
|
||||
call.respond(EmptyBaseData.wapperToResponse())
|
||||
@@ -36,32 +37,28 @@ fun Application.httpRouting() {
|
||||
post("/setTaskParams") {
|
||||
with(call.receive<SetTaskParamsRequest>()) {
|
||||
MaaService.setTaskParams(
|
||||
host,
|
||||
id,
|
||||
type,
|
||||
taskId,
|
||||
params.jsonPrimitive.content
|
||||
params.jsonObject.toString()
|
||||
)
|
||||
}
|
||||
call.respond(EmptyBaseData.wapperToResponse())
|
||||
}
|
||||
post("/start") {
|
||||
val start = call.receive<Start>()
|
||||
MaaService.start(start.host)
|
||||
MaaService.start(start.id)
|
||||
call.respond(EmptyBaseData.wapperToResponse())
|
||||
}
|
||||
post("/stop") {
|
||||
val stop = call.receive<Stop>()
|
||||
MaaService.stop(stop.host)
|
||||
MaaService.stop(stop.id)
|
||||
call.respond(EmptyBaseData.wapperToResponse())
|
||||
}
|
||||
get("/listInstance") {
|
||||
val list = MaaService.listInstance()
|
||||
call.respond(ListInstance(list).wapperToResponse())
|
||||
}
|
||||
get("/getLog") {
|
||||
val list = MaaService.listInstance()
|
||||
call.respond(ListInstance(list).wapperToResponse())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user