[*] 日常优化
This commit is contained in:
@@ -118,8 +118,11 @@ public final class NetUtils {
|
||||
final InetAddress clientAddress = NetUtils.realAddress(clientIP);
|
||||
final boolean sourceLocal = NetUtils.localAddress(sourceAddress);
|
||||
final boolean clientLocal = NetUtils.localAddress(clientAddress);
|
||||
// 内网服务 && 内网设备
|
||||
// 内网服务 && 内网设备 => 重写服务地址
|
||||
if(sourceLocal && clientLocal) {
|
||||
if(NetUtils.subnetIP(sourceIP, clientIP)) {
|
||||
return sourceIP;
|
||||
}
|
||||
final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream()
|
||||
.filter(v -> NetUtils.subnetIP(v.getNetwork(), clientIP))
|
||||
.findFirst()
|
||||
@@ -127,11 +130,10 @@ public final class NetUtils {
|
||||
if(rule == null) {
|
||||
return sourceIP;
|
||||
}
|
||||
log.debug("地址重写:{} - {} - {}", sourceIP, clientIP, rule.getNetwork());
|
||||
// 明确配置
|
||||
if(StringUtils.isNotEmpty(rule.getInnerHost())) {
|
||||
return rule.getInnerHost();
|
||||
}
|
||||
log.debug("地址重写:{} - {} - {}", sourceIP, clientIP, rule.getNetwork());
|
||||
// 地址 = 网络号 + 主机号
|
||||
final byte[] sourceBytes = sourceAddress.getAddress();
|
||||
final byte[] clientBytes = clientAddress.getAddress();
|
||||
@@ -151,7 +153,7 @@ public final class NetUtils {
|
||||
return InetAddress.getByAddress(bytes).getHostAddress();
|
||||
}
|
||||
}
|
||||
// 内网服务 && 公网设备
|
||||
// 内网服务 && 公网设备 => 公网服务地址
|
||||
if(sourceLocal && !clientLocal) {
|
||||
final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream()
|
||||
.filter(v -> NetUtils.subnetIP(v.getNetwork(), sourceIP))
|
||||
@@ -164,7 +166,7 @@ public final class NetUtils {
|
||||
return rule.getOuterHost();
|
||||
}
|
||||
}
|
||||
// 公网服务 && 内网设备
|
||||
// 公网服务 && 内网设备 => 内网服务地址
|
||||
if(!sourceLocal && clientLocal) {
|
||||
final RewriteRuleProperties rule = NetUtils.rewriteProperties.getRule().stream()
|
||||
.filter(v -> NetUtils.subnetIP(v.getNetwork(), clientIP))
|
||||
|
||||
@@ -31,7 +31,7 @@ public class TaoyaoAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SecurityService securityService(
|
||||
SecurityProperties securityProperties,
|
||||
@Autowired(required = true) SecurityProperties securityProperties,
|
||||
@Autowired(required = false) UsernamePasswordService usernamePasswordService
|
||||
) {
|
||||
return new SecurityServiceImpl(securityProperties, usernamePasswordService);
|
||||
|
||||
@@ -5,8 +5,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
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.RewriteProperties;
|
||||
import com.acgist.taoyao.boot.config.SocketProperties;
|
||||
import com.acgist.taoyao.boot.config.WebrtcProperties;
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.acgist.taoyao.signal.protocol.control.IControlPhotographProtocol;
|
||||
import com.acgist.taoyao.signal.protocol.control.IControlServerRecordProtocol;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -43,22 +44,13 @@ public class ControlController {
|
||||
|
||||
@Operation(summary = "响铃", description = "响铃控制")
|
||||
@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);
|
||||
}
|
||||
|
||||
@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 = "拍照控制")
|
||||
@GetMapping("/photograph/{clientId}")
|
||||
public Message photograph(@PathVariable String clientId) {
|
||||
@@ -67,14 +59,39 @@ public class ControlController {
|
||||
|
||||
@Operation(summary = "配置音频", description = "配置音频")
|
||||
@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);
|
||||
}
|
||||
|
||||
@Operation(summary = "配置视频", description = "配置视频")
|
||||
@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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,10 @@ public class SecurityInterceptor extends InterceptorAdapter {
|
||||
*/
|
||||
private final AntPathMatcher matcher;
|
||||
|
||||
public SecurityInterceptor(SecurityService securityService, SecurityProperties securityProperties) {
|
||||
public SecurityInterceptor(
|
||||
SecurityService securityService,
|
||||
SecurityProperties securityProperties
|
||||
) {
|
||||
this.securityService = securityService;
|
||||
this.securityProperties = securityProperties;
|
||||
this.authenticate = "Basic Realm=\"" + this.securityProperties.getRealm() + "\"";
|
||||
|
||||
@@ -50,9 +50,8 @@ public class SlowInterceptor extends InterceptorAdapter {
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) throws Exception {
|
||||
final long duration;
|
||||
final Long last = this.local.get();
|
||||
if(last != null && (duration = System.currentTimeMillis() - last) > this.taoyaoProperties.getTimeout()) {
|
||||
final long duration = System.currentTimeMillis() - this.local.get();
|
||||
if(duration > this.taoyaoProperties.getTimeout()) {
|
||||
log.info("请求执行时间过慢:{} - {}", request.getRequestURI(), duration);
|
||||
}
|
||||
this.local.remove();
|
||||
|
||||
Reference in New Issue
Block a user