|
|
@ -27,8 +27,7 @@ public class TeambitionClientService { |
|
|
|
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 Map<String, TFile> nodeIdMap = new ConcurrentHashMap<>(); |
|
|
|
private ThreadLocal<Map<String, Set<TFile>>> tFilesCache = new ThreadLocal<>(); |
|
|
|
private Map<String, Set<TFile>> tFilesCache = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final TeambitionClient client; |
|
|
|
private final TeambitionClient client; |
|
|
|
|
|
|
|
|
|
|
@ -38,7 +37,12 @@ public class TeambitionClientService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Set<TFile> getTFiles(String nodeId) { |
|
|
|
public Set<TFile> getTFiles(String nodeId) { |
|
|
|
return tFilesCache.computeIfAbsent(nodeId, key -> { |
|
|
|
Map<String, Set<TFile>> map = tFilesCache.get(); |
|
|
|
|
|
|
|
if (map == null) { |
|
|
|
|
|
|
|
map = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
tFilesCache.set(map); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return map.computeIfAbsent(nodeId, key -> { |
|
|
|
NodeQuery nodeQuery = new NodeQuery(); |
|
|
|
NodeQuery nodeQuery = new NodeQuery(); |
|
|
|
nodeQuery.setOrgId(client.getOrgId()); |
|
|
|
nodeQuery.setOrgId(client.getOrgId()); |
|
|
|
nodeQuery.setOffset(0); |
|
|
|
nodeQuery.setOffset(0); |
|
|
@ -145,6 +149,11 @@ public class TeambitionClientService { |
|
|
|
if (oldFile != null) { |
|
|
|
if (oldFile != null) { |
|
|
|
LOGGER.info("旧文件{}还存在,大小为{},进行删除操作,可前往网页版的回收站查看", path, oldFile.getSize()); |
|
|
|
LOGGER.info("旧文件{}还存在,大小为{},进行删除操作,可前往网页版的回收站查看", path, oldFile.getSize()); |
|
|
|
remove(path); |
|
|
|
remove(path); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Thread.sleep(1500); |
|
|
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
|
|
// no
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
RenameRequest renameRequest = new RenameRequest(); |
|
|
|
RenameRequest renameRequest = new RenameRequest(); |
|
|
|
renameRequest.setCcpFileId(uploadPreResult.getCcpFileId()); |
|
|
|
renameRequest.setCcpFileId(uploadPreResult.getCcpFileId()); |
|
|
@ -153,7 +162,7 @@ public class TeambitionClientService { |
|
|
|
renameRequest.setName(pathInfo.getName()); |
|
|
|
renameRequest.setName(pathInfo.getName()); |
|
|
|
client.put("/pan/api/nodes/" + parent.getNodeId(), renameRequest); |
|
|
|
client.put("/pan/api/nodes/" + parent.getNodeId(), renameRequest); |
|
|
|
} |
|
|
|
} |
|
|
|
clearCache(path); |
|
|
|
clearCache(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void rename(String sourcePath, String newName) { |
|
|
|
public void rename(String sourcePath, String newName) { |
|
|
@ -165,7 +174,7 @@ public class TeambitionClientService { |
|
|
|
renameRequest.setOrgId(client.getOrgId()); |
|
|
|
renameRequest.setOrgId(client.getOrgId()); |
|
|
|
renameRequest.setName(newName); |
|
|
|
renameRequest.setName(newName); |
|
|
|
client.put("/pan/api/nodes/" + tFile.getParentId(), renameRequest); |
|
|
|
client.put("/pan/api/nodes/" + tFile.getParentId(), renameRequest); |
|
|
|
clearCache(sourcePath); |
|
|
|
clearCache(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void move(String sourcePath, String targetPath) { |
|
|
|
public void move(String sourcePath, String targetPath) { |
|
|
@ -183,8 +192,8 @@ public class TeambitionClientService { |
|
|
|
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(sourcePath); |
|
|
|
clearCache(); |
|
|
|
clearCache(targetPath); |
|
|
|
clearCache(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void remove(String path) { |
|
|
|
public void remove(String path) { |
|
|
@ -197,7 +206,7 @@ public class TeambitionClientService { |
|
|
|
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(path); |
|
|
|
clearCache(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -228,16 +237,16 @@ public class TeambitionClientService { |
|
|
|
if (!createFileResult.getName().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(pathInfo.getParentPath() + "/" + createFileResult.getName()); |
|
|
|
clearCache(); |
|
|
|
} |
|
|
|
} |
|
|
|
clearCache(path); |
|
|
|
clearCache(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TFile getTFileByPath(String path) { |
|
|
|
public TFile getTFileByPath(String path) { |
|
|
|
path = normalizingPath(path); |
|
|
|
path = normalizingPath(path); |
|
|
|
|
|
|
|
|
|
|
|
return nodeIdMap.computeIfAbsent(path, this::getNodeIdByPath2); |
|
|
|
return getNodeIdByPath2(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public InputStream download(String path) { |
|
|
|
public InputStream download(String path) { |
|
|
@ -311,8 +320,11 @@ public class TeambitionClientService { |
|
|
|
return path; |
|
|
|
return path; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void clearCache(String path) { |
|
|
|
public void clearCache() { |
|
|
|
nodeIdMap.remove(path); |
|
|
|
Map<String, Set<TFile>> map = tFilesCache.get(); |
|
|
|
tFilesCache.clear(); |
|
|
|
if (map != null) { |
|
|
|
|
|
|
|
map.clear(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|