feat.HTTP增加getImage接口

This commit is contained in:
guigui
2022-06-03 01:14:43 +08:00
parent 4a4e83d1ae
commit 5f0f04986e
3 changed files with 18 additions and 6 deletions

View File

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

View File

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

View File

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