Maa HTTP Server

This commit is contained in:
guigui
2022-05-27 02:11:28 +08:00
parent 0376cd5d88
commit b356b4bc29
3 changed files with 16 additions and 18 deletions

View File

@@ -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")

View File

@@ -86,6 +86,7 @@ data class CallBackLog(
) : BaseData()
@Serializable
object EmptyBaseData : BaseData()
fun BaseData.toJsonElement() =

View File

@@ -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())
}
}
}
}