|
|
@@ -13,6 +13,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
|
|
import vip.xiaonuo.disk.component.FileDealComp;
|
|
|
@@ -62,6 +63,9 @@ public class FiletransferController {
|
|
|
@Resource
|
|
|
UFOPFactory ufopFactory;
|
|
|
|
|
|
+ @Value("${common.account}")
|
|
|
+ private String commonUserId;
|
|
|
+
|
|
|
|
|
|
public static final String CURRENT_MODULE = "文件传输接口";
|
|
|
|
|
|
@@ -83,11 +87,11 @@ public class FiletransferController {
|
|
|
|
|
|
|
|
|
@Operation(summary = "极速上传", description = "校验文件MD5判断文件是否存在,如果存在直接上传成功并返回skipUpload=true,如果不存在返回skipUpload=false需要再次调用该接口的POST方法", tags = {"filetransfer"})
|
|
|
- @RequestMapping(value = "/uploadcommonfile", method = RequestMethod.GET)
|
|
|
+ @RequestMapping(value = "/uploadCommonFile", method = RequestMethod.GET)
|
|
|
@MyLog(operation = "极速上传", module = CURRENT_MODULE)
|
|
|
@ResponseBody
|
|
|
- public RestResult<UploadFileVo> uploadcommonfile(UploadFileDTO uploadFileDto) {
|
|
|
- String userId = "common";
|
|
|
+ public RestResult<UploadFileVo> uploadCommonFile(UploadFileDTO uploadFileDto) {
|
|
|
+ String userId = commonUserId;
|
|
|
|
|
|
boolean isCheckSuccess = storageService.checkStorage(userId, uploadFileDto.getTotalSize());
|
|
|
if (!isCheckSuccess) {
|
|
|
@@ -112,7 +116,19 @@ public class FiletransferController {
|
|
|
return RestResult.success().data(uploadFileVo);
|
|
|
|
|
|
}
|
|
|
+ @Operation(summary = "上传文件", description = "真正的上传文件接口", tags = {"filetransfer"})
|
|
|
+ @RequestMapping(value = "/uploadCommonFile", method = RequestMethod.POST)
|
|
|
+ @MyLog(operation = "上传文件", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<UploadFileVo> uploadCommonFile(HttpServletRequest request, UploadFileDTO uploadFileDto) {
|
|
|
+ String userId =commonUserId;
|
|
|
|
|
|
+ filetransferService.uploadFile(request, uploadFileDto, userId);
|
|
|
+
|
|
|
+ UploadFileVo uploadFileVo = new UploadFileVo();
|
|
|
+ return RestResult.success().data(uploadFileVo);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
@Operation(summary = "下载文件", description = "下载文件接口", tags = {"filetransfer"})
|
|
|
@MyLog(operation = "下载文件", module = CURRENT_MODULE)
|
|
|
@@ -155,6 +171,56 @@ public class FiletransferController {
|
|
|
filetransferService.downloadFile(httpServletResponse, downloadFileDTO);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "下载文件", description = "下载文件接口", tags = {"filetransfer"})
|
|
|
+ @MyLog(operation = "下载文件", module = CURRENT_MODULE)
|
|
|
+ @RequestMapping(value = "/downloadCommonFile", method = RequestMethod.GET)
|
|
|
+ public void downloadCommonFile(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, DownloadFileDTO downloadFileDTO) {
|
|
|
+// Cookie[] cookieArr = httpServletRequest.getCookies();
|
|
|
+ String token = "";
|
|
|
+// if (cookieArr != null) {
|
|
|
+// for (Cookie cookie : cookieArr) {
|
|
|
+// if ("token".equals(cookie.getName())) {
|
|
|
+// token = cookie.getValue();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ boolean authResult = fileDealComp.checkAuthDownloadAndPreview(downloadFileDTO.getShareBatchNum(),
|
|
|
+ downloadFileDTO.getExtractionCode(),
|
|
|
+ token,
|
|
|
+ downloadFileDTO.getUserFileId(), null);
|
|
|
+ if (!authResult) {
|
|
|
+ log.error("没有权限下载!!!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ httpServletResponse.setContentType("application/force-download");// 设置强制下载不打开
|
|
|
+ UserFile userFile = userFileService.getById(downloadFileDTO.getUserFileId());
|
|
|
+ String fileName = "";
|
|
|
+ if (userFile.getIsDir() == 1) {
|
|
|
+ fileName = userFile.getFileName() + ".zip";
|
|
|
+ } else {
|
|
|
+ fileName = userFile.getFileName() + "." + userFile.getExtendName();
|
|
|
+
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ httpServletResponse.addHeader("Content-Disposition", "attachment;fileName=" + fileName);// 设置文件名
|
|
|
+
|
|
|
+ filetransferService.downloadFile(httpServletResponse, downloadFileDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "批量下载文件", description = "批量下载文件", tags = {"filetransfer"})
|
|
|
@RequestMapping(value = "/batchDownloadFile", method = RequestMethod.GET)
|
|
|
@MyLog(operation = "批量下载文件", module = CURRENT_MODULE)
|
|
|
@@ -202,6 +268,59 @@ public class FiletransferController {
|
|
|
filetransferService.downloadUserFileList(httpServletResponse, userFile.getFilePath(), fileName, userFileIds);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary = "批量下载文件", description = "批量下载文件", tags = {"filetransfer"})
|
|
|
+ @RequestMapping(value = "/batchCommonDownloadFile", method = RequestMethod.GET)
|
|
|
+ @MyLog(operation = "批量下载文件", module = CURRENT_MODULE)
|
|
|
+ @ResponseBody
|
|
|
+ public void batchCommonDownloadFile(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BatchDownloadFileDTO batchDownloadFileDTO) {
|
|
|
+// Cookie[] cookieArr = httpServletRequest.getCookies();
|
|
|
+ String token = "";
|
|
|
+// if (cookieArr != null) {
|
|
|
+// for (Cookie cookie : cookieArr) {
|
|
|
+// if ("token".equals(cookie.getName())) {
|
|
|
+// token = cookie.getValue();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ boolean authResult = fileDealComp.checkAuthDownloadAndPreview(batchDownloadFileDTO.getShareBatchNum(),
|
|
|
+ batchDownloadFileDTO.getExtractionCode(),
|
|
|
+ token,
|
|
|
+ batchDownloadFileDTO.getUserFileIds(), null);
|
|
|
+ if (!authResult) {
|
|
|
+ log.error("没有权限下载!!!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String files = batchDownloadFileDTO.getUserFileIds();
|
|
|
+ String[] userFileIdStrs = files.split(",");
|
|
|
+ List<String> userFileIds = new ArrayList<>();
|
|
|
+ for(String userFileId : userFileIdStrs) {
|
|
|
+ UserFile userFile = userFileService.getById(userFileId);
|
|
|
+ if (userFile.getIsDir() == 0) {
|
|
|
+ userFileIds.add(userFileId);
|
|
|
+ } else {
|
|
|
+ QiwenFile qiwenFile = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true);
|
|
|
+ List<UserFile> userFileList = userFileService.selectUserFileByLikeRightFilePath(qiwenFile.getPath(), userFile.getUserId());
|
|
|
+ List<String> userFileIds1 = userFileList.stream().map(UserFile::getUserFileId).collect(Collectors.toList());
|
|
|
+ userFileIds.add(userFile.getUserFileId());
|
|
|
+ userFileIds.addAll(userFileIds1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ UserFile userFile = userFileService.getById(userFileIdStrs[0]);
|
|
|
+ httpServletResponse.setContentType("application/force-download");// 设置强制下载不打开
|
|
|
+ Date date = new Date();
|
|
|
+ String fileName = String.valueOf(date.getTime());
|
|
|
+ httpServletResponse.addHeader("Content-Disposition", "attachment;fileName=" + fileName + ".zip");// 设置文件名
|
|
|
+ filetransferService.downloadUserFileList(httpServletResponse, userFile.getFilePath(), fileName, userFileIds);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary="预览文件", description="用于文件预览", tags = {"filetransfer"})
|
|
|
@GetMapping("/preview")
|
|
|
public void preview(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, PreviewDTO previewDTO) throws IOException {
|
|
|
@@ -290,6 +409,111 @@ public class FiletransferController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Operation(summary="预览文件", description="用于文件预览", tags = {"filetransfer"})
|
|
|
+ @GetMapping("/previewCommon")
|
|
|
+ public void previewCommon(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, PreviewDTO previewDTO) throws IOException {
|
|
|
+
|
|
|
+ if (previewDTO.getPlatform() != null && previewDTO.getPlatform() == 2) {
|
|
|
+ filetransferService.previewPictureFile(httpServletResponse, previewDTO);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ // token逻辑去掉
|
|
|
+ String token = "";
|
|
|
+
|
|
|
+ UserFile userFile = userFileService.getById(previewDTO.getUserFileId());
|
|
|
+ boolean authResult = fileDealComp.checkAuthDownloadAndPreview(previewDTO.getShareBatchNum(),
|
|
|
+ previewDTO.getExtractionCode(),
|
|
|
+ token,
|
|
|
+ previewDTO.getUserFileId(),
|
|
|
+ previewDTO.getPlatform());
|
|
|
+
|
|
|
+ if (!authResult) {
|
|
|
+ log.error("没有权限预览!!!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String fileName = userFile.getFileName() + "." + userFile.getExtendName();
|
|
|
+ try {
|
|
|
+ fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ httpServletResponse.addHeader("Content-Disposition", "fileName=" + fileName);// 设置文件名
|
|
|
+ String mime = MimeUtils.getMime(userFile.getExtendName());
|
|
|
+ httpServletResponse.setHeader("Content-Type", mime);
|
|
|
+ if (UFOPUtils.isImageFile(userFile.getExtendName())) {
|
|
|
+ httpServletResponse.setHeader("cache-control", "public");
|
|
|
+ }
|
|
|
+
|
|
|
+ FileBean fileBean = fileService.getById(userFile.getFileId());
|
|
|
+ if (UFOPUtils.isVideoFile(userFile.getExtendName()) || "mp3".equalsIgnoreCase(userFile.getExtendName()) || "flac".equalsIgnoreCase(userFile.getExtendName())) {
|
|
|
+ //获取从那个字节开始读取文件
|
|
|
+ String rangeString = httpServletRequest.getHeader("Range");
|
|
|
+ int start = 0;
|
|
|
+ if (StringUtils.isNotBlank(rangeString)) {
|
|
|
+ start = Integer.parseInt(rangeString.substring(rangeString.indexOf("=") + 1, rangeString.indexOf("-")));
|
|
|
+ }
|
|
|
+
|
|
|
+ Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType());
|
|
|
+ DownloadFile downloadFile = new DownloadFile();
|
|
|
+ downloadFile.setFileUrl(fileBean.getFileUrl());
|
|
|
+ Range range = new Range();
|
|
|
+ range.setStart(start);
|
|
|
+
|
|
|
+ if (start + 1024 * 1024 * 1 >= fileBean.getFileSize().intValue()) {
|
|
|
+ range.setLength(fileBean.getFileSize().intValue() - start);
|
|
|
+ } else {
|
|
|
+ range.setLength(1024 * 1024 * 1);
|
|
|
+ }
|
|
|
+ downloadFile.setRange(range);
|
|
|
+ InputStream inputStream = downloader.getInputStream(downloadFile);
|
|
|
+
|
|
|
+ OutputStream outputStream = httpServletResponse.getOutputStream();
|
|
|
+ try {
|
|
|
+
|
|
|
+ //返回码需要为206,代表只处理了部分请求,响应了部分数据
|
|
|
+
|
|
|
+ httpServletResponse.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
|
|
+ // 每次请求只返回1MB的视频流
|
|
|
+
|
|
|
+ httpServletResponse.setHeader("Accept-Ranges", "bytes");
|
|
|
+ //设置此次相应返回的数据范围
|
|
|
+ httpServletResponse.setHeader("Content-Range", "bytes " + start + "-" + (fileBean.getFileSize() - 1) + "/" + fileBean.getFileSize());
|
|
|
+ IOUtils.copy(inputStream, outputStream);
|
|
|
+
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeQuietly(inputStream);
|
|
|
+ IOUtils.closeQuietly(outputStream);
|
|
|
+ if (downloadFile.getOssClient() != null) {
|
|
|
+ downloadFile.getOssClient().shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ filetransferService.previewFile(httpServletResponse, previewDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Operation(summary = "获取存储信息", description = "获取存储信息", tags = {"filetransfer"})
|
|
|
@RequestMapping(value = "/getstorage", method = RequestMethod.GET)
|
|
|
@ResponseBody
|
|
|
@@ -312,5 +536,24 @@ public class FiletransferController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Operation(summary = "获取存储信息", description = "获取存储信息", tags = {"filetransfer"})
|
|
|
+ @RequestMapping(value = "/getCommonStorage", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public RestResult<StorageBean> getCommonStorage() {
|
|
|
+
|
|
|
+ String userId = commonUserId;
|
|
|
+ StorageBean storageBean = new StorageBean();
|
|
|
+
|
|
|
+ storageBean.setUserId(userId);
|
|
|
+
|
|
|
+
|
|
|
+ Long storageSize = filetransferService.selectStorageSizeByUserId(userId);
|
|
|
+ StorageBean storage = new StorageBean();
|
|
|
+ storage.setUserId(userId);
|
|
|
+ storage.setStorageSize(storageSize);
|
|
|
+ Long totalStorageSize = storageService.getTotalStorageSize(userId);
|
|
|
+ storage.setTotalStorageSize(totalStorageSize);
|
|
|
+ return RestResult.success().data(storage);
|
|
|
|
|
|
+ }
|
|
|
}
|