| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | public R triggerBuild(@RequestBody JSONObject param) { |
| | | try { |
| | | String buildType = param.getString("buildType"); |
| | | String androidTarget = param.getString("android_target"); |
| | | String repoAlias = param.getString("repoAlias"); |
| | | String branch = param.getString("branch"); |
| | | String serverUrl = param.getString("server_url"); |
| | | |
| | | if (Cools.isEmpty(buildType)) { |
| | | buildType = "release"; |
| | |
| | | branch = "master"; |
| | | } |
| | | |
| | | ApkBuildTask task = apkBuildTaskService.triggerBuild(buildType, repoAlias, branch); |
| | | ApkBuildTask task = apkBuildTaskService.triggerBuild(buildType, androidTarget, repoAlias, branch, serverUrl); |
| | | return R.ok(task); |
| | | } catch (Exception e) { |
| | | return R.error("打包任务创建失败: " + e.getMessage()); |
| | |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/apkBuildTask/downloadFile/{id}/auth", method = RequestMethod.GET) |
| | | @ManagerAuth |
| | | public void downloadApkFile(@PathVariable("id") Long id, HttpServletResponse response) { |
| | | try { |
| | | String localPath = apkBuildTaskService.downloadApk(id); |
| | | File file = new File(localPath); |
| | | if (!file.exists()) { |
| | | throw new RuntimeException("APK文件不存在"); |
| | | } |
| | | String fileName = URLEncoder.encode(file.getName(), "UTF-8"); |
| | | response.setContentType("application/vnd.android.package-archive"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setHeader("Content-Length", String.valueOf(file.length())); |
| | | try (InputStream inputStream = new FileInputStream(file); |
| | | OutputStream outputStream = response.getOutputStream()) { |
| | | byte[] buffer = new byte[8192]; |
| | | int len; |
| | | while ((len = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, len); |
| | | } |
| | | outputStream.flush(); |
| | | } |
| | | } catch (Exception e) { |
| | | try { |
| | | response.reset(); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setContentType("application/json; charset=utf-8"); |
| | | response.getWriter().print(JSON.toJSONString(R.error("下载APK失败: " + e.getMessage()))); |
| | | } catch (IOException ignore) { |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通过ADB安装APK到指定设备 |
| | | */ |