From 46f09836f321e9a3995df1877fe5a1c81fa39631 Mon Sep 17 00:00:00 2001 From: 122cygf Date: Fri, 26 Feb 2021 12:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5=E6=9C=89?= =?UTF-8?q?=E6=95=88=E6=9C=9F=E5=BB=B6=E9=95=BF=E5=88=B0=E5=9B=9B=E5=B0=8F?= =?UTF-8?q?=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alidrive/req_bean.go | 7 +++++++ alidrive/request.go | 17 ++++++++++++++++- server/controllers/get.go | 12 +++++++++--- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/alidrive/req_bean.go b/alidrive/req_bean.go index 847aaf25..fea1cc4a 100644 --- a/alidrive/req_bean.go +++ b/alidrive/req_bean.go @@ -22,6 +22,13 @@ type GetReq struct { VideoThumbnailProcess string `json:"video_thumbnail_process"` } +// download request bean +type DownloadReq struct { + DriveId string `json:"drive_id"` + FileId string `json:"file_id"` + ExpireSec int `json:"expire_sec"` +} + // search request bean type SearchReq struct { DriveId string `json:"drive_id"` diff --git a/alidrive/request.go b/alidrive/request.go index 3a90db0e..4fad0f3c 100644 --- a/alidrive/request.go +++ b/alidrive/request.go @@ -28,6 +28,21 @@ func GetFile(fileId string) (*File, error) { return &resp,nil } +// get download_url +func GetDownLoadUrl(fileId string) (*File, error) { + url:=conf.Conf.AliDrive.ApiUrl+"/file/get_download_url" + req:=DownloadReq{ + DriveId: User.DefaultDriveId, + FileId: fileId, + ExpireSec: 14400, + } + var resp File + if err := BodyToJson(url, req, &resp, true); err!=nil { + return nil,err + } + return &resp,nil +} + // search by keyword func Search(key string,limit int, marker string) (*Files, error) { url:=conf.Conf.AliDrive.ApiUrl+"/file/search" @@ -186,4 +201,4 @@ func GetPaths(fileId string) (*[]Path,error) { FileId: "root", }) return &paths,nil -} \ No newline at end of file +} diff --git a/server/controllers/get.go b/server/controllers/get.go index 34cd2810..167b669e 100644 --- a/server/controllers/get.go +++ b/server/controllers/get.go @@ -37,6 +37,12 @@ func Get(c *gin.Context) { return } file.Paths=*paths + download,err:=alidrive.GetDownLoadUrl(get.FileId) + if err!=nil { + c.JSON(200, MetaResponse(500,err.Error())) + return + } + file.DownloadUrl=download.Url //if conf.Conf.Cache.Enable { // conf.Cache.Set(cacheKey,file,cache.DefaultExpiration) //} @@ -56,7 +62,7 @@ func Down(c *gin.Context) { // return // } //} - file,err:=alidrive.GetFile(fileId) + file,err:=alidrive.GetDownLoadUrl(fileId) if err != nil { c.JSON(200, MetaResponse(500,err.Error())) return @@ -64,6 +70,6 @@ func Down(c *gin.Context) { //if conf.Conf.Cache.Enable { // conf.Cache.Set(cacheKey,file.DownloadUrl,cache.DefaultExpiration) //} - c.Redirect(301,file.DownloadUrl) + c.Redirect(301,file.Url) return -} \ No newline at end of file +}