ソースを参照

更新构建包下载接口

reghao 2 年 前
コミット
ed5a02e909

+ 0 - 14
manager/src/main/java/cn/reghao/devops/manager/app/controller/BuildDeployController.java

@@ -69,18 +69,4 @@ public class BuildDeployController {
         webhookService.handle(body);
         return WebResult.success();
     }
-
-    @ApiOperation(value = "构建包下载接口")
-    @GetMapping(value = "/dlpak/{buildLogId}", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String packageUrl(@PathVariable("buildLogId") String buildLogId) throws Exception {
-        String dl = "/api/app/bd/dl/test.jar";
-        //return WebResult.successWithMsg(dl);
-        return WebResult.failWithMsg("不能下载");
-    }
-
-    @ApiOperation(value = "构建包下载接口")
-    @GetMapping("/dl/{filename}")
-    public void dlPackage(@PathVariable("filename") String filename) throws Exception {
-        System.out.println(filename);
-    }
 }

+ 46 - 0
manager/src/main/java/cn/reghao/devops/manager/app/controller/GetAppController.java

@@ -0,0 +1,46 @@
+package cn.reghao.devops.manager.app.controller;
+
+import cn.reghao.devops.manager.app.service.bd.GetApp;
+import cn.reghao.jutil.jdk.result.WebResult;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * @author reghao
+ * @date 2023-04-21 23:57:00
+ */
+@Slf4j
+@Controller
+@RequestMapping("/api/app/bd")
+public class GetAppController {
+    private final GetApp getApp;
+
+    public GetAppController(GetApp getApp) {
+        this.getApp = getApp;
+    }
+
+    @ApiOperation(value = "构建包下载接口")
+    @GetMapping(value = "/packageurl/{buildLogId}", produces = MediaType.APPLICATION_JSON_VALUE)
+    @ResponseBody
+    public String packageUrl(@PathVariable("buildLogId") String buildLogId) throws Exception {
+        String packageUrl = getApp.packageUrl(buildLogId);
+        return WebResult.successWithMsg(packageUrl);
+    }
+
+    @ApiOperation(value = "构建包下载接口")
+    @GetMapping("/dl/{filename}")
+    public String dlPackage(@PathVariable("filename") String filename) {
+        try {
+            getApp.dlPackage(filename);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        return "redirect:/app/config/app";
+    }
+}

+ 11 - 6
manager/src/main/java/cn/reghao/devops/manager/app/service/bd/impl/GetAppImpl.java

@@ -7,10 +7,11 @@ import cn.reghao.devops.manager.app.model.po.config.AppConfig;
 import cn.reghao.devops.common.build.model.LocalBuildDir;
 import cn.reghao.devops.manager.app.model.po.log.BuildLog;
 import cn.reghao.devops.manager.app.service.bd.GetApp;
-import cn.reghao.devops.manager.spring.HttpUtil;
+import cn.reghao.devops.manager.util.ServletUtil;
 import cn.reghao.devops.manager.util.UploadDownload;
 import org.springframework.stereotype.Service;
 
+import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 
@@ -69,10 +70,14 @@ public class GetAppImpl implements GetApp {
 
         String appId = arr[0];
         String commitId = arr[1];
-        String localPath = String.format("%s%s%s%s%s",
-                LocalBuildDir.packDir, File.separator, appId, File.separator, filename);
-        FileInputStream fileInputStream = new FileInputStream(localPath);
-        //BufferedInputStream bis = new BufferedInputStream(fileInputStream);
-        uploadDownload.download(filename, fileInputStream, HttpUtil.getResponse());
+        String filePath = LocalBuildDir.packDir + File.separator + appId + File.separator + filename;
+        File file = new File(filePath);
+        if (!file.exists()) {
+            throw new Exception("文件不存在");
+        }
+
+        FileInputStream fileInputStream = new FileInputStream(file);
+        BufferedInputStream bis = new BufferedInputStream(fileInputStream);
+        uploadDownload.download(filename, bis, ServletUtil.getResponse());
     }
 }

+ 2 - 2
manager/src/main/java/cn/reghao/devops/manager/spring/exception/ControllerExceptionHandler.java

@@ -1,7 +1,7 @@
 package cn.reghao.devops.manager.spring.exception;
 
 import cn.reghao.jutil.jdk.exception.ExceptionUtil;
-import cn.reghao.jutil.jdk.result.WebBody;
+import cn.reghao.jutil.jdk.result.WebResult;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
@@ -60,6 +60,6 @@ public class ControllerExceptionHandler {
     private ResponseEntity<String> setResponse(String body) {
         HttpHeaders headers = new HttpHeaders();
         headers.setContentType(MediaType.APPLICATION_JSON);
-        return new ResponseEntity<>(WebBody.errorMsg(body), headers, HttpStatus.OK);
+        return new ResponseEntity<>(WebResult.errorWithMsg(body), headers, HttpStatus.OK);
     }
 }

+ 1 - 0
manager/src/main/java/cn/reghao/devops/manager/util/db/PageSort.java

@@ -10,6 +10,7 @@ import org.springframework.data.domain.Sort;
  * @author reghao
  * @date 2021-06-02 11:07:56
  */
+@Deprecated
 public class PageSort {
     private static final int DEFAULT_PAGE_SIZE = 10;
     private static final String DEFAULT_ORDER_BY_COLUMN = "updateTime";

+ 2 - 5
manager/src/main/resources/static/js/main.js

@@ -195,13 +195,10 @@ layui.use(['element', 'form', 'layer', 'upload'], function () {
     $(document).on("click", ".ajax-redirect", function (e) {
         e.preventDefault();
         $.get(e.target.href, function (result) {
-            console.log(result)
-
-            var code = result.code
-            if (code === 0) {
+            if (result.code === 0) {
                 window.location.href = result.msg
             } else {
-                $.fn.Messager(result);
+                $.fn.Messager(result.msg);
             }
         });
     });

+ 1 - 1
manager/src/main/resources/templates/app/bd/index.html

@@ -86,7 +86,7 @@
                         <a class="open-popup"
                            th:attr="data-title=@{${item.appId} + ' 部署列表'}, data-url=@{'/app/bd/deploy?appId=' + ${item.appId} + '&buildLogId=' + ${item.buildLogId}}"
                            data-size="1000,500" href="#">部署</a>
-                        <a class="ajax-redirect" th:href="@{'/api/app/bd/dlpak/'+${item.buildLogId}}">下载</a>
+                        <a class="ajax-redirect" th:href="@{'/api/app/bd/packageurl/'+${item.buildLogId}}">下载</a>
                         <a class="open-popup" th:attr="data-title=@{${item.appId} + ' 历史构建列表'}, data-url=@{'/app/bd/build/history?appId='+${item.appId}}"
                            data-size="max" href="#">历史构建</a>
                     </td>

+ 1 - 1
manager/src/main/resources/templates/app/bd/log/buildlog.html

@@ -41,7 +41,7 @@
                 <td>
                     <a class="open-popup" th:attr="data-title=@{${item.appId} + ' 部署列表'}, data-url=@{'/app/bd/deploy?appId=' + ${item.appId} + '&buildLogId=' + ${item.buildLogId}}"
                        data-size="1000,500" href="#">部署</a>
-                    <a class="ajax-redirect" th:href="@{'/api/app/bd/dlpak/'+${item.buildLogId}}">下载</a>
+                    <a class="ajax-redirect" th:href="@{'/api/app/bd/packageurl/'+${item.buildLogId}}">下载</a>
                 </td>
             </tr>
             </tbody>