暂存提交
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(scanBasePackages = {"com.baiyue.integration", "com.baiyue.common.web"})
|
||||
@ConfigurationPropertiesScan
|
||||
public class IntegrationServiceApplication {
|
||||
public static void main(String[] args) {
|
||||
|
||||
+58
-2
@@ -1,12 +1,68 @@
|
||||
package com.baiyue.integration.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.util.unit.DataSize;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
|
||||
@ConfigurationProperties(prefix = "baiyue.integration")
|
||||
public record IntegrationProperties(BaiduOcr baiduOcr, AmazonSpApi amazonSpApi) {
|
||||
public record BaiduOcr(boolean enabled, String apiKey, String secretKey) {
|
||||
public record BaiduOcr(boolean enabled,
|
||||
String apiKey,
|
||||
String secretKey,
|
||||
URI tokenUrl,
|
||||
URI meterUrl,
|
||||
Duration connectTimeout,
|
||||
Duration requestTimeout,
|
||||
Path inputRoot,
|
||||
Path outputRoot,
|
||||
DataSize maxImageSize,
|
||||
long maxImagePixels,
|
||||
int maxBatchSize,
|
||||
Duration minRequestInterval,
|
||||
int maxQpsRetries) {
|
||||
public boolean configured() {
|
||||
return enabled && hasText(apiKey) && hasText(secretKey);
|
||||
return enabled
|
||||
&& hasText(apiKey)
|
||||
&& hasText(secretKey)
|
||||
&& tokenUrl != null
|
||||
&& meterUrl != null;
|
||||
}
|
||||
|
||||
public Duration effectiveConnectTimeout() {
|
||||
return positive(connectTimeout) ? connectTimeout : Duration.ofSeconds(10);
|
||||
}
|
||||
|
||||
public Duration effectiveRequestTimeout() {
|
||||
return positive(requestTimeout) ? requestTimeout : Duration.ofSeconds(60);
|
||||
}
|
||||
|
||||
public DataSize effectiveMaxImageSize() {
|
||||
return maxImageSize != null && maxImageSize.toBytes() > 0
|
||||
? maxImageSize : DataSize.ofMegabytes(3);
|
||||
}
|
||||
|
||||
public long effectiveMaxImagePixels() {
|
||||
return maxImagePixels > 0 ? maxImagePixels : 40_000_000L;
|
||||
}
|
||||
|
||||
public int effectiveMaxBatchSize() {
|
||||
return maxBatchSize > 0 ? maxBatchSize : 50;
|
||||
}
|
||||
|
||||
public Duration effectiveMinRequestInterval() {
|
||||
return minRequestInterval != null && !minRequestInterval.isNegative()
|
||||
? minRequestInterval : Duration.ofMillis(600);
|
||||
}
|
||||
|
||||
public int effectiveMaxQpsRetries() {
|
||||
return Math.min(10, Math.max(0, maxQpsRetries));
|
||||
}
|
||||
|
||||
private boolean positive(Duration value) {
|
||||
return value != null && !value.isNegative() && !value.isZero();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package com.baiyue.integration.security;
|
||||
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
@@ -22,7 +22,7 @@ public class InternalServiceTokenGuard {
|
||||
public void verify(String actualToken) {
|
||||
byte[] actual = actualToken == null ? new byte[0] : actualToken.getBytes(StandardCharsets.UTF_8);
|
||||
if (!MessageDigest.isEqual(expectedToken, actual)) {
|
||||
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "内部服务令牌无效");
|
||||
throw new BizException(ResultCode.UNAUTHORIZED, "内部服务令牌无效");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user