Browse Source

ai服务上传类型bug修复

master
maojian 2 months ago
parent
commit
a41b133903
  1. 2
      ai-service/src/main/java/com/bw/ai/emotionextract/service/impl/EmotionExtractServiceImpl.java
  2. 4
      opai-api/src/main/java/com/bw/opai/auth/controller/OpaiAuthController.java
  3. 4
      opai-api/src/main/java/com/bw/opai/auth/interceptor/AuthInterceptor.java
  4. 4
      opai-api/src/main/java/com/bw/opai/auth/service/IRemoteAuthService.java
  5. 4
      opai-api/src/main/java/com/bw/opai/auth/service/impl/RemoteAuthServiceImpl.java
  6. 6
      opai-api/src/main/java/com/bw/opai/exception/GlobalExceptionHandler.java
  7. 5
      opai-api/src/main/java/com/bw/opai/file/service/impl/FileServiceImpl.java

2
ai-service/src/main/java/com/bw/ai/emotionextract/service/impl/EmotionExtractServiceImpl.java

@ -71,9 +71,9 @@ public class EmotionExtractServiceImpl implements EmotionExtractService {
String fileName = UUID.randomUUID().toString() + "." + format;
String downloadFilePath = downloadFilePathPrefix + fileName;
DownLoadUtil.downloadFile(reference, downloadFilePath);
reference = FileUtil.readFile(downloadFilePath);
//删除文件
FileUtil.delFile(downloadFilePath);
reference = FileUtil.readFile(downloadFilePath);
}
//获取
String question = null;

4
opai-api/src/main/java/com/bw/opai/auth/controller/OpaiAuthController.java

@ -1,5 +1,7 @@
package com.bw.opai.auth.controller;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -30,7 +32,7 @@ public class OpaiAuthController {
* 逻辑透传给远端认证中心
*/
@PostMapping("/login")
public Res<String> login(@RequestBody LoginRequest loginReq) {
public Res<Map<String, String>> login(@RequestBody LoginRequest loginReq) {
// 1. 基本参数校验
if (loginReq == null || loginReq.getUsername() == null) {
return Res.fail("用户名不能为空");

4
opai-api/src/main/java/com/bw/opai/auth/interceptor/AuthInterceptor.java

@ -26,6 +26,10 @@ public class AuthInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
return true;
}
// 1. 拿到 Token (逻辑参考)
String token = request.getHeader("Authorization");
if (token == null) {

4
opai-api/src/main/java/com/bw/opai/auth/service/IRemoteAuthService.java

@ -1,5 +1,7 @@
package com.bw.opai.auth.service;
import java.util.Map;
import com.bw.opai.auth.dto.UserDTO;
import com.bw.opai.auth.entity.SysUser;
import com.bw.opai.common.Res;
@ -13,7 +15,7 @@ import com.bw.opai.common.Res;
public interface IRemoteAuthService {
/*** 登录中转 ***/
Res<String> remoteLogin(String username, String password);
Res<Map<String, String>> remoteLogin(String username, String password);
/*** 注册中转 ***/
Res<String> remoteRegister(SysUser user);
/*** 核心鉴权:拿着 token 去 Auth-Server 换 UserDTO ***/

4
opai-api/src/main/java/com/bw/opai/auth/service/impl/RemoteAuthServiceImpl.java

@ -1,6 +1,8 @@
package com.bw.opai.auth.service.impl;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -45,7 +47,7 @@ public class RemoteAuthServiceImpl implements IRemoteAuthService {
private Long appId;
@Override
public Res<String> remoteLogin(String username, String password) {
public Res<Map<String, String>> remoteLogin(String username, String password) {
String url = authUrl + "/auth/login";
LoginRequest loginReq = new LoginRequest();

6
opai-api/src/main/java/com/bw/opai/exception/GlobalExceptionHandler.java

@ -23,6 +23,9 @@ public class GlobalExceptionHandler {
@ExceptionHandler(BizException.class)
public Res<?> handleBizException(BizException e) {
log.error("业务异常: {}", e.getMsg());
if(e.getMsg().equals("缺失凭证") || e.getMsg().equals("凭证无效")) {
return Res.unAuth("登录无效");
}
return Res.fail(e.getMsg());
}
@ -32,6 +35,9 @@ public class GlobalExceptionHandler {
@ExceptionHandler(RuntimeException.class)
public Res<?> handleRuntimeException(RuntimeException e) {
log.error("运行时异常: ", e);
if(e.getMessage().equals("缺失凭证") || e.getMessage().equals("凭证无效")) {
return Res.unAuth("登录无效");
}
return Res.fail(e.getMessage());
}

5
opai-api/src/main/java/com/bw/opai/file/service/impl/FileServiceImpl.java

@ -2,6 +2,7 @@ package com.bw.opai.file.service.impl;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
@ -15,6 +16,7 @@ import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSONObject;
@ -56,12 +58,13 @@ public class FileServiceImpl implements FileService {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
String newFileName = UUID.randomUUID() + "." + StringUtils.getFilenameExtension(file.getOriginalFilename());
// 文件流
builder.addBinaryBody(
"file",
file.getInputStream(),
ContentType.APPLICATION_OCTET_STREAM,
file.getOriginalFilename()
newFileName
);
// 👇 关键要求 GoFast 返回 JSON
builder.addTextBody("output", "json");

Loading…
Cancel
Save