|
|
@@ -12,7 +12,7 @@ import cn.reghao.oss.sdk.model.dto.ObjectInfo;
|
|
|
import cn.reghao.tnb.common.auth.UserContext;
|
|
|
import cn.reghao.tnb.common.util.StringUtil;
|
|
|
import cn.reghao.tnb.content.app.disk.db.mapper.DiskFileMapper;
|
|
|
-import cn.reghao.tnb.content.app.disk.model.dto.CreateFile;
|
|
|
+import cn.reghao.tnb.content.app.disk.model.dto.UploadedFile;
|
|
|
import cn.reghao.tnb.content.app.disk.model.dto.MoveFile;
|
|
|
import cn.reghao.tnb.content.app.disk.model.po.DiskFile;
|
|
|
import cn.reghao.tnb.content.app.disk.model.query.DiskQuery;
|
|
|
@@ -21,7 +21,6 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -45,27 +44,24 @@ public class DiskFileService {
|
|
|
this.byteConverter = new ByteConverter();
|
|
|
}
|
|
|
|
|
|
- public Result addDiskFile(CreateFile createFile) {
|
|
|
- String parentPath = createFile.getParentPath();
|
|
|
- File file = new File(parentPath);
|
|
|
- String filename = createFile.getFilename();
|
|
|
- String path = String.format("%s/%s", file.getAbsolutePath(), filename);
|
|
|
-
|
|
|
- DiskFile diskFile1 = diskSyncService.checkFile(parentPath);
|
|
|
+ public Result addDiskFile(UploadedFile uploadedFile) {
|
|
|
+ String pid = uploadedFile.getPid();
|
|
|
+ DiskFile diskFile1 = findByFileId(pid);
|
|
|
if (diskFile1 == null) {
|
|
|
return Result.fail("folder not exist");
|
|
|
}
|
|
|
- String pid = diskFile1.getFileId();
|
|
|
-
|
|
|
- DiskFile diskFile2 = diskSyncService.checkFile(path);
|
|
|
- if (diskFile2 != null) {
|
|
|
- return Result.fail("file exist");
|
|
|
- }
|
|
|
-
|
|
|
- int channelCode = createFile.getChannelCode();
|
|
|
- String uploadId = createFile.getUploadId();
|
|
|
+ String parentPath = diskFile1.getPath();
|
|
|
try {
|
|
|
+ int channelCode = uploadedFile.getChannelCode();
|
|
|
+ String uploadId = uploadedFile.getUploadId();
|
|
|
ObjectInfo objectInfo = ossService.getObjectInfo(channelCode, uploadId);
|
|
|
+ String filename = objectInfo.getFilename();
|
|
|
+ String path = String.format("%s/%s", parentPath, filename);
|
|
|
+ DiskFile diskFile2 = diskSyncService.checkFile(path);
|
|
|
+ if (diskFile2 != null) {
|
|
|
+ return Result.fail("file exist");
|
|
|
+ }
|
|
|
+
|
|
|
long size = objectInfo.getSize();
|
|
|
int fileType = objectInfo.getFileType();
|
|
|
String sha256sum = objectInfo.getSha256sum();
|
|
|
@@ -467,7 +463,18 @@ public class DiskFileService {
|
|
|
.path(path)
|
|
|
.owner(owner)
|
|
|
.build();
|
|
|
- Page page = new Page(1, 10);
|
|
|
+ Page page = new Page(1, 1);
|
|
|
+ List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
+ return diskFileList.isEmpty() ? null : diskFileList.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public DiskFile findByFileId(String fileId) {
|
|
|
+ long owner = UserContext.getUserId();
|
|
|
+ DiskQuery diskQuery = new DiskQuery.Builder()
|
|
|
+ .fileId(fileId)
|
|
|
+ .owner(owner)
|
|
|
+ .build();
|
|
|
+ Page page = new Page(1, 1);
|
|
|
List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
|
|
|
return diskFileList.isEmpty() ? null : diskFileList.get(0);
|
|
|
}
|