Commit 5ec5ccf0 authored by liqin's avatar liqin 💬

bug fixed

parent c74324d4
......@@ -105,11 +105,11 @@ public class FastDFSUtils {
/**
* 下载文件(字节数组)
*/
public static BufferedInputStream downloadFile(String fileUrl, OutputStream outputStream) {
public static void downloadFile(String fileUrl, OutputStream outputStream) {
fileUrl = fileUrl.replace(dfsFileAccessBasePath + "/", "");
String groupName = fileUrl.substring(0, fileUrl.indexOf("/"));
String path = fileUrl.substring(fileUrl.indexOf("/") + 1);
return storageClient.downloadFile(groupName, path, new DownloadFileStream(outputStream));
storageClient.downloadFile(groupName, path, new DownloadFileStream(outputStream));
}
/**
......
package cn.wisenergy.chnmuseum.party.common.video;
import lombok.extern.slf4j.Slf4j;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
@Slf4j
public class VideoEncryptUtil {
//此为AES128位,如果要求AES256位,需要更新jdk内的包,jdk8发布版本默认不支持
private static final String cipher = "3348c95c60520be7";
public static final String cipher = "3348c95c60520be7";
private static final int dataLength = 4096;
public static InputStream main(InputStream fis, String cipher) throws IOException {
public static InputStream encrypt(InputStream fis, String cipher) throws IOException {
final ByteArrayOutputStream[] outputStream = new ByteArrayOutputStream[1];
AesCipherDataSink encryptingDataSink = new AesCipherDataSink(cipher.getBytes(StandardCharsets.UTF_8),
new DataSink() {
......@@ -42,7 +39,6 @@ public class VideoEncryptUtil {
}
encryptingDataSink.close();
fis.close();
log.info("加解密完成");
return new ByteArrayInputStream(outputStream[0].toByteArray());
}
......
......@@ -7,6 +7,7 @@ import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
import java.util.Set;
/**
* 批量操作响应结果
......@@ -34,7 +35,7 @@ public class BatchUploadResVO {
private List<HandleResult> handleList;
@ApiModelProperty("成功上传的文件集合")
private List<Asset> fileList;
private Set<Asset> fileList;
@Data
public static class HandleResult {
......
......@@ -94,6 +94,7 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/loginByQrCode", "anon");
filterChainDefinitionMap.put("/doc.html", "anon");
filterChainDefinitionMap.put("/swagger-ui.html", "anon");
filterChainDefinitionMap.put("/asset/download1", "anon");
filterChainDefinitionMap.put("/404", "anon");
filterChainDefinitionMap.put("/500", "anon");
......
......@@ -8,6 +8,7 @@ import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* <p>
......@@ -105,4 +106,21 @@ public class Asset implements Serializable {
@TableField(exist = false)
private String videoContentCopyrightOwnerName;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Asset asset = (Asset) o;
return md5.equals(asset.md5);
}
@Override
public int hashCode() {
return Objects.hash(md5);
}
}
package cn.wisenergy.chnmuseum.party.web.controller;
import cn.hutool.core.util.ZipUtil;
import cn.wisenergy.chnmuseum.party.common.dfs.FastDFSUtils;
import cn.wisenergy.chnmuseum.party.common.video.VideoEncryptUtil;
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;
import cn.wisenergy.chnmuseum.party.model.Asset;
import cn.wisenergy.chnmuseum.party.service.AssetService;
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.tobato.fastdfs.domain.fdfs.MetaData;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
......@@ -14,12 +18,19 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* <pre>
......@@ -78,19 +89,82 @@ public class AssetController extends BaseController {
@ApiImplicitParam(name = "idList", value = "视频文件标识ID集合", dataType = "String", paramType = "path")
})
@PostMapping("/download")
@RequiresAuthentication //@RequiresPermissions("asset:download")
public void download(@RequestParam("idList") List<String> idList) {
//@RequiresAuthentication
public void download(@RequestParam("idList") List<String> idList, HttpServletResponse response) throws IOException {
response.setContentType("application/octet-stream");
//保证下载时文件名为指定文件名,避免中文文件名乱码
response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + URLEncoder.encode("1.zip", "UTF-8") + "\"");
final List<Asset> assetList = assetService.listByIds(idList);
InputStream[] inputStreams = new InputStream[idList.size()];
for (Asset asset : assetList) {
final InputStream[] inputStreams = new InputStream[idList.size()];
final String[] paths = new String[idList.size()];
for (int i = 0; i < assetList.size(); i++) {
final Asset asset = assetList.get(i);
final String fileUrl = asset.getFileUrl();
final InputStream inputStream = FastDFSUtils.downloadFile(fileUrl);
ByteOutputStream byteOutputStream = new ByteOutputStream();
FastDFSUtils.downloadFile(fileUrl, byteOutputStream);
inputStreams[i] = VideoEncryptUtil.encrypt(byteOutputStream.newInputStream(), VideoEncryptUtil.cipher);
final Set<MetaData> fileMetaData = FastDFSUtils.getFileMetaData(fileUrl);
String md5 = fileMetaData.stream().filter(x -> "MD5".equals(x.getName())).map(MetaData::getValue).findFirst().get();
paths[i] = md5 + ".chnmuseum";
}
ServletOutputStream outputStream = response.getOutputStream();
ZipUtil.zip(outputStream, paths, inputStreams);
}
@ApiOperation(value = "视频文件汇出", notes = "视频文件汇出")
@ApiImplicitParams({
@ApiImplicitParam(name = "idList", value = "视频文件标识ID集合", dataType = "String", paramType = "path")
})
@GetMapping("/download1")
//@RequiresAuthentication
public void download1(@RequestParam("idList") List<String> idList, HttpServletResponse response) throws IOException {
response.setContentType("application/octet-stream");
//保证下载时文件名为指定文件名,避免中文文件名乱码
response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + URLEncoder.encode("1.zip", "UTF-8") + "\"");
final List<Asset> assetList = assetService.listByIds(idList);
final InputStream[] inputStreams = new InputStream[idList.size()];
final String[] paths = new String[idList.size()];
for (int i = 0; i < assetList.size(); i++) {
final Asset asset = assetList.get(i);
final String fileUrl = asset.getFileUrl();
ByteOutputStream byteOutputStream = new ByteOutputStream();
FastDFSUtils.downloadFile(fileUrl, byteOutputStream);
inputStreams[i] = VideoEncryptUtil.encrypt(byteOutputStream.newInputStream(), VideoEncryptUtil.cipher);
final Set<MetaData> fileMetaData = FastDFSUtils.getFileMetaData(fileUrl);
String md5 = fileMetaData.stream().filter(x -> "MD5".equals(x.getName())).map(MetaData::getValue).findFirst().get();
paths[i] = md5 + ".chnmuseum";
}
ServletOutputStream outputStream = response.getOutputStream();
ZipUtil.zip(outputStream, paths, inputStreams);
}
@ApiOperation(value = "视频文件汇出", notes = "视频文件汇出")
@ApiImplicitParams({
@ApiImplicitParam(name = "idList", value = "视频文件标识ID集合", dataType = "String", paramType = "path")
})
@GetMapping("/download2")
//@RequiresAuthentication
public void download2(@RequestParam("idList") List<String> idList, HttpServletResponse response) throws IOException {
response.setContentType("application/octet-stream");
//保证下载时文件名为指定文件名,避免中文文件名乱码
response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + URLEncoder.encode("1.zip", "UTF-8") + "\"");
final Map<String, InputStream> map = new LinkedHashMap<>(idList.size() + 1);
final List<Asset> assetList = assetService.listByIds(idList);
for (final Asset asset : assetList) {
final String fileUrl = asset.getFileUrl();
ByteOutputStream byteOutputStream = new ByteOutputStream();
FastDFSUtils.downloadFile(fileUrl, byteOutputStream);
final Set<MetaData> fileMetaData = FastDFSUtils.getFileMetaData(fileUrl);
String fileName = fileMetaData.stream().filter(x -> "MD5".equals(x.getName())).map(MetaData::getValue).findFirst().get() + ".chnmuseum";
map.put(fileName, byteOutputStream.newInputStream());
}
ServletOutputStream outputStream = response.getOutputStream();
String[] paths = map.keySet().toArray(new String[0]);
InputStream[] ins = map.values().toArray(new InputStream[0]);
ZipUtil.zip(outputStream, paths, ins);
}
}
......
......@@ -10,6 +10,7 @@ import cn.wisenergy.chnmuseum.party.common.vo.ImageUploadResult;
import cn.wisenergy.chnmuseum.party.model.Asset;
import cn.wisenergy.chnmuseum.party.service.AssetService;
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.tobato.fastdfs.domain.fdfs.FileInfo;
import com.github.tobato.fastdfs.domain.fdfs.MetaData;
import io.swagger.annotations.Api;
......@@ -80,7 +81,7 @@ public class FileUploadController extends BaseController {
int failureCount = 0;
List<BatchUploadResVO.HandleResult> handleList = new ArrayList<>();
List<Asset> datumUrlList = new ArrayList<>();
Set<Asset> datumUrlList = new LinkedHashSet<>();
for (MultipartFile file : files) {
// 当前维度表下线结果
BatchUploadResVO.HandleResult handleResult = new BatchUploadResVO.HandleResult();
......@@ -268,7 +269,7 @@ public class FileUploadController extends BaseController {
int failureCount = 0;
List<BatchUploadResVO.HandleResult> handleList = new ArrayList<>();
List<Asset> videoUrlList = new ArrayList<>();
Set<Asset> videoUrlList = new LinkedHashSet<>();
for (MultipartFile file : files) {
// 当前维度表下线结果
BatchUploadResVO.HandleResult handleResult = new BatchUploadResVO.HandleResult();
......@@ -380,7 +381,7 @@ public class FileUploadController extends BaseController {
int failureCount = 0;
List<BatchUploadResVO.HandleResult> handleList = new ArrayList<>();
List<Asset> fileList = new ArrayList<>();
Set<Asset> fileList = new LinkedHashSet<>();
for (MultipartFile file : files) {
// 当前维度表下线结果
BatchUploadResVO.HandleResult handleResult = new BatchUploadResVO.HandleResult();
......@@ -433,6 +434,21 @@ public class FileUploadController extends BaseController {
final FileInfo fileInfo = FastDFSUtils.getFileInfo(fileUrl);
final Set<MetaData> fileMetaData = FastDFSUtils.getFileMetaData(fileUrl);
String md5 = fileMetaData.stream().filter(x -> "MD5".equals(x.getName())).map(MetaData::getValue).findFirst().get();
final Asset one = this.assetService.getOne(Wrappers.<Asset>lambdaQuery().eq(Asset::getMd5, md5));
if (one != null) {
FastDFSUtils.deleteFile(fileUrl);
fileList.add(one);
handleResult.setFileUrl(fileUrl);
handleResult.setFileName(originalFilename);
handleResult.setFileType(FileTypeEnum.VIDEO.getName());
handleResult.setHandleResult(HANDLE_STATUS_ENUM.SUCCESS.getName());
handleResult.setDescription("");
successCount++;
handleList.add(handleResult);
continue;
}
final LocalDateTime createTime = TimeUtils.getDateTimeOfTimestamp(fileInfo.getCreateTime() * 1000);
final long fileSize = fileInfo.getFileSize();
final Asset asset = Asset.builder()
......@@ -490,7 +506,7 @@ public class FileUploadController extends BaseController {
int failureCount = 0;
List<BatchUploadResVO.HandleResult> handleList = new ArrayList<>();
List<Asset> fileList = new ArrayList<>();
Set<Asset> fileList = new LinkedHashSet<>();
for (MultipartFile file : files) {
// 当前维度表下线结果
BatchUploadResVO.HandleResult handleResult = new BatchUploadResVO.HandleResult();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment