Browse Source

支持上传

main
zhouxin 4 years ago
parent
commit
f3decc21ff
  1. 2
      src/main/java/com/github/zxbu/webdavteambition/model/UploadPreRequest.java
  2. 9
      src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java
  3. 4
      src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverFileSystemStore.java

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

@ -5,7 +5,7 @@ import java.util.List;
public class UploadPreRequest { public class UploadPreRequest {
private String check_name_mode = "refuse"; private String check_name_mode = "refuse";
private String content_hash; private String content_hash;
private String content_hash_name = "sha1"; private String content_hash_name = "none";
private String drive_id; private String drive_id;
private String name; private String name;
private String parent_file_id; private String parent_file_id;

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

@ -93,10 +93,17 @@ public class AliYunDriverClientService {
if (parent == null) { if (parent == null) {
return; return;
} }
// 如果已存在,先删除
TFile tfile = getTFileByPath(path);
if (tfile != null) {
remove(path);
}
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.setContent_hash(UUID.randomUUID().toString()); // uploadPreRequest.setContent_hash(UUID.randomUUID().toString());
uploadPreRequest.setDrive_id(client.getDriveId()); uploadPreRequest.setDrive_id(client.getDriveId());
uploadPreRequest.setName(pathInfo.getName()); uploadPreRequest.setName(pathInfo.getName());
uploadPreRequest.setParent_file_id(parent.getFile_id()); uploadPreRequest.setParent_file_id(parent.getFile_id());

4
src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverFileSystemStore.java

@ -1,5 +1,6 @@
package com.github.zxbu.webdavteambition.store; package com.github.zxbu.webdavteambition.store;
import com.github.zxbu.webdavteambition.model.FileType;
import com.github.zxbu.webdavteambition.model.PathInfo; import com.github.zxbu.webdavteambition.model.PathInfo;
import com.github.zxbu.webdavteambition.model.result.TFile; import com.github.zxbu.webdavteambition.model.result.TFile;
import net.sf.webdav.ITransaction; import net.sf.webdav.ITransaction;
@ -107,6 +108,9 @@ public class AliYunDriverFileSystemStore implements IWebdavStore {
public String[] getChildrenNames(ITransaction transaction, String folderUri) { public String[] getChildrenNames(ITransaction transaction, String folderUri) {
LOGGER.debug("getChildrenNames: {}", folderUri); LOGGER.debug("getChildrenNames: {}", folderUri);
TFile tFile = aliYunDriverClientService.getTFileByPath(folderUri); TFile tFile = aliYunDriverClientService.getTFileByPath(folderUri);
if (tFile.getType().equals(FileType.file.name())) {
return new String[0];
}
Set<TFile> tFileList = aliYunDriverClientService.getTFiles(tFile.getFile_id()); Set<TFile> tFileList = aliYunDriverClientService.getTFiles(tFile.getFile_id());
return tFileList.stream().map(TFile::getName).toArray(String[]::new); return tFileList.stream().map(TFile::getName).toArray(String[]::new);
} }

Loading…
Cancel
Save