From 5ff0d850d7a2eb5449bec4f3ac50b121106f0e71 Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Sun, 11 Sep 2022 19:12:54 +0800 Subject: [PATCH] feat(aliyundrive): add doc and video preview api --- drivers/aliyundrive/driver.go | 24 +++++++++++++++++++++++- server/router.go | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/aliyundrive/driver.go b/drivers/aliyundrive/driver.go index 151eceaf7de..6fa9835c6d4 100644 --- a/drivers/aliyundrive/driver.go +++ b/drivers/aliyundrive/driver.go @@ -286,7 +286,29 @@ func (d *AliDrive) Put(ctx context.Context, dstDir model.Obj, stream model.FileS } func (d *AliDrive) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) { - return nil, errs.NotSupport + var resp base.Json + var url string + data := base.Json{ + "drive_id": d.DriveId, + "file_id": args.Obj.GetID(), + } + switch args.Method { + case "doc_preview": + url = "https://api.aliyundrive.com/v2/file/get_office_preview_url" + data["access_token"] = d.AccessToken + case "video_preview": + url = "https://api.aliyundrive.com/v2/file/get_video_preview_play_info" + data["category"] = "live_transcoding" + default: + return nil, errs.NotSupport + } + _, err, _ := d.request(url, http.MethodPost, func(req *resty.Request) { + req.SetBody(data) + }, &resp) + if err != nil { + return nil, err + } + return resp, nil } var _ driver.Driver = (*AliDrive)(nil) diff --git a/server/router.go b/server/router.go index 23f8f892d27..e5284af0e03 100644 --- a/server/router.go +++ b/server/router.go @@ -112,6 +112,7 @@ func admin(g *gin.RouterGroup) { func _fs(g *gin.RouterGroup) { g.Any("/list", handles.FsList) g.Any("/get", handles.FsGet) + g.Any("/other", handles.FsOther) g.Any("/dirs", handles.FsDirs) g.POST("/mkdir", handles.FsMkdir) g.POST("/rename", handles.FsRename)