From 50f71bd7c83fe29166e59793b6632985a5850a49 Mon Sep 17 00:00:00 2001 From: zhouxin Date: Tue, 25 May 2021 21:27:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BD=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/AliYunDriverClient.java | 2 +- .../model/DownloadRequest.java | 22 +++++++++++++++++++ .../store/AliYunDriverClientService.java | 9 ++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/github/zxbu/webdavteambition/model/DownloadRequest.java 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) {