增加视频接口

This commit is contained in:
Xhofe
2021-03-30 10:22:07 +08:00
parent 76081a81a6
commit 77aae6660e
9 changed files with 182 additions and 107 deletions

View File

@ -0,0 +1,33 @@
package controllers
import (
"github.com/Xhofe/alist/alidrive"
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
type VideoPreviewReq struct {
FileId string `json:"file_id" binding:"required"`
}
// handle video_preview request
func VideoPreview(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.GetVideoPreviewUrl(req.FileId, drive)
if err != nil {
c.JSON(200, MetaResponse(500, err.Error()))
return
}
c.JSON(200, DataResponse(preview))
}