🚧 change video preview api
This commit is contained in:
@ -73,3 +73,11 @@ type VideoPreviewUrlReq struct {
|
|||||||
FileId string `json:"file_id"`
|
FileId string `json:"file_id"`
|
||||||
ExpireSec int `json:"expire_sec"`
|
ExpireSec int `json:"expire_sec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VideoPreviewPlayInfoReq video preview play info req
|
||||||
|
type VideoPreviewPlayInfoReq struct {
|
||||||
|
Category string `json:"category"`
|
||||||
|
DriveId string `json:"drive_id"`
|
||||||
|
FileId string `json:"file_id"`
|
||||||
|
TemplateId string `json:"template_id"`
|
||||||
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
// get file
|
// GetFile get file
|
||||||
func GetFile(fileId string, drive *conf.Drive) (*File, error) {
|
func GetFile(fileId string, drive *conf.Drive) (*File, error) {
|
||||||
url := conf.Conf.AliDrive.ApiUrl + "/file/get"
|
url := conf.Conf.AliDrive.ApiUrl + "/file/get"
|
||||||
req := GetReq{
|
req := GetReq{
|
||||||
@ -21,7 +21,7 @@ func GetFile(fileId string, drive *conf.Drive) (*File, error) {
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// get download_url
|
// GetDownLoadUrl get download_url
|
||||||
func GetDownLoadUrl(fileId string, drive *conf.Drive) (*DownloadResp, error) {
|
func GetDownLoadUrl(fileId string, drive *conf.Drive) (*DownloadResp, error) {
|
||||||
url := conf.Conf.AliDrive.ApiUrl + "/file/get_download_url"
|
url := conf.Conf.AliDrive.ApiUrl + "/file/get_download_url"
|
||||||
req := DownloadReq{
|
req := DownloadReq{
|
||||||
@ -36,7 +36,7 @@ func GetDownLoadUrl(fileId string, drive *conf.Drive) (*DownloadResp, error) {
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// search by keyword
|
// Search search by keyword
|
||||||
func Search(key string, limit int, marker string, drive *conf.Drive) (*Files, error) {
|
func Search(key string, limit int, marker string, drive *conf.Drive) (*Files, error) {
|
||||||
url := conf.Conf.AliDrive.ApiUrl + "/file/search"
|
url := conf.Conf.AliDrive.ApiUrl + "/file/search"
|
||||||
req := SearchReq{
|
req := SearchReq{
|
||||||
@ -56,12 +56,12 @@ func Search(key string, limit int, marker string, drive *conf.Drive) (*Files, er
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// get root folder
|
// GetRoot get root folder
|
||||||
func GetRoot(limit int, marker string, orderBy string, orderDirection string, drive *conf.Drive) (*Files, error) {
|
func GetRoot(limit int, marker string, orderBy string, orderDirection string, drive *conf.Drive) (*Files, error) {
|
||||||
return GetList(drive.RootFolder, limit, marker, orderBy, orderDirection, drive)
|
return GetList(drive.RootFolder, limit, marker, orderBy, orderDirection, drive)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get folder list by file_id
|
// GetList get folder list by file_id
|
||||||
func GetList(parent string, limit int, marker string, orderBy string, orderDirection string, drive *conf.Drive) (*Files, error) {
|
func GetList(parent string, limit int, marker string, orderBy string, orderDirection string, drive *conf.Drive) (*Files, error) {
|
||||||
url := conf.Conf.AliDrive.ApiUrl + "/file/list"
|
url := conf.Conf.AliDrive.ApiUrl + "/file/list"
|
||||||
req := ListReq{
|
req := ListReq{
|
||||||
@ -83,7 +83,7 @@ func GetList(parent string, limit int, marker string, orderBy string, orderDirec
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// get user info
|
// GetUserInfo get user info
|
||||||
func GetUserInfo(drive *conf.Drive) (*UserInfo, error) {
|
func GetUserInfo(drive *conf.Drive) (*UserInfo, error) {
|
||||||
url := conf.Conf.AliDrive.ApiUrl + "/user/get"
|
url := conf.Conf.AliDrive.ApiUrl + "/user/get"
|
||||||
var resp UserInfo
|
var resp UserInfo
|
||||||
@ -93,7 +93,7 @@ func GetUserInfo(drive *conf.Drive) (*UserInfo, error) {
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// get office preview url and token
|
// GetOfficePreviewUrl get office preview url and token
|
||||||
func GetOfficePreviewUrl(fileId string, drive *conf.Drive) (*OfficePreviewUrlResp, error) {
|
func GetOfficePreviewUrl(fileId string, drive *conf.Drive) (*OfficePreviewUrlResp, error) {
|
||||||
url := conf.Conf.AliDrive.ApiUrl + "/file/get_office_preview_url"
|
url := conf.Conf.AliDrive.ApiUrl + "/file/get_office_preview_url"
|
||||||
req := OfficePreviewUrlReq{
|
req := OfficePreviewUrlReq{
|
||||||
@ -108,7 +108,7 @@ func GetOfficePreviewUrl(fileId string, drive *conf.Drive) (*OfficePreviewUrlRes
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// get video preview url
|
// GetVideoPreviewUrl get video preview url
|
||||||
func GetVideoPreviewUrl(fileId string, drive *conf.Drive) (*VideoPreviewUrlResp, error) {
|
func GetVideoPreviewUrl(fileId string, drive *conf.Drive) (*VideoPreviewUrlResp, error) {
|
||||||
url := conf.Conf.AliDrive.ApiUrl + "/databox/get_video_play_info"
|
url := conf.Conf.AliDrive.ApiUrl + "/databox/get_video_play_info"
|
||||||
req := VideoPreviewUrlReq{
|
req := VideoPreviewUrlReq{
|
||||||
@ -122,3 +122,18 @@ func GetVideoPreviewUrl(fileId string, drive *conf.Drive) (*VideoPreviewUrlResp,
|
|||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetVideoPreviewPlayInfo get video preview url
|
||||||
|
func GetVideoPreviewPlayInfo(fileId string, drive *conf.Drive) (*VideoPreviewPlayInfoResp, error) {
|
||||||
|
url := conf.Conf.AliDrive.ApiUrl + "/file/get_video_preview_play_info"
|
||||||
|
req := VideoPreviewPlayInfoReq{
|
||||||
|
DriveId: drive.DefaultDriveId,
|
||||||
|
FileId: fileId,
|
||||||
|
Category: "live_transcoding",
|
||||||
|
}
|
||||||
|
var resp VideoPreviewPlayInfoResp
|
||||||
|
if err := BodyToJson(url, req, &resp, drive); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// response bean methods
|
// RespHandle response bean methods
|
||||||
type RespHandle interface {
|
type RespHandle interface {
|
||||||
IsAvailable() bool // check available
|
IsAvailable() bool // check available
|
||||||
GetCode() string // get err code
|
GetCode() string // get err code
|
||||||
@ -12,7 +12,7 @@ type RespHandle interface {
|
|||||||
SetCode(code string) // set err code
|
SetCode(code string) // set err code
|
||||||
}
|
}
|
||||||
|
|
||||||
// common response bean
|
// RespError common response bean
|
||||||
type RespError struct {
|
type RespError struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
@ -34,7 +34,7 @@ func (resp *RespError) SetCode(code string) {
|
|||||||
resp.Code = code
|
resp.Code = code
|
||||||
}
|
}
|
||||||
|
|
||||||
// user_info response bean
|
// UserInfo user_info response bean
|
||||||
type UserInfo struct {
|
type UserInfo struct {
|
||||||
RespError
|
RespError
|
||||||
DomainId string `json:"domain_id"`
|
DomainId string `json:"domain_id"`
|
||||||
@ -53,7 +53,7 @@ type UserInfo struct {
|
|||||||
UserData map[string]interface{} `json:"user_data"`
|
UserData map[string]interface{} `json:"user_data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// folder files response bean
|
// Files folder files response bean
|
||||||
type Files struct {
|
type Files struct {
|
||||||
RespError
|
RespError
|
||||||
Items []File `json:"items"`
|
Items []File `json:"items"`
|
||||||
@ -62,7 +62,7 @@ type Files struct {
|
|||||||
Paths []Path `json:"paths"`
|
Paths []Path `json:"paths"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// path bean
|
// Path path bean
|
||||||
type Path struct {
|
type Path struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
FileId string `json:"file_id"`
|
FileId string `json:"file_id"`
|
||||||
@ -75,8 +75,9 @@ type Path struct {
|
|||||||
"size":1141068377,
|
"size":1141068377,
|
||||||
"content_type":"video/mp4"
|
"content_type":"video/mp4"
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// file response bean
|
|
||||||
|
// File file response bean
|
||||||
type File struct {
|
type File struct {
|
||||||
RespError
|
RespError
|
||||||
DriveId string `json:"drive_id"`
|
DriveId string `json:"drive_id"`
|
||||||
@ -120,13 +121,13 @@ type DownloadResp struct {
|
|||||||
//} `json:"rate_limit"`//rate limit
|
//} `json:"rate_limit"`//rate limit
|
||||||
}
|
}
|
||||||
|
|
||||||
// token_login response bean
|
// TokenLoginResp token_login response bean
|
||||||
type TokenLoginResp struct {
|
type TokenLoginResp struct {
|
||||||
RespError
|
RespError
|
||||||
Goto string `json:"goto"`
|
Goto string `json:"goto"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// token response bean
|
// TokenResp token response bean
|
||||||
type TokenResp struct {
|
type TokenResp struct {
|
||||||
RespError
|
RespError
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
@ -147,7 +148,7 @@ type TokenResp struct {
|
|||||||
DeviceId string `json:"device_id"`
|
DeviceId string `json:"device_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// office_preview_url response bean
|
// OfficePreviewUrlResp office_preview_url response bean
|
||||||
type OfficePreviewUrlResp struct {
|
type OfficePreviewUrlResp struct {
|
||||||
RespError
|
RespError
|
||||||
PreviewUrl string `json:"preview_url"`
|
PreviewUrl string `json:"preview_url"`
|
||||||
@ -162,3 +163,15 @@ type VideoPreviewUrlResp struct {
|
|||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
} `json:"template_list"`
|
} `json:"template_list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type VideoPreviewPlayInfoResp struct {
|
||||||
|
RespError
|
||||||
|
VideoPreviewPlayInfo struct {
|
||||||
|
LiveTranscodingTaskList []struct {
|
||||||
|
TemplateId string `json:"template_id"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
Stage string `json:"stage"`
|
||||||
|
} `json:"live_transcoding_task_list"`
|
||||||
|
} `json:"video_preview_play_info"`
|
||||||
|
}
|
||||||
|
@ -22,7 +22,7 @@ var (
|
|||||||
var Conf = new(Config)
|
var Conf = new(Config)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "v1.0.5"
|
VERSION = "v1.0.6"
|
||||||
|
|
||||||
ImageThumbnailProcess = "image/resize,w_50"
|
ImageThumbnailProcess = "image/resize,w_50"
|
||||||
VideoThumbnailProcess = "video/snapshot,t_0,f_jpg,w_50"
|
VideoThumbnailProcess = "video/snapshot,t_0,f_jpg,w_50"
|
||||||
|
@ -11,7 +11,7 @@ type VideoPreviewReq struct {
|
|||||||
FileId string `json:"file_id" binding:"required"`
|
FileId string `json:"file_id" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle video_preview request
|
// VideoPreview handle video_preview request
|
||||||
func VideoPreview(c *gin.Context) {
|
func VideoPreview(c *gin.Context) {
|
||||||
drive := utils.GetDriveByName(c.Param("drive"))
|
drive := utils.GetDriveByName(c.Param("drive"))
|
||||||
if drive == nil {
|
if drive == nil {
|
||||||
@ -31,3 +31,23 @@ func VideoPreview(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
c.JSON(200, DataResponse(preview))
|
c.JSON(200, DataResponse(preview))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func VideoPreviewPlayInfo(c *gin.Context) {
|
||||||
|
drive := utils.GetDriveByName(c.Param("drive"))
|
||||||
|
if drive == nil {
|
||||||
|
c.JSON(200, MetaResponse(400, "drive isn't exist."))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var req VideoPreviewReq
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
c.JSON(200, MetaResponse(400, "Bad Request:"+err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Debugf("preview_req:%+v", req)
|
||||||
|
preview, err := alidrive.GetVideoPreviewPlayInfo(req.FileId, drive)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, MetaResponse(500, err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(200, DataResponse(preview))
|
||||||
|
}
|
@ -34,7 +34,7 @@ func InitApiRouter(engine *gin.Engine, download bool) {
|
|||||||
if download {
|
if download {
|
||||||
apiV2.POST("/office_preview/:drive", controllers.OfficePreview)
|
apiV2.POST("/office_preview/:drive", controllers.OfficePreview)
|
||||||
apiV2.POST("/video_preview/:drive", controllers.VideoPreview)
|
apiV2.POST("/video_preview/:drive", controllers.VideoPreview)
|
||||||
|
apiV2.POST("/video_preview_play_info/:drive", controllers.VideoPreviewPlayInfo)
|
||||||
engine.GET("/d/*path", controllers.Down)
|
engine.GET("/d/*path", controllers.Down)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user