Browse Source

支持列表、移动、删除、创建文件夹

main
zhouxin 4 years ago
parent
commit
4e6d717107
  1. 2
      src/main/java/com/github/zxbu/webdavteambition/client/AliYunDriverClient.java
  2. 57
      src/main/java/com/github/zxbu/webdavteambition/model/CreateFileRequest.java
  3. 48
      src/main/java/com/github/zxbu/webdavteambition/model/MoveRequest.java
  4. 20
      src/main/java/com/github/zxbu/webdavteambition/model/RemoveRequest.java
  5. 30
      src/main/java/com/github/zxbu/webdavteambition/model/RenameRequest.java
  6. 48
      src/main/java/com/github/zxbu/webdavteambition/model/UploadFinalRequest.java
  7. 125
      src/main/java/com/github/zxbu/webdavteambition/model/UploadPreRequest.java
  8. 9
      src/main/java/com/github/zxbu/webdavteambition/model/result/TFile.java
  9. 71
      src/main/java/com/github/zxbu/webdavteambition/model/result/UploadPreResult.java
  10. 156
      src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java

2
src/main/java/com/github/zxbu/webdavteambition/client/AliYunDriverClient.java

@ -63,7 +63,7 @@ public class AliYunDriverClient {
.put(RequestBody.create(MediaType.parse(""), bytes, offset, byteCount)) .put(RequestBody.create(MediaType.parse(""), bytes, offset, byteCount))
.url(url).build(); .url(url).build();
try (Response response = okHttpClient.newCall(request).execute()){ try (Response response = okHttpClient.newCall(request).execute()){
LOGGER.info("post {}, code {}", url, response.code()); LOGGER.info("upload {}, code {}", url, response.code());
if (!response.isSuccessful()) { if (!response.isSuccessful()) {
LOGGER.error("请求失败,url={}, code={}, body={}", url, response.code(), response.body().string()); LOGGER.error("请求失败,url={}, code={}, body={}", url, response.code(), response.body().string());
throw new WebdavException("请求失败:" + url); throw new WebdavException("请求失败:" + url);

57
src/main/java/com/github/zxbu/webdavteambition/model/CreateFileRequest.java

@ -1,29 +1,26 @@
package com.github.zxbu.webdavteambition.model; package com.github.zxbu.webdavteambition.model;
public class CreateFileRequest { public class CreateFileRequest {
private String ccpParentId; private String check_name_mode = "refuse";
private String checkNameMode = "refuse"; private String drive_id;
private String driveId;
private String name; private String name;
private String orgId; private String parent_file_id;
private String parentId;
private String spaceId;
private String type; private String type;
public String getCheckNameMode() { public String getCheck_name_mode() {
return checkNameMode; return check_name_mode;
} }
public void setCheckNameMode(String checkNameMode) { public void setCheck_name_mode(String check_name_mode) {
this.checkNameMode = checkNameMode; this.check_name_mode = check_name_mode;
} }
public String getDriveId() { public String getDrive_id() {
return driveId; return drive_id;
} }
public void setDriveId(String driveId) { public void setDrive_id(String drive_id) {
this.driveId = driveId; this.drive_id = drive_id;
} }
public String getName() { public String getName() {
@ -34,28 +31,12 @@ public class CreateFileRequest {
this.name = name; this.name = name;
} }
public String getOrgId() { public String getParent_file_id() {
return orgId; return parent_file_id;
} }
public void setOrgId(String orgId) { public void setParent_file_id(String parent_file_id) {
this.orgId = orgId; this.parent_file_id = parent_file_id;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public String getSpaceId() {
return spaceId;
}
public void setSpaceId(String spaceId) {
this.spaceId = spaceId;
} }
public String getType() { public String getType() {
@ -65,12 +46,4 @@ public class CreateFileRequest {
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
public String getCcpParentId() {
return ccpParentId;
}
public void setCcpParentId(String ccpParentId) {
this.ccpParentId = ccpParentId;
}
} }

48
src/main/java/com/github/zxbu/webdavteambition/model/MoveRequest.java

@ -3,49 +3,31 @@ package com.github.zxbu.webdavteambition.model;
import java.util.List; import java.util.List;
public class MoveRequest { public class MoveRequest {
private String driveId; private String drive_id;
private String parentId; private String file_id;
private String orgId; private String to_parent_file_id;
private boolean sameLevel = false;
private List<MoveRequestId> ids;
public String getDriveId() {
return driveId;
}
public void setDriveId(String driveId) {
this.driveId = driveId;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public String getOrgId() { public String getDrive_id() {
return orgId; return drive_id;
} }
public void setOrgId(String orgId) { public void setDrive_id(String drive_id) {
this.orgId = orgId; this.drive_id = drive_id;
} }
public boolean isSameLevel() { public String getFile_id() {
return sameLevel; return file_id;
} }
public void setSameLevel(boolean sameLevel) { public void setFile_id(String file_id) {
this.sameLevel = sameLevel; this.file_id = file_id;
} }
public List<MoveRequestId> getIds() { public String getTo_parent_file_id() {
return ids; return to_parent_file_id;
} }
public void setIds(List<MoveRequestId> ids) { public void setTo_parent_file_id(String to_parent_file_id) {
this.ids = ids; this.to_parent_file_id = to_parent_file_id;
} }
} }

20
src/main/java/com/github/zxbu/webdavteambition/model/RemoveRequest.java

@ -3,22 +3,22 @@ package com.github.zxbu.webdavteambition.model;
import java.util.List; import java.util.List;
public class RemoveRequest { public class RemoveRequest {
private String orgId; private String drive_id;
private List<String> nodeIds; private String file_id;
public List<String> getNodeIds() { public String getDrive_id() {
return nodeIds; return drive_id;
} }
public void setNodeIds(List<String> nodeIds) { public void setDrive_id(String drive_id) {
this.nodeIds = nodeIds; this.drive_id = drive_id;
} }
public String getOrgId() { public String getFile_id() {
return orgId; return file_id;
} }
public void setOrgId(String orgId) { public void setFile_id(String file_id) {
this.orgId = orgId; this.file_id = file_id;
} }
} }

30
src/main/java/com/github/zxbu/webdavteambition/model/RenameRequest.java

@ -1,25 +1,25 @@
package com.github.zxbu.webdavteambition.model; package com.github.zxbu.webdavteambition.model;
public class RenameRequest { public class RenameRequest {
private String ccpFileId; private String check_name_mode = "refuse";
private String driveId; private String drive_id;
private String name; private String name;
private String orgId; private String file_id;
public String getCcpFileId() { public String getCheck_name_mode() {
return ccpFileId; return check_name_mode;
} }
public void setCcpFileId(String ccpFileId) { public void setCheck_name_mode(String check_name_mode) {
this.ccpFileId = ccpFileId; this.check_name_mode = check_name_mode;
} }
public String getDriveId() { public String getDrive_id() {
return driveId; return drive_id;
} }
public void setDriveId(String driveId) { public void setDrive_id(String drive_id) {
this.driveId = driveId; this.drive_id = drive_id;
} }
public String getName() { public String getName() {
@ -30,11 +30,11 @@ public class RenameRequest {
this.name = name; this.name = name;
} }
public String getOrgId() { public String getFile_id() {
return orgId; return file_id;
} }
public void setOrgId(String orgId) { public void setFile_id(String file_id) {
this.orgId = orgId; this.file_id = file_id;
} }
} }

48
src/main/java/com/github/zxbu/webdavteambition/model/UploadFinalRequest.java

@ -1,49 +1,31 @@
package com.github.zxbu.webdavteambition.model; package com.github.zxbu.webdavteambition.model;
public class UploadFinalRequest { public class UploadFinalRequest {
private String ccpFileId; private String drive_id;
private String driveId; private String file_id;
private String nodeId; private String upload_id;
private String orgId;
private String uploadId;
public String getDriveId() { public String getDrive_id() {
return driveId; return drive_id;
} }
public void setDriveId(String driveId) { public void setDrive_id(String drive_id) {
this.driveId = driveId; this.drive_id = drive_id;
} }
public String getNodeId() { public String getFile_id() {
return nodeId; return file_id;
} }
public void setNodeId(String nodeId) { public void setFile_id(String file_id) {
this.nodeId = nodeId; this.file_id = file_id;
} }
public String getOrgId() { public String getUpload_id() {
return orgId; return upload_id;
} }
public void setOrgId(String orgId) { public void setUpload_id(String upload_id) {
this.orgId = orgId; this.upload_id = upload_id;
}
public String getUploadId() {
return uploadId;
}
public void setUploadId(String uploadId) {
this.uploadId = uploadId;
}
public String getCcpFileId() {
return ccpFileId;
}
public void setCcpFileId(String ccpFileId) {
this.ccpFileId = ccpFileId;
} }
} }

125
src/main/java/com/github/zxbu/webdavteambition/model/UploadPreRequest.java

@ -3,49 +3,124 @@ package com.github.zxbu.webdavteambition.model;
import java.util.List; import java.util.List;
public class UploadPreRequest { public class UploadPreRequest {
private String checkNameMode = "autoRename"; private String check_name_mode = "refuse";
private String orgId; private String content_hash;
private String parentId; private String content_hash_name = "sha1";
private String spaceId; private String drive_id;
private List<UploadPreInfo> infos; private String name;
private String parent_file_id;
private String proof_code;
private String proof_version = "v1";
private Long size;
private List<PartInfo> part_info_list;
private String type = "file";
public String getCheckNameMode() { public String getCheck_name_mode() {
return checkNameMode; return check_name_mode;
} }
public void setCheckNameMode(String checkNameMode) { public void setCheck_name_mode(String check_name_mode) {
this.checkNameMode = checkNameMode; this.check_name_mode = check_name_mode;
} }
public String getOrgId() { public String getContent_hash() {
return orgId; return content_hash;
} }
public void setOrgId(String orgId) { public void setContent_hash(String content_hash) {
this.orgId = orgId; this.content_hash = content_hash;
} }
public String getParentId() { public String getContent_hash_name() {
return parentId; return content_hash_name;
} }
public void setParentId(String parentId) { public void setContent_hash_name(String content_hash_name) {
this.parentId = parentId; this.content_hash_name = content_hash_name;
} }
public String getSpaceId() { public String getDrive_id() {
return spaceId; return drive_id;
} }
public void setSpaceId(String spaceId) { public void setDrive_id(String drive_id) {
this.spaceId = spaceId; this.drive_id = drive_id;
} }
public List<UploadPreInfo> getInfos() { public String getName() {
return infos; return name;
} }
public void setInfos(List<UploadPreInfo> infos) { public void setName(String name) {
this.infos = infos; this.name = name;
}
public String getParent_file_id() {
return parent_file_id;
}
public void setParent_file_id(String parent_file_id) {
this.parent_file_id = parent_file_id;
}
public String getProof_code() {
return proof_code;
}
public void setProof_code(String proof_code) {
this.proof_code = proof_code;
}
public String getProof_version() {
return proof_version;
}
public void setProof_version(String proof_version) {
this.proof_version = proof_version;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public List<PartInfo> getPart_info_list() {
return part_info_list;
}
public void setPart_info_list(List<PartInfo> part_info_list) {
this.part_info_list = part_info_list;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public static class PartInfo {
private Integer part_number;
private String upload_url;
public Integer getPart_number() {
return part_number;
}
public void setPart_number(Integer part_number) {
this.part_number = part_number;
}
public String getUpload_url() {
return upload_url;
}
public void setUpload_url(String upload_url) {
this.upload_url = upload_url;
}
} }
} }

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

@ -11,6 +11,7 @@ public class TFile {
private String file_id; private String file_id;
private Boolean hidden; private Boolean hidden;
private String name; private String name;
private String file_name;
private String parent_file_id; private String parent_file_id;
private String starred; private String starred;
private String status; private String status;
@ -136,6 +137,14 @@ public class TFile {
this.download_url = download_url; this.download_url = download_url;
} }
public String getFile_name() {
return file_name;
}
public void setFile_name(String file_name) {
this.file_name = file_name;
}
public void setUpdated_at(Date updated_at) { public void setUpdated_at(Date updated_at) {
this.updated_at = updated_at; this.updated_at = updated_at;
} }

71
src/main/java/com/github/zxbu/webdavteambition/model/result/UploadPreResult.java

@ -1,60 +1,71 @@
package com.github.zxbu.webdavteambition.model.result; package com.github.zxbu.webdavteambition.model.result;
import com.github.zxbu.webdavteambition.model.UploadPreRequest;
import java.util.List; import java.util.List;
public class UploadPreResult { public class UploadPreResult {
private String ccpFileId; private String file_id;
private String nodeId; private String file_name;
private String name; private String location;
private String kind; private Boolean rapid_upload;
private String uploadId; private String type;
private List<String> uploadUrl; private String upload_id;
private List<UploadPreRequest.PartInfo> part_info_list;
public String getFile_id() {
return file_id;
}
public void setFile_id(String file_id) {
this.file_id = file_id;
}
public String getNodeId() { public String getFile_name() {
return nodeId; return file_name;
} }
public void setNodeId(String nodeId) { public void setFile_name(String file_name) {
this.nodeId = nodeId; this.file_name = file_name;
} }
public String getName() { public String getLocation() {
return name; return location;
} }
public void setName(String name) { public void setLocation(String location) {
this.name = name; this.location = location;
} }
public String getCcpFileId() { public Boolean getRapid_upload() {
return ccpFileId; return rapid_upload;
} }
public void setCcpFileId(String ccpFileId) { public void setRapid_upload(Boolean rapid_upload) {
this.ccpFileId = ccpFileId; this.rapid_upload = rapid_upload;
} }
public String getKind() { public String getType() {
return kind; return type;
} }
public void setKind(String kind) { public void setType(String type) {
this.kind = kind; this.type = type;
} }
public String getUploadId() { public String getUpload_id() {
return uploadId; return upload_id;
} }
public void setUploadId(String uploadId) { public void setUpload_id(String upload_id) {
this.uploadId = uploadId; this.upload_id = upload_id;
} }
public List<String> getUploadUrl() { public List<UploadPreRequest.PartInfo> getPart_info_list() {
return uploadUrl; return part_info_list;
} }
public void setUploadUrl(List<String> uploadUrl) { public void setPart_info_list(List<UploadPreRequest.PartInfo> part_info_list) {
this.uploadUrl = uploadUrl; this.part_info_list = part_info_list;
} }
} }

156
src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java

@ -96,71 +96,72 @@ public class AliYunDriverClientService {
int chunkCount = (int) Math.ceil(((double) size) / chunkSize); // 进1法 int chunkCount = (int) Math.ceil(((double) size) / chunkSize); // 进1法
UploadPreRequest uploadPreRequest = new UploadPreRequest(); UploadPreRequest uploadPreRequest = new UploadPreRequest();
// uploadPreRequest.setOrgId(client.getOrgId()); uploadPreRequest.setContent_hash(UUID.randomUUID().toString());
// uploadPreRequest.setParentId(parent.getNodeId()); uploadPreRequest.setDrive_id(client.getDriveId());
// uploadPreRequest.setSpaceId(client.getSpaceId()); uploadPreRequest.setName(pathInfo.getName());
UploadPreInfo uploadPreInfo = new UploadPreInfo(); uploadPreRequest.setParent_file_id(parent.getFile_id());
// uploadPreInfo.setCcpParentId(parent.getCcpFileId()); uploadPreRequest.setSize((long) size);
uploadPreInfo.setDriveId(client.getDriveId()); List<UploadPreRequest.PartInfo> part_info_list = new ArrayList<>();
uploadPreInfo.setName(pathInfo.getName()); for (int i = 0; i < chunkCount; i++) {
uploadPreInfo.setSize(size); UploadPreRequest.PartInfo partInfo = new UploadPreRequest.PartInfo();
uploadPreInfo.setChunkCount(chunkCount); partInfo.setPart_number(i + 1);
uploadPreInfo.setType(FileType.file.name()); part_info_list.add(partInfo);
uploadPreRequest.setInfos(Collections.singletonList(uploadPreInfo)); }
uploadPreRequest.setPart_info_list(part_info_list);
LOGGER.info("开始上传文件,文件名:{},总大小:{}, 文件块数量:{}", path, size, chunkCount); LOGGER.info("开始上传文件,文件名:{},总大小:{}, 文件块数量:{}", path, size, chunkCount);
String json = client.post("/pan/api/nodes/file", uploadPreRequest); String json = client.post("/file/create_with_proof", uploadPreRequest);
List<UploadPreResult> uploadPreResultList = JsonUtil.readValue(json, new TypeReference<List<UploadPreResult>>() { UploadPreResult uploadPreResult = JsonUtil.readValue(json, UploadPreResult.class);
}); List<UploadPreRequest.PartInfo> partInfoList = uploadPreResult.getPart_info_list();
UploadPreResult uploadPreResult = uploadPreResultList.get(0); if (partInfoList != null) {
List<String> uploadUrl = uploadPreResult.getUploadUrl(); LOGGER.info("文件预处理成功,开始上传。文件名:{},上传URL数量:{}", path, partInfoList.size());
LOGGER.info("文件预处理成功,开始上传。文件名:{},上传URL数量:{}", path, uploadUrl.size());
byte[] buffer = new byte[chunkSize];
for (int i = 0; i < uploadUrl.size(); i++) {
String oneUploadUrl = uploadUrl.get(i);
try {
int read = IOUtils.read(inputStream, buffer, 0, buffer.length);
if (read == -1) {
return;
}
client.upload(oneUploadUrl, buffer, 0, read);
LOGGER.info("文件正在上传。文件名:{},当前进度:{}/{}", path, (i+1), uploadUrl.size());
} catch (IOException e) { byte[] buffer = new byte[chunkSize];
throw new WebdavException(e); for (int i = 0; i < partInfoList.size(); i++) {
UploadPreRequest.PartInfo partInfo = partInfoList.get(i);
try {
int read = IOUtils.read(inputStream, buffer, 0, buffer.length);
if (read == -1) {
return;
}
client.upload(partInfo.getUpload_url(), buffer, 0, read);
LOGGER.info("文件正在上传。文件名:{},当前进度:{}/{}", path, (i+1), partInfoList.size());
} catch (IOException e) {
throw new WebdavException(e);
}
} }
} }
UploadFinalRequest uploadFinalRequest = new UploadFinalRequest(); UploadFinalRequest uploadFinalRequest = new UploadFinalRequest();
uploadFinalRequest.setCcpFileId(uploadPreResult.getCcpFileId()); uploadFinalRequest.setFile_id(uploadPreResult.getFile_id());
uploadFinalRequest.setDriveId(client.getDriveId()); uploadFinalRequest.setDrive_id(client.getDriveId());
uploadFinalRequest.setNodeId(uploadPreResult.getNodeId()); uploadFinalRequest.setUpload_id(uploadPreResult.getUpload_id());
// uploadFinalRequest.setOrgId(client.getOrgId());
uploadFinalRequest.setUploadId(uploadPreResult.getUploadId()); client.post("/file/complete", uploadFinalRequest);
client.post("/pan/api/nodes/complete", uploadFinalRequest);
LOGGER.info("文件上传成功。文件名:{}", path); LOGGER.info("文件上传成功。文件名:{}", path);
if (!uploadPreResult.getName().equals(pathInfo.getName())) { // if (!uploadPreResult.getName().equals(pathInfo.getName())) {
LOGGER.info("上传文件名{}与原文件名{}不同,对文件进行重命名", uploadPreResult.getName(), pathInfo.getName()); // LOGGER.info("上传文件名{}与原文件名{}不同,对文件进行重命名", uploadPreResult.getName(), pathInfo.getName());
TFile oldFile = getNodeIdByPath2(path); // TFile oldFile = getNodeIdByPath2(path);
// 如果旧文件存在,则先删除 // // 如果旧文件存在,则先删除
if (oldFile != null) { // if (oldFile != null) {
LOGGER.info("旧文件{}还存在,大小为{},进行删除操作,可前往网页版的回收站查看", path, oldFile.getSize()); // LOGGER.info("旧文件{}还存在,大小为{},进行删除操作,可前往网页版的回收站查看", path, oldFile.getSize());
remove(path); // remove(path);
try { // try {
Thread.sleep(1500); // Thread.sleep(1500);
} catch (InterruptedException e) { // } catch (InterruptedException e) {
// no // // no
} // }
} // }
RenameRequest renameRequest = new RenameRequest(); // RenameRequest renameRequest = new RenameRequest();
renameRequest.setCcpFileId(uploadPreResult.getCcpFileId()); // renameRequest.setDrive_id(client.getDriveId());
renameRequest.setDriveId(client.getDriveId()); // renameRequest.setFile_id(oldFile.getFile_id());
// renameRequest.setOrgId(client.getOrgId()); // renameRequest.setName(pathInfo.getName());
renameRequest.setName(pathInfo.getName()); // client.post("/file/update", renameRequest);
client.put("/pan/api/nodes/" + uploadPreResult.getNodeId(), renameRequest); // }
}
clearCache(); clearCache();
} }
@ -168,11 +169,10 @@ public class AliYunDriverClientService {
sourcePath = normalizingPath(sourcePath); sourcePath = normalizingPath(sourcePath);
TFile tFile = getTFileByPath(sourcePath); TFile tFile = getTFileByPath(sourcePath);
RenameRequest renameRequest = new RenameRequest(); RenameRequest renameRequest = new RenameRequest();
// renameRequest.setCcpFileId(tFile.getCcpFileId()); renameRequest.setDrive_id(client.getDriveId());
renameRequest.setDriveId(client.getDriveId()); renameRequest.setFile_id(tFile.getFile_id());
// renameRequest.setOrgId(client.getOrgId());
renameRequest.setName(newName); renameRequest.setName(newName);
// client.put("/pan/api/nodes/" + tFile.getNodeId(), renameRequest); client.post("/file/update", renameRequest);
clearCache(); clearCache();
} }
@ -183,15 +183,10 @@ public class AliYunDriverClientService {
TFile sourceTFile = getTFileByPath(sourcePath); TFile sourceTFile = getTFileByPath(sourcePath);
TFile targetTFile = getTFileByPath(targetPath); TFile targetTFile = getTFileByPath(targetPath);
MoveRequest moveRequest = new MoveRequest(); MoveRequest moveRequest = new MoveRequest();
// moveRequest.setOrgId(client.getOrgId()); moveRequest.setDrive_id(client.getDriveId());
moveRequest.setDriveId(client.getDriveId()); moveRequest.setFile_id(sourceTFile.getFile_id());
// moveRequest.setParentId(targetTFile.getNodeId()); moveRequest.setTo_parent_file_id(targetTFile.getFile_id());
MoveRequestId moveRequestId = new MoveRequestId(); client.post("/file/move", moveRequest);
// moveRequestId.setCcpFileId(sourceTFile.getCcpFileId());
// moveRequestId.setId(sourceTFile.getNodeId());
moveRequest.setIds(Collections.singletonList(moveRequestId));
client.post("/pan/api/nodes/move", moveRequest);
clearCache();
clearCache(); clearCache();
} }
@ -202,9 +197,9 @@ public class AliYunDriverClientService {
return; return;
} }
RemoveRequest removeRequest = new RemoveRequest(); RemoveRequest removeRequest = new RemoveRequest();
// removeRequest.setOrgId(client.getOrgId()); removeRequest.setDrive_id(client.getDriveId());
// removeRequest.setNodeIds(Collections.singletonList(tFile.getNodeId())); removeRequest.setFile_id(tFile.getFile_id());
client.post("/pan/api/nodes/archive", removeRequest); client.post("/recyclebin/trash", removeRequest);
clearCache(); clearCache();
} }
@ -219,21 +214,16 @@ public class AliYunDriverClientService {
} }
CreateFileRequest createFileRequest = new CreateFileRequest(); CreateFileRequest createFileRequest = new CreateFileRequest();
// createFileRequest.setCcpParentId(parent.getCcpFileId()); createFileRequest.setDrive_id(client.getDriveId());
createFileRequest.setDriveId(client.getDriveId());
createFileRequest.setName(pathInfo.getName()); createFileRequest.setName(pathInfo.getName());
// createFileRequest.setOrgId(client.getOrgId()); createFileRequest.setParent_file_id(parent.getFile_id());
// createFileRequest.setParentId(parent.getNodeId());
// createFileRequest.setSpaceId(client.getSpaceId());
createFileRequest.setType(FileType.folder.name()); createFileRequest.setType(FileType.folder.name());
String json = client.post("/pan/api/nodes/folder", createFileRequest); String json = client.post("/file/create_with_proof", createFileRequest);
List<CreateFileResult> createFileResults = JsonUtil.readValue(json, new TypeReference<List<CreateFileResult>>() { TFile createFileResult = JsonUtil.readValue(json, TFile.class);
}); if (createFileResult.getFile_name() == null) {
if (createFileResults.size() != 1) {
LOGGER.error("创建目录{}失败: {}",path, json); LOGGER.error("创建目录{}失败: {}",path, json);
} }
CreateFileResult createFileResult = createFileResults.get(0); if (!createFileResult.getFile_name().equals(pathInfo.getName())) {
if (!createFileResult.getName().equals(pathInfo.getName())) {
LOGGER.info("创建目录{}与原值{}不同,重命名", createFileResult.getName(), pathInfo.getName()); LOGGER.info("创建目录{}与原值{}不同,重命名", createFileResult.getName(), pathInfo.getName());
rename(pathInfo.getParentPath() + "/" + createFileResult.getName(), pathInfo.getName()); rename(pathInfo.getParentPath() + "/" + createFileResult.getName(), pathInfo.getName());
clearCache(); clearCache();

Loading…
Cancel
Save