diff --git a/src/main/java/com/github/zxbu/webdavteambition/client/AliYunDriverClient.java b/src/main/java/com/github/zxbu/webdavteambition/client/AliYunDriverClient.java index b76f9fd..5f938c5 100644 --- a/src/main/java/com/github/zxbu/webdavteambition/client/AliYunDriverClient.java +++ b/src/main/java/com/github/zxbu/webdavteambition/client/AliYunDriverClient.java @@ -86,7 +86,7 @@ public class AliYunDriverClient { public InputStream download(String url) { - Request request = new Request.Builder().url(url).build(); + Request request = new Request.Builder().header("referer", "https://www.aliyundrive.com/").url(url).build(); Response response = null; try { response = okHttpClient.newCall(request).execute(); diff --git a/src/main/java/com/github/zxbu/webdavteambition/model/DownloadRequest.java b/src/main/java/com/github/zxbu/webdavteambition/model/DownloadRequest.java new file mode 100644 index 0000000..b3aec42 --- /dev/null +++ b/src/main/java/com/github/zxbu/webdavteambition/model/DownloadRequest.java @@ -0,0 +1,22 @@ +package com.github.zxbu.webdavteambition.model; + +public class DownloadRequest { + private String drive_id; + private String file_id; + + public String getDrive_id() { + return drive_id; + } + + public void setDrive_id(String drive_id) { + this.drive_id = drive_id; + } + + public String getFile_id() { + return file_id; + } + + public void setFile_id(String file_id) { + this.file_id = file_id; + } +} diff --git a/src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java b/src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java index cdfeda9..c86258a 100644 --- a/src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java +++ b/src/main/java/com/github/zxbu/webdavteambition/store/AliYunDriverClientService.java @@ -249,8 +249,13 @@ public class AliYunDriverClientService { } public InputStream download(String path) { -// String downloadUrl = getTFileByPath(path).getDownloadUrl(); - return client.download("downloadUrl"); + TFile file = getTFileByPath(path); + DownloadRequest downloadRequest = new DownloadRequest(); + downloadRequest.setDrive_id(client.getDriveId()); + downloadRequest.setFile_id(file.getFile_id()); + String json = client.post("/file/get_download_url", downloadRequest); + Object url = JsonUtil.getJsonNodeValue(json, "url"); + return client.download(url.toString()); } private TFile getNodeIdByPath2(String path) {