增加视频接口

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

@@ -31,3 +31,4 @@ func OfficePreview(c *gin.Context) {
}
c.JSON(200, DataResponse(preview))
}

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))
}

View File

@@ -27,6 +27,7 @@ func InitApiRouter(engine *gin.Engine) {
apiV2.POST("/get", controllers.Get)
apiV2.POST("/path", controllers.Path)
apiV2.POST("/office_preview/:drive", controllers.OfficePreview)
apiV2.POST("/video_preview/:drive", controllers.VideoPreview)
apiV2.POST("/local_search", controllers.LocalSearch)
apiV2.POST("/global_search", controllers.GlobalSearch)
apiV2.GET("/rebuild/:drive/:password", controllers.RebuildTree)