|
|
@ -2,10 +2,10 @@ package com.github.zxbu.webdavteambition.store; |
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.github.zxbu.webdavteambition.client.TeambitionClient; |
|
|
|
import com.github.zxbu.webdavteambition.client.AliYunDriverClient; |
|
|
|
import com.github.zxbu.webdavteambition.model.*; |
|
|
|
import com.github.zxbu.webdavteambition.model.*; |
|
|
|
import com.github.zxbu.webdavteambition.model.result.CreateFileResult; |
|
|
|
import com.github.zxbu.webdavteambition.model.result.CreateFileResult; |
|
|
|
import com.github.zxbu.webdavteambition.model.result.ListResult; |
|
|
|
import com.github.zxbu.webdavteambition.model.result.TFileListResult; |
|
|
|
import com.github.zxbu.webdavteambition.model.result.TFile; |
|
|
|
import com.github.zxbu.webdavteambition.model.result.TFile; |
|
|
|
import com.github.zxbu.webdavteambition.model.result.UploadPreResult; |
|
|
|
import com.github.zxbu.webdavteambition.model.result.UploadPreResult; |
|
|
|
import com.github.zxbu.webdavteambition.util.JsonUtil; |
|
|
|
import com.github.zxbu.webdavteambition.util.JsonUtil; |
|
|
@ -22,19 +22,19 @@ import java.util.*; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
@Service |
|
|
|
public class TeambitionClientService { |
|
|
|
public class AliYunDriverClientService { |
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TeambitionClientService.class); |
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(AliYunDriverClientService.class); |
|
|
|
private static ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
private static ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
private static String rootPath = "/"; |
|
|
|
private static String rootPath = "/"; |
|
|
|
private static int chunkSize = 10485760; // 10MB
|
|
|
|
private static int chunkSize = 10485760; // 10MB
|
|
|
|
private TFile rootTFile = null; |
|
|
|
private TFile rootTFile = null; |
|
|
|
private ThreadLocal<Map<String, Set<TFile>>> tFilesCache = new ThreadLocal<>(); |
|
|
|
private ThreadLocal<Map<String, Set<TFile>>> tFilesCache = new ThreadLocal<>(); |
|
|
|
|
|
|
|
|
|
|
|
private final TeambitionClient client; |
|
|
|
private final AliYunDriverClient client; |
|
|
|
|
|
|
|
|
|
|
|
public TeambitionClientService(TeambitionClient teambitionClient) { |
|
|
|
public AliYunDriverClientService(AliYunDriverClient aliYunDriverClient) { |
|
|
|
this.client = teambitionClient; |
|
|
|
this.client = aliYunDriverClient; |
|
|
|
TeambitionFileSystemStore.setBean(this); |
|
|
|
AliYunDriverFileSystemStore.setBean(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Set<TFile> getTFiles(String nodeId) { |
|
|
|
public Set<TFile> getTFiles(String nodeId) { |
|
|
@ -44,20 +44,18 @@ public class TeambitionClientService { |
|
|
|
tFilesCache.set(map); |
|
|
|
tFilesCache.set(map); |
|
|
|
} |
|
|
|
} |
|
|
|
return map.computeIfAbsent(nodeId, key -> { |
|
|
|
return map.computeIfAbsent(nodeId, key -> { |
|
|
|
NodeQuery nodeQuery = new NodeQuery(); |
|
|
|
FileListRequest listQuery = new FileListRequest(); |
|
|
|
nodeQuery.setOrgId(client.getOrgId()); |
|
|
|
listQuery.setOffset(0); |
|
|
|
nodeQuery.setOffset(0); |
|
|
|
listQuery.setLimit(10000); |
|
|
|
nodeQuery.setLimit(10000); |
|
|
|
listQuery.setOrder_by("updated_at"); |
|
|
|
nodeQuery.setOrderBy("updateTime"); |
|
|
|
listQuery.setOrder_direction("DESC"); |
|
|
|
nodeQuery.setOrderDirection("desc"); |
|
|
|
listQuery.setDrive_id(client.getDriveId()); |
|
|
|
nodeQuery.setDriveId(client.getDriveId()); |
|
|
|
listQuery.setParent_file_id(nodeId); |
|
|
|
nodeQuery.setSpaceId(client.getSpaceId()); |
|
|
|
String json = client.post("/file/list", listQuery); |
|
|
|
nodeQuery.setParentId(nodeId); |
|
|
|
TFileListResult<TFile> tFileListResult = JsonUtil.readValue(json, new TypeReference<TFileListResult<TFile>>() { |
|
|
|
String json = client.get("/pan/api/nodes", toMap(nodeQuery)); |
|
|
|
|
|
|
|
ListResult<TFile> tFileListResult = JsonUtil.readValue(json, new TypeReference<ListResult<TFile>>() { |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
List<TFile> tFileList = tFileListResult.getData(); |
|
|
|
List<TFile> tFileList = tFileListResult.getItems(); |
|
|
|
tFileList.sort(Comparator.comparing(TFile::getUpdated).reversed()); |
|
|
|
tFileList.sort(Comparator.comparing(TFile::getUpdated_at).reversed()); |
|
|
|
Set<TFile> tFileSets = new LinkedHashSet<>(); |
|
|
|
Set<TFile> tFileSets = new LinkedHashSet<>(); |
|
|
|
for (TFile tFile : tFileList) { |
|
|
|
for (TFile tFile : tFileList) { |
|
|
|
if (!tFileSets.add(tFile)) { |
|
|
|
if (!tFileSets.add(tFile)) { |
|
|
@ -98,11 +96,11 @@ public class TeambitionClientService { |
|
|
|
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.setOrgId(client.getOrgId());
|
|
|
|
uploadPreRequest.setParentId(parent.getNodeId()); |
|
|
|
// uploadPreRequest.setParentId(parent.getNodeId());
|
|
|
|
uploadPreRequest.setSpaceId(client.getSpaceId()); |
|
|
|
// uploadPreRequest.setSpaceId(client.getSpaceId());
|
|
|
|
UploadPreInfo uploadPreInfo = new UploadPreInfo(); |
|
|
|
UploadPreInfo uploadPreInfo = new UploadPreInfo(); |
|
|
|
uploadPreInfo.setCcpParentId(parent.getCcpFileId()); |
|
|
|
// uploadPreInfo.setCcpParentId(parent.getCcpFileId());
|
|
|
|
uploadPreInfo.setDriveId(client.getDriveId()); |
|
|
|
uploadPreInfo.setDriveId(client.getDriveId()); |
|
|
|
uploadPreInfo.setName(pathInfo.getName()); |
|
|
|
uploadPreInfo.setName(pathInfo.getName()); |
|
|
|
uploadPreInfo.setSize(size); |
|
|
|
uploadPreInfo.setSize(size); |
|
|
@ -139,7 +137,7 @@ public class TeambitionClientService { |
|
|
|
uploadFinalRequest.setCcpFileId(uploadPreResult.getCcpFileId()); |
|
|
|
uploadFinalRequest.setCcpFileId(uploadPreResult.getCcpFileId()); |
|
|
|
uploadFinalRequest.setDriveId(client.getDriveId()); |
|
|
|
uploadFinalRequest.setDriveId(client.getDriveId()); |
|
|
|
uploadFinalRequest.setNodeId(uploadPreResult.getNodeId()); |
|
|
|
uploadFinalRequest.setNodeId(uploadPreResult.getNodeId()); |
|
|
|
uploadFinalRequest.setOrgId(client.getOrgId()); |
|
|
|
// uploadFinalRequest.setOrgId(client.getOrgId());
|
|
|
|
uploadFinalRequest.setUploadId(uploadPreResult.getUploadId()); |
|
|
|
uploadFinalRequest.setUploadId(uploadPreResult.getUploadId()); |
|
|
|
client.post("/pan/api/nodes/complete", uploadFinalRequest); |
|
|
|
client.post("/pan/api/nodes/complete", uploadFinalRequest); |
|
|
|
LOGGER.info("文件上传成功。文件名:{}", path); |
|
|
|
LOGGER.info("文件上传成功。文件名:{}", path); |
|
|
@ -159,7 +157,7 @@ public class TeambitionClientService { |
|
|
|
RenameRequest renameRequest = new RenameRequest(); |
|
|
|
RenameRequest renameRequest = new RenameRequest(); |
|
|
|
renameRequest.setCcpFileId(uploadPreResult.getCcpFileId()); |
|
|
|
renameRequest.setCcpFileId(uploadPreResult.getCcpFileId()); |
|
|
|
renameRequest.setDriveId(client.getDriveId()); |
|
|
|
renameRequest.setDriveId(client.getDriveId()); |
|
|
|
renameRequest.setOrgId(client.getOrgId()); |
|
|
|
// renameRequest.setOrgId(client.getOrgId());
|
|
|
|
renameRequest.setName(pathInfo.getName()); |
|
|
|
renameRequest.setName(pathInfo.getName()); |
|
|
|
client.put("/pan/api/nodes/" + uploadPreResult.getNodeId(), renameRequest); |
|
|
|
client.put("/pan/api/nodes/" + uploadPreResult.getNodeId(), renameRequest); |
|
|
|
} |
|
|
|
} |
|
|
@ -170,11 +168,11 @@ public class TeambitionClientService { |
|
|
|
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.setCcpFileId(tFile.getCcpFileId());
|
|
|
|
renameRequest.setDriveId(client.getDriveId()); |
|
|
|
renameRequest.setDriveId(client.getDriveId()); |
|
|
|
renameRequest.setOrgId(client.getOrgId()); |
|
|
|
// renameRequest.setOrgId(client.getOrgId());
|
|
|
|
renameRequest.setName(newName); |
|
|
|
renameRequest.setName(newName); |
|
|
|
client.put("/pan/api/nodes/" + tFile.getNodeId(), renameRequest); |
|
|
|
// client.put("/pan/api/nodes/" + tFile.getNodeId(), renameRequest);
|
|
|
|
clearCache(); |
|
|
|
clearCache(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -185,12 +183,12 @@ public class TeambitionClientService { |
|
|
|
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.setOrgId(client.getOrgId());
|
|
|
|
moveRequest.setDriveId(client.getDriveId()); |
|
|
|
moveRequest.setDriveId(client.getDriveId()); |
|
|
|
moveRequest.setParentId(targetTFile.getNodeId()); |
|
|
|
// moveRequest.setParentId(targetTFile.getNodeId());
|
|
|
|
MoveRequestId moveRequestId = new MoveRequestId(); |
|
|
|
MoveRequestId moveRequestId = new MoveRequestId(); |
|
|
|
moveRequestId.setCcpFileId(sourceTFile.getCcpFileId()); |
|
|
|
// moveRequestId.setCcpFileId(sourceTFile.getCcpFileId());
|
|
|
|
moveRequestId.setId(sourceTFile.getNodeId()); |
|
|
|
// moveRequestId.setId(sourceTFile.getNodeId());
|
|
|
|
moveRequest.setIds(Collections.singletonList(moveRequestId)); |
|
|
|
moveRequest.setIds(Collections.singletonList(moveRequestId)); |
|
|
|
client.post("/pan/api/nodes/move", moveRequest); |
|
|
|
client.post("/pan/api/nodes/move", moveRequest); |
|
|
|
clearCache(); |
|
|
|
clearCache(); |
|
|
@ -204,8 +202,8 @@ public class TeambitionClientService { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
RemoveRequest removeRequest = new RemoveRequest(); |
|
|
|
RemoveRequest removeRequest = new RemoveRequest(); |
|
|
|
removeRequest.setOrgId(client.getOrgId()); |
|
|
|
// removeRequest.setOrgId(client.getOrgId());
|
|
|
|
removeRequest.setNodeIds(Collections.singletonList(tFile.getNodeId())); |
|
|
|
// removeRequest.setNodeIds(Collections.singletonList(tFile.getNodeId()));
|
|
|
|
client.post("/pan/api/nodes/archive", removeRequest); |
|
|
|
client.post("/pan/api/nodes/archive", removeRequest); |
|
|
|
clearCache(); |
|
|
|
clearCache(); |
|
|
|
} |
|
|
|
} |
|
|
@ -221,12 +219,12 @@ public class TeambitionClientService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CreateFileRequest createFileRequest = new CreateFileRequest(); |
|
|
|
CreateFileRequest createFileRequest = new CreateFileRequest(); |
|
|
|
createFileRequest.setCcpParentId(parent.getCcpFileId()); |
|
|
|
// createFileRequest.setCcpParentId(parent.getCcpFileId());
|
|
|
|
createFileRequest.setDriveId(client.getDriveId()); |
|
|
|
createFileRequest.setDriveId(client.getDriveId()); |
|
|
|
createFileRequest.setName(pathInfo.getName()); |
|
|
|
createFileRequest.setName(pathInfo.getName()); |
|
|
|
createFileRequest.setOrgId(client.getOrgId()); |
|
|
|
// createFileRequest.setOrgId(client.getOrgId());
|
|
|
|
createFileRequest.setParentId(parent.getNodeId()); |
|
|
|
// createFileRequest.setParentId(parent.getNodeId());
|
|
|
|
createFileRequest.setSpaceId(client.getSpaceId()); |
|
|
|
// 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("/pan/api/nodes/folder", createFileRequest); |
|
|
|
List<CreateFileResult> createFileResults = JsonUtil.readValue(json, new TypeReference<List<CreateFileResult>>() { |
|
|
|
List<CreateFileResult> createFileResults = JsonUtil.readValue(json, new TypeReference<List<CreateFileResult>>() { |
|
|
@ -251,8 +249,8 @@ public class TeambitionClientService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public InputStream download(String path) { |
|
|
|
public InputStream download(String path) { |
|
|
|
String downloadUrl = getTFileByPath(path).getDownloadUrl(); |
|
|
|
// String downloadUrl = getTFileByPath(path).getDownloadUrl();
|
|
|
|
return client.download(downloadUrl); |
|
|
|
return client.download("downloadUrl"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private TFile getNodeIdByPath2(String path) { |
|
|
|
private TFile getNodeIdByPath2(String path) { |
|
|
@ -267,7 +265,7 @@ public class TeambitionClientService { |
|
|
|
if (tFile == null ) { |
|
|
|
if (tFile == null ) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
return getNodeIdByParentId(tFile.getNodeId(), pathInfo.getName()); |
|
|
|
return getNodeIdByParentId(tFile.getFile_id(), pathInfo.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -291,12 +289,17 @@ public class TeambitionClientService { |
|
|
|
|
|
|
|
|
|
|
|
private TFile getRootTFile() { |
|
|
|
private TFile getRootTFile() { |
|
|
|
if (rootTFile == null) { |
|
|
|
if (rootTFile == null) { |
|
|
|
NodeQuery nodeQuery = new NodeQuery(); |
|
|
|
// FileGetRequest fileGetRequest = new FileGetRequest();
|
|
|
|
nodeQuery.setOrgId(client.getOrgId()); |
|
|
|
// fileGetRequest.setFile_id("root");
|
|
|
|
nodeQuery.setDriveId(client.getDriveId()); |
|
|
|
// fileGetRequest.setDrive_id(client.getDriveId());
|
|
|
|
nodeQuery.setSpaceId(client.getSpaceId()); |
|
|
|
// String json = client.post("/file/get", fileGetRequest);
|
|
|
|
String json = client.get("/pan/api/nodes/" + client.getRootId(), toMap(nodeQuery)); |
|
|
|
// rootTFile = JsonUtil.readValue(json, TFile.class);
|
|
|
|
rootTFile = JsonUtil.readValue(json, TFile.class); |
|
|
|
rootTFile = new TFile(); |
|
|
|
|
|
|
|
rootTFile.setName("/"); |
|
|
|
|
|
|
|
rootTFile.setFile_id("root"); |
|
|
|
|
|
|
|
rootTFile.setCreated_at(new Date()); |
|
|
|
|
|
|
|
rootTFile.setUpdated_at(new Date()); |
|
|
|
|
|
|
|
rootTFile.setType("folder"); |
|
|
|
} |
|
|
|
} |
|
|
|
return rootTFile; |
|
|
|
return rootTFile; |
|
|
|
} |
|
|
|
} |