|
@@ -1,7 +1,5 @@
|
|
|
package com.usoftchina.smartschool.file.controller;
|
|
package com.usoftchina.smartschool.file.controller;
|
|
|
|
|
|
|
|
-import com.github.tobato.fastdfs.domain.StorePath;
|
|
|
|
|
-import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
|
|
|
|
import com.usoftchina.smartschool.base.Result;
|
|
import com.usoftchina.smartschool.base.Result;
|
|
|
import com.usoftchina.smartschool.exception.BizException;
|
|
import com.usoftchina.smartschool.exception.BizException;
|
|
|
import com.usoftchina.smartschool.exception.ExceptionCode;
|
|
import com.usoftchina.smartschool.exception.ExceptionCode;
|
|
@@ -11,6 +9,7 @@ import com.usoftchina.smartschool.file.dto.FolderDTO;
|
|
|
import com.usoftchina.smartschool.file.dto.FolderSaveDTO;
|
|
import com.usoftchina.smartschool.file.dto.FolderSaveDTO;
|
|
|
import com.usoftchina.smartschool.file.po.FileInfo;
|
|
import com.usoftchina.smartschool.file.po.FileInfo;
|
|
|
import com.usoftchina.smartschool.file.service.FileInfoService;
|
|
import com.usoftchina.smartschool.file.service.FileInfoService;
|
|
|
|
|
+import com.usoftchina.smartschool.file.storage.FileStorageClient;
|
|
|
import com.usoftchina.smartschool.utils.BeanMapper;
|
|
import com.usoftchina.smartschool.utils.BeanMapper;
|
|
|
import com.usoftchina.smartschool.utils.BizAssert;
|
|
import com.usoftchina.smartschool.utils.BizAssert;
|
|
|
import com.usoftchina.smartschool.utils.CollectionUtils;
|
|
import com.usoftchina.smartschool.utils.CollectionUtils;
|
|
@@ -20,7 +19,6 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.compress.archivers.ArchiveOutputStream;
|
|
import org.apache.commons.compress.archivers.ArchiveOutputStream;
|
|
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
|
|
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
|
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
@@ -48,7 +46,7 @@ public class FileController {
|
|
|
private FileInfoService fileService;
|
|
private FileInfoService fileService;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private FastFileStorageClient storageClient;
|
|
|
|
|
|
|
+ private FileStorageClient storageClient;
|
|
|
/**
|
|
/**
|
|
|
* 文件访问服务baseUrl
|
|
* 文件访问服务baseUrl
|
|
|
*
|
|
*
|
|
@@ -127,9 +125,7 @@ public class FileController {
|
|
|
if (null != info.getFullPath()) {
|
|
if (null != info.getFullPath()) {
|
|
|
response.setHeader("Content-disposition",
|
|
response.setHeader("Content-disposition",
|
|
|
"attachment; filename=" + URLEncoder.encode(info.getName(), "UTF-8"));
|
|
"attachment; filename=" + URLEncoder.encode(info.getName(), "UTF-8"));
|
|
|
- StorePath path = StorePath.praseFromUrl(info.getFullPath());
|
|
|
|
|
- storageClient.downloadFile(path.getGroup(), path.getPath(),
|
|
|
|
|
- in -> IOUtils.copy(in, response.getOutputStream()));
|
|
|
|
|
|
|
+ storageClient.downloadFile(info.getFullPath(), response.getOutputStream());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -159,9 +155,7 @@ public class FileController {
|
|
|
if (!StringUtils.isEmpty(info.getMime())) {
|
|
if (!StringUtils.isEmpty(info.getMime())) {
|
|
|
response.setContentType(info.getMime());
|
|
response.setContentType(info.getMime());
|
|
|
}
|
|
}
|
|
|
- StorePath path = StorePath.praseFromUrl(info.getFullPath());
|
|
|
|
|
- storageClient.downloadFile(path.getGroup(), path.getPath(),
|
|
|
|
|
- in -> IOUtils.copy(in, response.getOutputStream()));
|
|
|
|
|
|
|
+ storageClient.downloadFile(info.getFullPath(), response.getOutputStream());
|
|
|
} else {
|
|
} else {
|
|
|
// 无法直接查看的文件,下载到客户端
|
|
// 无法直接查看的文件,下载到客户端
|
|
|
download(info.getId(), response);
|
|
download(info.getId(), response);
|
|
@@ -248,8 +242,7 @@ public class FileController {
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
out.putArchiveEntry(new ZipArchiveEntry(directory + info.getName()));
|
|
out.putArchiveEntry(new ZipArchiveEntry(directory + info.getName()));
|
|
|
- StorePath path = StorePath.praseFromUrl(info.getFullPath());
|
|
|
|
|
- storageClient.downloadFile(path.getGroup(), path.getPath(), in -> IOUtils.copy(in, out));
|
|
|
|
|
|
|
+ storageClient.downloadFile(info.getFullPath(), out);
|
|
|
out.closeArchiveEntry();
|
|
out.closeArchiveEntry();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|