diff --git a/src/main/java/com/github/zxbu/webdavteambition/model/result/CreateFileResult.java b/src/main/java/com/github/zxbu/webdavteambition/model/result/CreateFileResult.java new file mode 100644 index 0000000..e424f5f --- /dev/null +++ b/src/main/java/com/github/zxbu/webdavteambition/model/result/CreateFileResult.java @@ -0,0 +1,40 @@ +package com.github.zxbu.webdavteambition.model.result; + +public class CreateFileResult { + private String ccpFileId; + private String nodeId; + private String name; + private String kind; + + public String getCcpFileId() { + return ccpFileId; + } + + public void setCcpFileId(String ccpFileId) { + this.ccpFileId = ccpFileId; + } + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } +} diff --git a/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java b/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java index 7c64310..28b32f9 100644 --- a/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java +++ b/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.zxbu.webdavteambition.client.TeambitionClient; import com.github.zxbu.webdavteambition.model.*; +import com.github.zxbu.webdavteambition.model.result.CreateFileResult; import com.github.zxbu.webdavteambition.model.result.ListResult; import com.github.zxbu.webdavteambition.model.result.TFile; import com.github.zxbu.webdavteambition.model.result.UploadPreResult; @@ -198,6 +199,7 @@ public class TeambitionClientService { PathInfo pathInfo = getPathInfo(path); TFile parent = getTFileByPath(pathInfo.getParentPath()); if (parent == null) { + LOGGER.warn("创建目录失败,未发现父级目录:{}", pathInfo.getParentPath()); return; } @@ -209,7 +211,18 @@ public class TeambitionClientService { createFileRequest.setParentId(parent.getNodeId()); createFileRequest.setSpaceId(client.getSpaceId()); createFileRequest.setType(FileType.folder.name()); - client.post("/pan/api/nodes/folder", createFileRequest); + String json = client.post("/pan/api/nodes/folder", createFileRequest); + List createFileResults = JsonUtil.readValue(json, new TypeReference>() { + }); + if (createFileResults.size() != 1) { + LOGGER.error("创建目录{}失败: {}",path, json); + } + CreateFileResult createFileResult = createFileResults.get(0); + if (!createFileResult.getName().equals(pathInfo.getName())) { + LOGGER.info("创建目录{}与原值{}不同,重命名", createFileResult.getName(), pathInfo.getName()); + rename(pathInfo.getParentPath() + "/" + createFileResult.getName(), pathInfo.getName()); + clearCache(pathInfo.getParentPath() + "/" + createFileResult.getName()); + } clearCache(path); }