Commit 3f5aad29 authored by alex yao's avatar alex yao

fix:Agent API 用户校验

parent b1844a67
...@@ -32,9 +32,7 @@ public class ModelLinkRestImpl implements ModelLinkRest { ...@@ -32,9 +32,7 @@ public class ModelLinkRestImpl implements ModelLinkRest {
Assert.notBlank(dto.getAgentId(), "Agent Id Can't Null"); Assert.notBlank(dto.getAgentId(), "Agent Id Can't Null");
String apiKey = httpServletRequest.getHeader("x-api-key"); String apiKey = httpServletRequest.getHeader("x-api-key");
String apiSecret = httpServletRequest.getHeader("x-api-secret"); String apiSecret = httpServletRequest.getHeader("x-api-secret");
if (apiKey == null || apiSecret == null) { checkApiKeyAndSecret(httpServletRequest);
throw new BusinessException("Api Key or Api Secret Can't Null");
}
return agentApplicationApiService.conversation(apiKey, apiSecret, dto.getAgentId()); return agentApplicationApiService.conversation(apiKey, apiSecret, dto.getAgentId());
} }
...@@ -42,9 +40,7 @@ public class ModelLinkRestImpl implements ModelLinkRest { ...@@ -42,9 +40,7 @@ public class ModelLinkRestImpl implements ModelLinkRest {
public void completions(CompletionsDto dto, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { public void completions(CompletionsDto dto, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
String apiKey = httpServletRequest.getHeader("x-api-key"); String apiKey = httpServletRequest.getHeader("x-api-key");
String apiSecret = httpServletRequest.getHeader("x-api-secret"); String apiSecret = httpServletRequest.getHeader("x-api-secret");
if (apiKey == null || apiSecret == null) { checkApiKeyAndSecret(httpServletRequest);
throw new BusinessException("Api Key or Api Secret Can't Null");
}
List<String> fileIds = new ArrayList<>(); List<String> fileIds = new ArrayList<>();
if (StringUtils.isNotBlank(dto.getFileId())) { if (StringUtils.isNotBlank(dto.getFileId())) {
fileIds.add(dto.getFileId()); fileIds.add(dto.getFileId());
...@@ -56,9 +52,15 @@ public class ModelLinkRestImpl implements ModelLinkRest { ...@@ -56,9 +52,15 @@ public class ModelLinkRestImpl implements ModelLinkRest {
public String uploadFile(String agentId, String conversationId, MultipartFile file, HttpServletRequest httpServletRequest) throws Exception { public String uploadFile(String agentId, String conversationId, MultipartFile file, HttpServletRequest httpServletRequest) throws Exception {
String apiKey = httpServletRequest.getHeader("x-api-key"); String apiKey = httpServletRequest.getHeader("x-api-key");
String apiSecret = httpServletRequest.getHeader("x-api-secret"); String apiSecret = httpServletRequest.getHeader("x-api-secret");
if (apiKey == null || apiSecret == null) { checkApiKeyAndSecret(httpServletRequest);
return agentApplicationApiService.uploadFile(apiKey, apiSecret, agentId, conversationId, file);
}
private void checkApiKeyAndSecret(HttpServletRequest httpServletRequest) {
String apiKey = httpServletRequest.getHeader("x-api-key");
String apiSecret = httpServletRequest.getHeader("x-api-secret");
if (StringUtils.isBlank(apiKey) || StringUtils.isBlank(apiSecret)) {
throw new BusinessException("Api Key or Api Secret Can't Null"); throw new BusinessException("Api Key or Api Secret Can't Null");
} }
return agentApplicationApiService.uploadFile(apiKey, apiSecret, agentId, conversationId, file);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment