Browse Source

修复文件同名的BUG

main
zhouxin5253@163.com 4 years ago
parent
commit
5af1fc9b1a
  1. 16
      src/main/java/com/github/zxbu/webdavteambition/model/result/TFile.java
  2. 16
      src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java

16
src/main/java/com/github/zxbu/webdavteambition/model/result/TFile.java

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
package com.github.zxbu.webdavteambition.model.result;
import java.util.Date;
import java.util.Objects;
public class TFile {
private String kind;
@ -102,4 +103,19 @@ public class TFile { @@ -102,4 +103,19 @@ public class TFile {
public void setSize(Long size) {
this.size = size;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TFile tFile = (TFile) o;
return Objects.equals(kind, tFile.kind) &&
Objects.equals(name, tFile.name) &&
Objects.equals(parentId, tFile.parentId);
}
@Override
public int hashCode() {
return Objects.hash(kind, name, parentId);
}
}

16
src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java

@ -16,11 +16,9 @@ import org.springframework.util.StringUtils; @@ -16,11 +16,9 @@ import org.springframework.util.StringUtils;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Service
public class TeambitionClientService {
@ -51,7 +49,9 @@ public class TeambitionClientService { @@ -51,7 +49,9 @@ public class TeambitionClientService {
String json = client.get("/pan/api/nodes", toMap(nodeQuery));
ListResult<TFile> tFileListResult = JsonUtil.readValue(json, new TypeReference<ListResult<TFile>>() {
});
return tFileListResult.getData();
List<TFile> tFileList = tFileListResult.getData();
// 对文件名进行去重,只保留最新的一个
return tFileList.stream().sorted(Comparator.comparing(TFile::getUpdated).reversed()).distinct().collect(Collectors.toList());
}
@ -125,6 +125,11 @@ public class TeambitionClientService { @@ -125,6 +125,11 @@ public class TeambitionClientService {
LOGGER.info("文件上传成功。文件名:{}", path);
if (!uploadPreResult.getName().equals(pathInfo.getName())) {
LOGGER.info("上传文件名{}与原文件名{}不同,对文件进行重命名", uploadPreResult.getName(), pathInfo.getName());
TFile oldFile = getNodeIdByPath2(path);
// 如果旧文件存在,则先删除
if (oldFile != null) {
remove(path);
}
RenameRequest renameRequest = new RenameRequest();
renameRequest.setCcpFileId(uploadPreResult.getCcpFileId());
renameRequest.setDriveId(client.getDriveId());
@ -269,6 +274,7 @@ public class TeambitionClientService { @@ -269,6 +274,7 @@ public class TeambitionClientService {
return null;
}
private String normalizingPath(String path) {
path = path.replaceAll("//", "/");
if (path.endsWith("/")) {

Loading…
Cancel
Save