@ -22,6 +22,13 @@ type GetReq struct {
|
|||||||
VideoThumbnailProcess string `json:"video_thumbnail_process"`
|
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
|
// search request bean
|
||||||
type SearchReq struct {
|
type SearchReq struct {
|
||||||
DriveId string `json:"drive_id"`
|
DriveId string `json:"drive_id"`
|
||||||
|
@ -28,6 +28,21 @@ func GetFile(fileId string) (*File, error) {
|
|||||||
return &resp,nil
|
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
|
// search by keyword
|
||||||
func Search(key string,limit int, marker string) (*Files, error) {
|
func Search(key string,limit int, marker string) (*Files, error) {
|
||||||
url:=conf.Conf.AliDrive.ApiUrl+"/file/search"
|
url:=conf.Conf.AliDrive.ApiUrl+"/file/search"
|
||||||
@ -186,4 +201,4 @@ func GetPaths(fileId string) (*[]Path,error) {
|
|||||||
FileId: "root",
|
FileId: "root",
|
||||||
})
|
})
|
||||||
return &paths,nil
|
return &paths,nil
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,12 @@ func Get(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
file.Paths=*paths
|
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 {
|
//if conf.Conf.Cache.Enable {
|
||||||
// conf.Cache.Set(cacheKey,file,cache.DefaultExpiration)
|
// conf.Cache.Set(cacheKey,file,cache.DefaultExpiration)
|
||||||
//}
|
//}
|
||||||
@ -56,7 +62,7 @@ func Down(c *gin.Context) {
|
|||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
file,err:=alidrive.GetFile(fileId)
|
file,err:=alidrive.GetDownLoadUrl(fileId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, MetaResponse(500,err.Error()))
|
c.JSON(200, MetaResponse(500,err.Error()))
|
||||||
return
|
return
|
||||||
@ -64,6 +70,6 @@ func Down(c *gin.Context) {
|
|||||||
//if conf.Conf.Cache.Enable {
|
//if conf.Conf.Cache.Enable {
|
||||||
// conf.Cache.Set(cacheKey,file.DownloadUrl,cache.DefaultExpiration)
|
// conf.Cache.Set(cacheKey,file.DownloadUrl,cache.DefaultExpiration)
|
||||||
//}
|
//}
|
||||||
c.Redirect(301,file.DownloadUrl)
|
c.Redirect(301,file.Url)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user