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