[*] 日常优化

This commit is contained in:
acgist
2023-07-18 08:24:44 +08:00
parent 9f6fdd564d
commit 6f9b66cb6f
17 changed files with 720 additions and 699 deletions

View File

@@ -118,8 +118,11 @@ public final class NetUtils {
final InetAddress clientAddress = NetUtils.realAddress(clientIP); final InetAddress clientAddress = NetUtils.realAddress(clientIP);
final boolean sourceLocal = NetUtils.localAddress(sourceAddress); final boolean sourceLocal = NetUtils.localAddress(sourceAddress);
final boolean clientLocal = NetUtils.localAddress(clientAddress); final boolean clientLocal = NetUtils.localAddress(clientAddress);
// 内网服务 && 内网设备 // 内网服务 && 内网设备 => 重写服务地址
if(sourceLocal && clientLocal) { if(sourceLocal && clientLocal) {
if(NetUtils.subnetIP(sourceIP, clientIP)) {
return sourceIP;
}
final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream() final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream()
.filter(v -> NetUtils.subnetIP(v.getNetwork(), clientIP)) .filter(v -> NetUtils.subnetIP(v.getNetwork(), clientIP))
.findFirst() .findFirst()
@@ -127,11 +130,10 @@ public final class NetUtils {
if(rule == null) { if(rule == null) {
return sourceIP; return sourceIP;
} }
log.debug("地址重写:{} - {} - {}", sourceIP, clientIP, rule.getNetwork());
// 明确配置
if(StringUtils.isNotEmpty(rule.getInnerHost())) { if(StringUtils.isNotEmpty(rule.getInnerHost())) {
return rule.getInnerHost(); return rule.getInnerHost();
} }
log.debug("地址重写:{} - {} - {}", sourceIP, clientIP, rule.getNetwork());
// 地址 = 网络号 + 主机号 // 地址 = 网络号 + 主机号
final byte[] sourceBytes = sourceAddress.getAddress(); final byte[] sourceBytes = sourceAddress.getAddress();
final byte[] clientBytes = clientAddress.getAddress(); final byte[] clientBytes = clientAddress.getAddress();
@@ -151,7 +153,7 @@ public final class NetUtils {
return InetAddress.getByAddress(bytes).getHostAddress(); return InetAddress.getByAddress(bytes).getHostAddress();
} }
} }
// 内网服务 && 公网设备 // 内网服务 && 公网设备 => 公网服务地址
if(sourceLocal && !clientLocal) { if(sourceLocal && !clientLocal) {
final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream() final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream()
.filter(v -> NetUtils.subnetIP(v.getNetwork(), sourceIP)) .filter(v -> NetUtils.subnetIP(v.getNetwork(), sourceIP))
@@ -164,7 +166,7 @@ public final class NetUtils {
return rule.getOuterHost(); return rule.getOuterHost();
} }
} }
// 公网服务 && 内网设备 // 公网服务 && 内网设备 => 内网服务地址
if(!sourceLocal && clientLocal) { if(!sourceLocal && clientLocal) {
final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream() final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream()
.filter(v -> NetUtils.subnetIP(v.getNetwork(), clientIP)) .filter(v -> NetUtils.subnetIP(v.getNetwork(), clientIP))

View File

@@ -31,7 +31,7 @@ public class TaoyaoAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public SecurityService securityService( public SecurityService securityService(
SecurityProperties securityProperties, @Autowired(required = true) SecurityProperties securityProperties,
@Autowired(required = false) UsernamePasswordService usernamePasswordService @Autowired(required = false) UsernamePasswordService usernamePasswordService
) { ) {
return new SecurityServiceImpl(securityProperties, usernamePasswordService); return new SecurityServiceImpl(securityProperties, usernamePasswordService);

View File

@@ -5,8 +5,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.acgist.taoyao.boot.config.FfmpegProperties; import com.acgist.taoyao.boot.config.FfmpegProperties;
import com.acgist.taoyao.boot.config.RewriteProperties;
import com.acgist.taoyao.boot.config.MediaProperties; import com.acgist.taoyao.boot.config.MediaProperties;
import com.acgist.taoyao.boot.config.RewriteProperties;
import com.acgist.taoyao.boot.config.SocketProperties; import com.acgist.taoyao.boot.config.SocketProperties;
import com.acgist.taoyao.boot.config.WebrtcProperties; import com.acgist.taoyao.boot.config.WebrtcProperties;
import com.acgist.taoyao.boot.model.Message; import com.acgist.taoyao.boot.model.Message;

View File

@@ -17,6 +17,7 @@ import com.acgist.taoyao.signal.protocol.control.IControlPhotographProtocol;
import com.acgist.taoyao.signal.protocol.control.IControlServerRecordProtocol; import com.acgist.taoyao.signal.protocol.control.IControlServerRecordProtocol;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@@ -43,22 +44,13 @@ public class ControlController {
@Operation(summary = "响铃", description = "响铃控制") @Operation(summary = "响铃", description = "响铃控制")
@GetMapping("/bell/{clientId}") @GetMapping("/bell/{clientId}")
public Message bell(@PathVariable String clientId, @NotNull(message = "没有指定操作状态") Boolean enabled) { public Message bell(
@PathVariable String clientId,
@NotNull(message = "没有指定操作状态") Boolean enabled
) {
return this.controlBellProtocol.execute(clientId, enabled); return this.controlBellProtocol.execute(clientId, enabled);
} }
@Operation(summary = "录像", description = "终端录像控制")
@GetMapping("/client/record/{clientId}")
public Message record(@PathVariable String clientId, @NotNull(message = "没有指定操作状态") Boolean enabled) {
return this.controlClientRecordProtocol.execute(clientId, enabled);
}
@Operation(summary = "录像", description = "服务端录像控制")
@GetMapping("/server/record/{roomId}/{clientId}")
public Message record(@PathVariable String roomId, @PathVariable String clientId, @NotNull(message = "没有指定操作状态") Boolean enabled) {
return this.controlServerRecordProtocol.execute(roomId, clientId, enabled);
}
@Operation(summary = "拍照", description = "拍照控制") @Operation(summary = "拍照", description = "拍照控制")
@GetMapping("/photograph/{clientId}") @GetMapping("/photograph/{clientId}")
public Message photograph(@PathVariable String clientId) { public Message photograph(@PathVariable String clientId) {
@@ -67,14 +59,39 @@ public class ControlController {
@Operation(summary = "配置音频", description = "配置音频") @Operation(summary = "配置音频", description = "配置音频")
@GetMapping("/config/audio/{clientId}") @GetMapping("/config/audio/{clientId}")
public Message configAudio(@PathVariable String clientId, @Valid MediaAudioProperties mediaAudioProperties) { public Message configAudio(
@PathVariable String clientId,
@Valid @RequestBody MediaAudioProperties mediaAudioProperties
) {
return this.controlConfigAudioProtocol.execute(clientId, mediaAudioProperties); return this.controlConfigAudioProtocol.execute(clientId, mediaAudioProperties);
} }
@Operation(summary = "配置视频", description = "配置视频") @Operation(summary = "配置视频", description = "配置视频")
@GetMapping("/config/video/{clientId}") @GetMapping("/config/video/{clientId}")
public Message configVideo(@PathVariable String clientId, @Valid MediaVideoProperties mediaVideoProperties) { public Message configVideo(
@PathVariable String clientId,
@Valid @RequestBody MediaVideoProperties mediaVideoProperties
) {
return this.controlConfigVideoProtocol.execute(clientId, mediaVideoProperties); return this.controlConfigVideoProtocol.execute(clientId, mediaVideoProperties);
} }
@Operation(summary = "录像", description = "终端录像控制")
@GetMapping("/client/record/{clientId}")
public Message record(
@PathVariable String clientId,
@NotNull(message = "没有指定操作状态") Boolean enabled
) {
return this.controlClientRecordProtocol.execute(clientId, enabled);
}
@Operation(summary = "录像", description = "服务端录像控制")
@GetMapping("/server/record/{roomId}/{clientId}")
public Message record(
@PathVariable String roomId,
@PathVariable String clientId,
@NotNull(message = "没有指定操作状态") Boolean enabled
) {
return this.controlServerRecordProtocol.execute(roomId, clientId, enabled);
}
} }

View File

@@ -36,7 +36,10 @@ public class SecurityInterceptor extends InterceptorAdapter {
*/ */
private final AntPathMatcher matcher; private final AntPathMatcher matcher;
public SecurityInterceptor(SecurityService securityService, SecurityProperties securityProperties) { public SecurityInterceptor(
SecurityService securityService,
SecurityProperties securityProperties
) {
this.securityService = securityService; this.securityService = securityService;
this.securityProperties = securityProperties; this.securityProperties = securityProperties;
this.authenticate = "Basic Realm=\"" + this.securityProperties.getRealm() + "\""; this.authenticate = "Basic Realm=\"" + this.securityProperties.getRealm() + "\"";

View File

@@ -50,9 +50,8 @@ public class SlowInterceptor extends InterceptorAdapter {
@Override @Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) throws Exception { public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) throws Exception {
final long duration; final long duration = System.currentTimeMillis() - this.local.get();
final Long last = this.local.get(); if(duration > this.taoyaoProperties.getTimeout()) {
if(last != null && (duration = System.currentTimeMillis() - last) > this.taoyaoProperties.getTimeout()) {
log.info("请求执行时间过慢:{} - {}", request.getRequestURI(), duration); log.info("请求执行时间过慢:{} - {}", request.getRequestURI(), duration);
} }
this.local.remove(); this.local.remove();