improvement: device 更名为 env

This commit is contained in:
shizhendong
2024-09-04 14:19:02 +08:00
parent 41ba204ee6
commit c861efd75d
10 changed files with 70 additions and 70 deletions

View File

@@ -9,10 +9,10 @@
<relativePath/>
</parent>
<groupId>net.geedge</groupId>
<artifactId>device-api</artifactId>
<artifactId>env-api</artifactId>
<version>1.0</version>
<name>device-api</name>
<description>AppSketch Works Device API</description>
<name>env-api</name>
<description>AppSketch Works Env API</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
@@ -94,7 +94,7 @@
<archive>
<manifest>
<mainClass>
net.geedge.DeviceApiApplication
net.geedge.EnvApiApplication
</mainClass>
</manifest>
</archive>

View File

@@ -1,48 +0,0 @@
package net.geedge;
import cn.hutool.extra.spring.EnableSpringUtil;
import net.geedge.api.entity.DeviceApiYml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import java.util.TimeZone;
@EnableSpringUtil
@SpringBootApplication
public class DeviceApiApplication {
public static void main(String[] args) {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
SpringApplication.run(DeviceApiApplication.class, args);
}
@Autowired
private Environment env;
@Bean
public DeviceApiYml deviceProperties() {
DeviceApiYml apiYml = new DeviceApiYml();
DeviceApiYml.Device device = apiYml.new Device();
device.setRoot(env.getProperty("device.root"));
device.setType(env.getProperty("device.type"));
device.setPlatform(env.getProperty("device.platform"));
DeviceApiYml.Adb adb = apiYml.new Adb();
adb.setSerial(env.getProperty("adb.serial"));
adb.setHost(env.getProperty("adb.host"));
adb.setPort(env.getProperty("adb.port", Integer.class));
DeviceApiYml.Vnc vnc = apiYml.new Vnc();
vnc.setHost(env.getProperty("vnc.host"));
vnc.setPort(env.getProperty("vnc.port", Integer.class));
apiYml.setDevice(device);
apiYml.setAdb(adb);
apiYml.setVnc(vnc);
return apiYml;
}
}

View File

@@ -0,0 +1,48 @@
package net.geedge;
import cn.hutool.extra.spring.EnableSpringUtil;
import net.geedge.api.entity.EnvApiYml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import java.util.TimeZone;
@EnableSpringUtil
@SpringBootApplication
public class EnvApiApplication {
public static void main(String[] args) {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
SpringApplication.run(EnvApiApplication.class, args);
}
@Autowired
private Environment environment;
@Bean
public EnvApiYml envProperties() {
EnvApiYml apiYml = new EnvApiYml();
EnvApiYml.Env envEntity = apiYml.new Env();
envEntity.setRoot(environment.getProperty("env.root"));
envEntity.setType(environment.getProperty("env.type"));
envEntity.setPlatform(environment.getProperty("env.platform"));
EnvApiYml.Adb adb = apiYml.new Adb();
adb.setSerial(environment.getProperty("adb.serial"));
adb.setHost(environment.getProperty("adb.host"));
adb.setPort(environment.getProperty("adb.port", Integer.class));
EnvApiYml.Vnc vnc = apiYml.new Vnc();
vnc.setHost(environment.getProperty("vnc.host"));
vnc.setPort(environment.getProperty("vnc.port", Integer.class));
apiYml.setEnv(envEntity);
apiYml.setAdb(adb);
apiYml.setVnc(vnc);
return apiYml;
}
}

View File

@@ -1,7 +1,7 @@
package net.geedge.api.config;
import cn.hutool.log.Log;
import net.geedge.api.entity.DeviceApiYml;
import net.geedge.api.entity.EnvApiYml;
import net.geedge.common.T;
import org.springframework.web.socket.BinaryMessage;
import org.springframework.web.socket.CloseStatus;
@@ -17,9 +17,9 @@ public class VncProxyHandler extends TextWebSocketHandler {
private static final Log log = Log.get();
private DeviceApiYml.Vnc vnc;
private EnvApiYml.Vnc vnc;
public VncProxyHandler(DeviceApiYml.Vnc vnc) {
public VncProxyHandler(EnvApiYml.Vnc vnc) {
this.vnc = vnc;
}

View File

@@ -1,6 +1,6 @@
package net.geedge.api.config;
import net.geedge.api.entity.DeviceApiYml;
import net.geedge.api.entity.EnvApiYml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
@@ -12,10 +12,10 @@ import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry
public class WebSocketConfig implements WebSocketConfigurer {
@Autowired
private DeviceApiYml deviceApiYml;
private EnvApiYml envApiYml;
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(new VncProxyHandler(deviceApiYml.getVnc()), "/api/v1/device/websocket").setAllowedOrigins("*");
registry.addHandler(new VncProxyHandler(envApiYml.getVnc()), "/api/v1/env/websocket").setAllowedOrigins("*");
}
}

View File

@@ -2,7 +2,7 @@ package net.geedge.api.controller;
import cn.hutool.core.codec.Base32Codec;
import jakarta.servlet.http.HttpServletResponse;
import net.geedge.api.entity.DeviceApiYml;
import net.geedge.api.entity.EnvApiYml;
import net.geedge.api.util.AdbUtil;
import net.geedge.common.*;
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,14 +15,14 @@ import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/v1/device")
@RequestMapping("/api/v1/env")
public class APIController {
private final AdbUtil adbUtil;
@Autowired
public APIController(DeviceApiYml deviceApiYml) {
this.adbUtil = AdbUtil.getInstance(deviceApiYml.getAdb());
public APIController(EnvApiYml envApiYml) {
this.adbUtil = AdbUtil.getInstance(envApiYml.getAdb());
}
@GetMapping("/status")

View File

@@ -3,14 +3,14 @@ package net.geedge.api.entity;
import lombok.Data;
@Data
public class DeviceApiYml {
public class EnvApiYml {
private Device device;
private Env env;
private Adb adb;
private Vnc vnc;
@Data
public class Device {
public class Env {
String type;
String platform;
String root;

View File

@@ -3,7 +3,7 @@ package net.geedge.api.util;
import cn.hutool.core.codec.Base32Codec;
import cn.hutool.core.thread.NamedThreadFactory;
import cn.hutool.log.Log;
import net.geedge.api.entity.DeviceApiYml;
import net.geedge.api.entity.EnvApiYml;
import net.geedge.common.APIException;
import net.geedge.common.Constant;
import net.geedge.common.RCode;
@@ -38,7 +38,7 @@ public class AdbUtil {
public record CommandResult(Integer exitCode, String output) {
}
private AdbUtil(DeviceApiYml.Adb adb) {
private AdbUtil(EnvApiYml.Adb adb) {
this.serial = T.StrUtil.emptyToDefault(adb.getSerial(), "");
this.host = adb.getHost();
this.port = adb.getPort();
@@ -48,7 +48,7 @@ public class AdbUtil {
this.init();
}
public static AdbUtil getInstance(DeviceApiYml.Adb connInfo) {
public static AdbUtil getInstance(EnvApiYml.Adb connInfo) {
if (instance == null) {
synchronized (AdbUtil.class) {
if (instance == null) {

View File

@@ -20,7 +20,7 @@ public class TokenInterceptor implements WebMvcConfigurer {
private static String tokenValue;
@Value("${device.tokenFile:config/token.auth}")
@Value("${env.tokenFile:config/token.auth}")
protected String tokenFile;

View File

@@ -8,5 +8,5 @@ spring:
max-request-size: 500MB
enabled: true
device:
env:
tokenFile: ./config/token.auth