清理代码;新增远程共育室公开接口
This commit is contained in:
@@ -5,6 +5,7 @@ import ink.snowflake.server.controller.User
|
||||
import ink.snowflake.server.controller.chat
|
||||
import ink.snowflake.server.utils.plugins.configureSockets
|
||||
import ink.snowflake.server.controller.ImageAnalytics
|
||||
import ink.snowflake.server.controller.Public
|
||||
import ink.snowflake.server.controller.RemoteDebug
|
||||
import ink.snowflake.server.controller.Traceability
|
||||
import ink.snowflake.server.controller.VideoAnalytics
|
||||
@@ -18,6 +19,7 @@ import ink.snowflake.server.utils.plugins.configureSerialization
|
||||
import ink.snowflake.server.utils.plugins.configureStaticPath
|
||||
import ink.snowflake.server.utils.plugins.configureStatusPages
|
||||
import ink.snowflake.server.utils.plugins.configureTemplating
|
||||
import io.ktor.http.CacheControl
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.tomcat.jakarta.*
|
||||
|
||||
@@ -76,4 +78,6 @@ fun Application.module() {
|
||||
// 业务-图片分析
|
||||
ImageAnalytics()
|
||||
Traceability(appConfig)
|
||||
// 业务-公开接口
|
||||
Public()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package ink.snowflake.server.controller
|
||||
|
||||
import ink.snowflake.server.SERVER_PATH_FRP
|
||||
import ink.snowflake.server.model.response.BaseResponse
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.server.routing.route
|
||||
import io.ktor.server.routing.routing
|
||||
|
||||
|
||||
fun Application.Public() {
|
||||
routing {
|
||||
route("/silk-remote") {
|
||||
get("/connectLocalDevice") {
|
||||
val port = call.parameters["port"]
|
||||
if (port != null) {
|
||||
runAdbCommand("disconnect")
|
||||
runAdbCommand("connect ${SERVER_PATH_FRP}:$port")
|
||||
val url =
|
||||
"https://ai.ronsunny.cn:8090/remote#!action=stream&udid=s3.ronsunny.cn%3ATTT&player=mse&ws=wss%3A%2F%2Fai.ronsunny.cn%3A8090%2Fremote%3Faction%3Dproxy-adb%26remote%3Dtcp%253A8886%26udid%3Ds3.ronsunny.cn%253ATTT"
|
||||
.replace(
|
||||
"TTT",
|
||||
port
|
||||
)
|
||||
call.respond(BaseResponse(data = url))
|
||||
} else {
|
||||
call.respond(BaseResponse(status = false, message = "IP或端口无效", data = null))
|
||||
}
|
||||
}
|
||||
get("/disConnectAll") {
|
||||
val result = runAdbCommand("disconnect")
|
||||
call.respond(BaseResponse(data = result))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,65 +40,66 @@ fun Application.RemoteDebug() {
|
||||
}
|
||||
}
|
||||
routing {
|
||||
authenticate {
|
||||
route("/remote") {
|
||||
get("/connect") {
|
||||
val ip = call.parameters["ip"]
|
||||
val port = call.parameters["port"]
|
||||
if (ip != null && port != null) {
|
||||
val result = runAdbCommand("connect $ip:$port")
|
||||
call.respond(BaseResponse(data = result))
|
||||
} else {
|
||||
call.respond(BaseResponse(status = false, message = "IP或端口无效", data = null))
|
||||
}
|
||||
}
|
||||
get("/connectLocalDevice") {
|
||||
val port = call.parameters["port"]
|
||||
if (port != null) {
|
||||
val result = runAdbCommand("connect ${SERVER_PATH_FRP}:$port")
|
||||
call.respond(BaseResponse(data = result))
|
||||
} else {
|
||||
call.respond(BaseResponse(status = false, message = "IP或端口无效", data = null))
|
||||
}
|
||||
}
|
||||
get("/disConnectAll") {
|
||||
val result = runAdbCommand("disconnect")
|
||||
authenticate {
|
||||
route("/remote") {
|
||||
get("/connect") {
|
||||
val ip = call.parameters["ip"]
|
||||
val port = call.parameters["port"]
|
||||
if (ip != null && port != null) {
|
||||
val result = runAdbCommand("connect $ip:$port")
|
||||
call.respond(BaseResponse(data = result))
|
||||
}
|
||||
get("/runLinuxCommand") {
|
||||
val command = call.parameters["command"]
|
||||
if (command != null) {
|
||||
call.respond(BaseResponse(data = runCommand(command)))
|
||||
} else {
|
||||
call.respond(BaseResponse(status = false, message = "Linux命令不可为空", data = null))
|
||||
}
|
||||
}
|
||||
get("/refreshDeviceList") {
|
||||
try {
|
||||
val name = call.parameters["name"]
|
||||
val response: HttpResponse = client.get("http://${SERVER_PATH_FRP}:65534/api/proxy/tcp")
|
||||
val responseBody: String = response.bodyAsText()
|
||||
val devicesInfoRequest: DevicesInfoRequest = Gson().fromJson(responseBody, DevicesInfoRequest::class.java)
|
||||
val onlineDevices = devicesInfoRequest.proxies.stream()
|
||||
.filter { it.status == "online" && it.conf != null && it.conf.remotePort >= 10000 && it.conf.remotePort <= 20000 }
|
||||
val devices: MutableList<DeviceItemResponse> = mutableListOf()
|
||||
for (data in onlineDevices) {
|
||||
if (name == "null" || name == null || data.name.contains(name) && data.conf != null) {
|
||||
devices.add(DeviceItemResponse(data.name, data.conf!!.remotePort))
|
||||
}
|
||||
}
|
||||
call.respond(BaseResponse(data = devices))
|
||||
} catch (e: Exception) {
|
||||
call.respond(
|
||||
BaseResponse(
|
||||
status = false,
|
||||
message = "端口信息请求失败:${e.message}",
|
||||
data = null
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
call.respond(BaseResponse(status = false, message = "IP或端口无效", data = null))
|
||||
}
|
||||
}
|
||||
get("/connectLocalDevice") {
|
||||
val port = call.parameters["port"]
|
||||
if (port != null) {
|
||||
val result = runAdbCommand("connect ${SERVER_PATH_FRP}:$port")
|
||||
call.respond(BaseResponse(data = result))
|
||||
} else {
|
||||
call.respond(BaseResponse(status = false, message = "IP或端口无效", data = null))
|
||||
}
|
||||
}
|
||||
get("/disConnectAll") {
|
||||
val result = runAdbCommand("disconnect")
|
||||
call.respond(BaseResponse(data = result))
|
||||
}
|
||||
get("/runLinuxCommand") {
|
||||
val command = call.parameters["command"]
|
||||
if (command != null) {
|
||||
call.respond(BaseResponse(data = runCommand(command)))
|
||||
} else {
|
||||
call.respond(BaseResponse(status = false, message = "Linux命令不可为空", data = null))
|
||||
}
|
||||
}
|
||||
get("/refreshDeviceList") {
|
||||
try {
|
||||
val name = call.parameters["name"]
|
||||
val response: HttpResponse = client.get("http://${SERVER_PATH_FRP}:65534/api/proxy/tcp")
|
||||
val responseBody: String = response.bodyAsText()
|
||||
val devicesInfoRequest: DevicesInfoRequest =
|
||||
Gson().fromJson(responseBody, DevicesInfoRequest::class.java)
|
||||
val onlineDevices = devicesInfoRequest.proxies.stream()
|
||||
.filter { it.status == "online" && it.conf != null && it.conf.remotePort >= 10000 && it.conf.remotePort <= 20000 }
|
||||
val devices: MutableList<DeviceItemResponse> = mutableListOf()
|
||||
for (data in onlineDevices) {
|
||||
if (name == "null" || name == null || data.name.contains(name) && data.conf != null) {
|
||||
devices.add(DeviceItemResponse(data.name, data.conf!!.remotePort))
|
||||
}
|
||||
}
|
||||
call.respond(BaseResponse(data = devices))
|
||||
} catch (e: Exception) {
|
||||
call.respond(
|
||||
BaseResponse(
|
||||
status = false,
|
||||
message = "端口信息请求失败:${e.message}",
|
||||
data = null
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
webSocket("/logStream") {
|
||||
send("日志系统连接成功")
|
||||
|
||||
Reference in New Issue
Block a user