mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
feat.HTTP增加getImage接口
This commit is contained in:
@@ -3,6 +3,7 @@ package com.iguigui.maaj.routing
|
||||
import com.iguigui.maaj.dto.*
|
||||
import com.iguigui.maaj.service.MaaService
|
||||
import com.iguigui.maaj.service.MaaService.appendTask
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.request.*
|
||||
import io.ktor.server.response.*
|
||||
@@ -67,11 +68,10 @@ fun Application.httpRouting() {
|
||||
get("/getImage") {
|
||||
val id = call.request.queryParameters["id"]
|
||||
id?.let {
|
||||
|
||||
MaaService.getImage(it)
|
||||
MaaService.getImage(it)?.run {
|
||||
call.respondBytes(this, ContentType("image", "png"))
|
||||
}
|
||||
}
|
||||
call.response.headers
|
||||
//todo
|
||||
}
|
||||
post("/listInstance") {
|
||||
val list = MaaService.listInstance()
|
||||
|
||||
@@ -82,4 +82,16 @@ class MaaInstance(
|
||||
fun stop() = instance.AsstStop(pointer)
|
||||
fun destroy() = instance.AsstDestroy(pointer)
|
||||
|
||||
fun getImage(): ByteArray? {
|
||||
val size = 1024 * 1024 * 6
|
||||
val byteArray = ByteArray(size)
|
||||
val length = instance.AsstGetImage(pointer, byteArray, size.toLong())
|
||||
if (length == 0L) {
|
||||
return null
|
||||
}
|
||||
val target = ByteArray(length.toInt())
|
||||
System.arraycopy(byteArray,0,target,0,length.toInt())
|
||||
return target
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ object MaaService {
|
||||
val meoAssistant: MeoAssistant by lazy {
|
||||
var maaPath = File(File("").absolutePath).parent
|
||||
logger.info("maaPath $maaPath")
|
||||
// maaPath = "C:\\Users\\atmzx\\Desktop\\MeoAssistantArknights3"
|
||||
maaPath = "C:\\Users\\atmzx\\Desktop\\MeoAssistantArknights3"
|
||||
System.setProperty("jna.library.path", maaPath)
|
||||
val load = Native.load("MeoAssistant", MeoAssistant::class.java)
|
||||
load.AsstLoadResource(maaPath)
|
||||
@@ -95,7 +95,7 @@ object MaaService {
|
||||
this.wsConnection -= connection
|
||||
}
|
||||
|
||||
fun getImage(id: String) : ByteArray? {
|
||||
fun getImage(id: String): ByteArray? {
|
||||
return instancePool[id]?.getImage()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user