|
@@ -1,14 +1,23 @@
|
|
|
package com.minto.app.organization;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import com.minto.app.organization.huadu.IHuaduDocService;
|
|
|
+import com.minto.app.organization.huadu.config.HuaduConfig;
|
|
|
import com.minto.app.organization.workpro.controller.WorkproController;
|
|
|
import com.minto.core.common.AppContext;
|
|
|
import com.minto.core.util.RespUtil;
|
|
|
+import com.minto.core.util.annotation.NeedlessCheckLogin;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -26,7 +35,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@Controller
|
|
|
@RequestMapping("/huadu")
|
|
|
public class HuaDuDocController{
|
|
|
- private static final Logger log = LoggerFactory.getLogger(WorkproController.class);
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(WorkproController.class);
|
|
|
|
|
|
@Autowired
|
|
|
private IHuaduDocService huaDuDocService;
|
|
@@ -45,4 +54,43 @@ public class HuaDuDocController{
|
|
|
RespUtil.rendJson(response, res);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/browser/download")
|
|
|
+ @NeedlessCheckLogin
|
|
|
+ public void download(HttpServletRequest request, HttpServletResponse response) throws IOException{
|
|
|
+ //新的文件目录
|
|
|
+ String filePath = HuaduConfig.getInstance().getBrowserDir();
|
|
|
+ if(StringUtils.isEmpty(filePath)){
|
|
|
+ response.sendError(HttpServletResponse.SC_NOT_FOUND, "文件路径未配置,找不到对应文件!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 默认统信uos系统
|
|
|
+ // 默认统信uos系统
|
|
|
+ String fileName = "signed_com.360.browser-stable_13.3.1012.21-1_arm64.deb";
|
|
|
+ String realPath = filePath + fileName;
|
|
|
+
|
|
|
+ // 检查文件是否存在
|
|
|
+ Path path = Paths.get(realPath);
|
|
|
+ if(!Files.exists(path)){
|
|
|
+ response.sendError(HttpServletResponse.SC_NOT_FOUND, "文件不存在!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置响应头
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
|
|
+
|
|
|
+ // 流式传输文件
|
|
|
+ try(InputStream in = Files.newInputStream(path); OutputStream out = response.getOutputStream()){
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int bytesRead;
|
|
|
+ while((bytesRead = in.read(buffer)) != -1){
|
|
|
+ out.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ } catch(IOException e){
|
|
|
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error reading file");
|
|
|
+ log.error("Error reading file", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|