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. 7
      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 fileName = UUID.randomUUID().toString() + "." + format;
String downloadFilePath = downloadFilePathPrefix + fileName; String downloadFilePath = downloadFilePathPrefix + fileName;
DownLoadUtil.downloadFile(reference, downloadFilePath); DownLoadUtil.downloadFile(reference, downloadFilePath);
reference = FileUtil.readFile(downloadFilePath);
//删除文件 //删除文件
FileUtil.delFile(downloadFilePath); FileUtil.delFile(downloadFilePath);
reference = FileUtil.readFile(downloadFilePath);
} }
//获取 //获取
String question = null; 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; package com.bw.opai.auth.controller;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -30,7 +32,7 @@ public class OpaiAuthController {
* 逻辑透传给远端认证中心 * 逻辑透传给远端认证中心
*/ */
@PostMapping("/login") @PostMapping("/login")
public Res<String> login(@RequestBody LoginRequest loginReq) {
public Res<Map<String, String>> login(@RequestBody LoginRequest loginReq) {
// 1. 基本参数校验 // 1. 基本参数校验
if (loginReq == null || loginReq.getUsername() == null) { if (loginReq == null || loginReq.getUsername() == null) {
return Res.fail("用户名不能为空"); 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 @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
return true;
}
// 1. 拿到 Token (逻辑参考) // 1. 拿到 Token (逻辑参考)
String token = request.getHeader("Authorization"); String token = request.getHeader("Authorization");
if (token == null) { 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; package com.bw.opai.auth.service;
import java.util.Map;
import com.bw.opai.auth.dto.UserDTO; import com.bw.opai.auth.dto.UserDTO;
import com.bw.opai.auth.entity.SysUser; import com.bw.opai.auth.entity.SysUser;
import com.bw.opai.common.Res; import com.bw.opai.common.Res;
@ -13,7 +15,7 @@ import com.bw.opai.common.Res;
public interface IRemoteAuthService { public interface IRemoteAuthService {
/*** 登录中转 ***/ /*** 登录中转 ***/
Res<String> remoteLogin(String username, String password);
Res<Map<String, String>> remoteLogin(String username, String password);
/*** 注册中转 ***/ /*** 注册中转 ***/
Res<String> remoteRegister(SysUser user); Res<String> remoteRegister(SysUser user);
/*** 核心鉴权:拿着 token 去 Auth-Server 换 UserDTO ***/ /*** 核心鉴权:拿着 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; package com.bw.opai.auth.service.impl;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -45,7 +47,7 @@ public class RemoteAuthServiceImpl implements IRemoteAuthService {
private Long appId; private Long appId;
@Override @Override
public Res<String> remoteLogin(String username, String password) {
public Res<Map<String, String>> remoteLogin(String username, String password) {
String url = authUrl + "/auth/login"; String url = authUrl + "/auth/login";
LoginRequest loginReq = new LoginRequest(); 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) @ExceptionHandler(BizException.class)
public Res<?> handleBizException(BizException e) { public Res<?> handleBizException(BizException e) {
log.error("业务异常: {}", e.getMsg()); log.error("业务异常: {}", e.getMsg());
if(e.getMsg().equals("缺失凭证") || e.getMsg().equals("凭证无效")) {
return Res.unAuth("登录无效");
}
return Res.fail(e.getMsg()); return Res.fail(e.getMsg());
} }
@ -32,6 +35,9 @@ public class GlobalExceptionHandler {
@ExceptionHandler(RuntimeException.class) @ExceptionHandler(RuntimeException.class)
public Res<?> handleRuntimeException(RuntimeException e) { public Res<?> handleRuntimeException(RuntimeException e) {
log.error("运行时异常: ", e); log.error("运行时异常: ", e);
if(e.getMessage().equals("缺失凭证") || e.getMessage().equals("凭证无效")) {
return Res.unAuth("登录无效");
}
return Res.fail(e.getMessage()); return Res.fail(e.getMessage());
} }

7
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.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse; 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.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -55,13 +57,14 @@ public class FileServiceImpl implements FileService {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
String newFileName = UUID.randomUUID() + "." + StringUtils.getFilenameExtension(file.getOriginalFilename());
// 文件流 // 文件流
builder.addBinaryBody( builder.addBinaryBody(
"file", "file",
file.getInputStream(), file.getInputStream(),
ContentType.APPLICATION_OCTET_STREAM, ContentType.APPLICATION_OCTET_STREAM,
file.getOriginalFilename()
newFileName
); );
// 👇 关键要求 GoFast 返回 JSON // 👇 关键要求 GoFast 返回 JSON
builder.addTextBody("output", "json"); builder.addTextBody("output", "json");

Loading…
Cancel
Save