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/> <relativePath/>
</parent> </parent>
<groupId>net.geedge</groupId> <groupId>net.geedge</groupId>
<artifactId>device-api</artifactId> <artifactId>env-api</artifactId>
<version>1.0</version> <version>1.0</version>
<name>device-api</name> <name>env-api</name>
<description>AppSketch Works Device API</description> <description>AppSketch Works Env API</description>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
@@ -94,7 +94,7 @@
<archive> <archive>
<manifest> <manifest>
<mainClass> <mainClass>
net.geedge.DeviceApiApplication net.geedge.EnvApiApplication
</mainClass> </mainClass>
</manifest> </manifest>
</archive> </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; package net.geedge.api.config;
import cn.hutool.log.Log; import cn.hutool.log.Log;
import net.geedge.api.entity.DeviceApiYml; import net.geedge.api.entity.EnvApiYml;
import net.geedge.common.T; import net.geedge.common.T;
import org.springframework.web.socket.BinaryMessage; import org.springframework.web.socket.BinaryMessage;
import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.CloseStatus;
@@ -17,9 +17,9 @@ public class VncProxyHandler extends TextWebSocketHandler {
private static final Log log = Log.get(); 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; this.vnc = vnc;
} }

View File

@@ -1,6 +1,6 @@
package net.geedge.api.config; 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.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket; 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 { public class WebSocketConfig implements WebSocketConfigurer {
@Autowired @Autowired
private DeviceApiYml deviceApiYml; private EnvApiYml envApiYml;
@Override @Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { 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 cn.hutool.core.codec.Base32Codec;
import jakarta.servlet.http.HttpServletResponse; 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.api.util.AdbUtil;
import net.geedge.common.*; import net.geedge.common.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -15,14 +15,14 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@RequestMapping("/api/v1/device") @RequestMapping("/api/v1/env")
public class APIController { public class APIController {
private final AdbUtil adbUtil; private final AdbUtil adbUtil;
@Autowired @Autowired
public APIController(DeviceApiYml deviceApiYml) { public APIController(EnvApiYml envApiYml) {
this.adbUtil = AdbUtil.getInstance(deviceApiYml.getAdb()); this.adbUtil = AdbUtil.getInstance(envApiYml.getAdb());
} }
@GetMapping("/status") @GetMapping("/status")

View File

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

View File

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

View File

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

View File

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