| @@ -20,6 +20,8 @@ import org.springframework.web.multipart.MultipartFile; | |||
| import javax.annotation.Nullable; | |||
| import javax.annotation.Resource; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.nio.file.Path; | |||
| import java.nio.file.Paths; | |||
| import java.util.List; | |||
| @@ -179,8 +181,8 @@ public class NewDatasetFromGitController { | |||
| */ | |||
| @GetMapping("/downloadAllFiles") | |||
| @ApiOperation(value = "下载同一版本下所有数据集,并打包") | |||
| public ResponseEntity<InputStreamResource> downloadAllDatasetFiles(@RequestParam("name") String name, @RequestParam("identifier") String identifier, @RequestParam("id") Integer id, @RequestParam("owner") String owner, @RequestParam("version") String version, @RequestParam("is_public") Boolean isPublic) throws Exception { | |||
| return newDatasetService.downloadAllDatasetFilesNew(name, identifier, id, owner, version, isPublic); | |||
| public void downloadAllDatasetFiles(HttpServletRequest req, HttpServletResponse resp, @RequestParam("name") String name, @RequestParam("identifier") String identifier, @RequestParam("id") Integer id, @RequestParam("owner") String owner, @RequestParam("version") String version, @RequestParam("is_public") Boolean isPublic) throws Exception { | |||
| newDatasetService.downloadAllDatasetFilesNew(req, resp, name, identifier, id, owner, version, isPublic); | |||
| } | |||
| /** | |||
| @@ -214,7 +216,7 @@ public class NewDatasetFromGitController { | |||
| @ApiOperation(value = "发布") | |||
| public AjaxResult publish(@RequestBody NewDatasetVo datasetVo) throws Exception { | |||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | |||
| return AjaxResult.success(newDatasetService.publish(datasetVo,loginUser)); | |||
| return AjaxResult.success(newDatasetService.publish(datasetVo, loginUser)); | |||
| } | |||
| @PostMapping("/privateToPublic") | |||
| @@ -12,6 +12,8 @@ import org.springframework.http.HttpRequest; | |||
| import org.springframework.http.ResponseEntity; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.IOException; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @@ -29,7 +31,7 @@ public interface NewDatasetService { | |||
| String downloadDatasetlocal(String filePath) throws Exception; | |||
| ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws IOException, Exception; | |||
| void downloadAllDatasetFilesNew(HttpServletRequest req, HttpServletResponse resp, String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws IOException, Exception; | |||
| Page<NewDatasetVo> newPersonalQueryByPage(Dataset dataset, PageRequest pageRequest) throws Exception; | |||
| @@ -34,6 +34,8 @@ import redis.clients.jedis.Jedis; | |||
| import com.ruoyi.system.api.domain.NewSysNotificationParamsVo; | |||
| import javax.annotation.Resource; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.*; | |||
| import java.nio.file.Files; | |||
| import java.nio.file.Path; | |||
| @@ -620,12 +622,11 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||
| // .contentType(MediaType.APPLICATION_OCTET_STREAM) | |||
| // .body(resource); | |||
| String[] split = filePath.split("/"); | |||
| String t1 = endpointIp + "/" + bucketName + "/" + platformDataBucketName + "/" + String.join("/", Arrays.copyOfRange(split, 3, split.length)); | |||
| return endpointIp + "/" + bucketName + "/" + platformDataBucketName + "/" + String.join("/", Arrays.copyOfRange(split, 3, split.length)); | |||
| } | |||
| @Override | |||
| public ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws Exception { | |||
| public void downloadAllDatasetFilesNew(HttpServletRequest req, HttpServletResponse resp, String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws Exception { | |||
| // 命令行操作 git clone 项目地址 | |||
| String localPath = localPathlocal + owner + "/datasets/" + id + "/" + identifier + "/" + version; | |||
| @@ -651,13 +652,40 @@ public class NewDatasetServiceImpl implements NewDatasetService { | |||
| // 返回压缩文件的输入流 | |||
| File zipFile = new File(zipFilePath); | |||
| InputStreamResource resource = new InputStreamResource(new FileInputStream(zipFile)); | |||
| return ResponseEntity.ok() | |||
| .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + name + "_" + version + "_dataset.zip") | |||
| .contentType(MediaType.APPLICATION_OCTET_STREAM) | |||
| .contentLength(zipFile.length()) | |||
| .body(resource); | |||
| BufferedInputStream bis = null; | |||
| BufferedOutputStream bos = null; | |||
| OutputStream fos = null; | |||
| try { | |||
| bis = new BufferedInputStream(new FileInputStream(zipFile)); | |||
| fos = resp.getOutputStream(); | |||
| bos = new BufferedOutputStream(fos); | |||
| ServletUtils.setFileDownloadHeader(req, resp, name); | |||
| int byteRead = 0; | |||
| byte[] buffer = new byte[8192]; | |||
| while ((byteRead = bis.read(buffer, 0, 8192)) != -1) { | |||
| bos.write(buffer, 0, byteRead); | |||
| } | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } finally { | |||
| try { | |||
| bos.flush(); | |||
| bis.close(); | |||
| fos.close(); | |||
| bos.close(); | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| // InputStreamResource resource = new InputStreamResource(new FileInputStream(zipFile)); | |||
| // | |||
| // return ResponseEntity.ok() | |||
| // .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + name + "_" + version + "_dataset.zip") | |||
| // .contentType(MediaType.APPLICATION_OCTET_STREAM) | |||
| // .contentLength(zipFile.length()) | |||
| // .body(resource); | |||
| } | |||