🍃 Optimization download config
This commit is contained in:
@ -2,6 +2,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/alidrive"
|
"github.com/Xhofe/alist/alidrive"
|
||||||
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/server/models"
|
"github.com/Xhofe/alist/server/models"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -14,8 +15,12 @@ type DownReq struct {
|
|||||||
Password string `form:"pw"`
|
Password string `form:"pw"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle download request
|
// Down handle download request
|
||||||
func Down(c *gin.Context) {
|
func Down(c *gin.Context) {
|
||||||
|
if !conf.Conf.Server.Download {
|
||||||
|
c.JSON(200,MetaResponse(403,"not allowed download and preview"))
|
||||||
|
return
|
||||||
|
}
|
||||||
filePath := c.Param("path")[1:]
|
filePath := c.Param("path")[1:]
|
||||||
var down DownReq
|
var down DownReq
|
||||||
if err := c.ShouldBindQuery(&down); err != nil {
|
if err := c.ShouldBindQuery(&down); err != nil {
|
||||||
|
@ -2,6 +2,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/alidrive"
|
"github.com/Xhofe/alist/alidrive"
|
||||||
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -13,6 +14,10 @@ type OfficePreviewReq struct {
|
|||||||
|
|
||||||
// handle office_preview request
|
// handle office_preview request
|
||||||
func OfficePreview(c *gin.Context) {
|
func OfficePreview(c *gin.Context) {
|
||||||
|
if !conf.Conf.Server.Download {
|
||||||
|
c.JSON(200,MetaResponse(403,"not allowed download and preview"))
|
||||||
|
return
|
||||||
|
}
|
||||||
drive := utils.GetDriveByName(c.Param("drive"))
|
drive := utils.GetDriveByName(c.Param("drive"))
|
||||||
if drive == nil {
|
if drive == nil {
|
||||||
c.JSON(200, MetaResponse(400, "drive isn't exist."))
|
c.JSON(200, MetaResponse(400, "drive isn't exist."))
|
||||||
|
@ -2,6 +2,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/alidrive"
|
"github.com/Xhofe/alist/alidrive"
|
||||||
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -13,6 +14,10 @@ type VideoPreviewReq struct {
|
|||||||
|
|
||||||
// VideoPreview handle video_preview request
|
// VideoPreview handle video_preview request
|
||||||
func VideoPreview(c *gin.Context) {
|
func VideoPreview(c *gin.Context) {
|
||||||
|
if !conf.Conf.Server.Download {
|
||||||
|
c.JSON(200,MetaResponse(403,"not allowed download and preview"))
|
||||||
|
return
|
||||||
|
}
|
||||||
drive := utils.GetDriveByName(c.Param("drive"))
|
drive := utils.GetDriveByName(c.Param("drive"))
|
||||||
if drive == nil {
|
if drive == nil {
|
||||||
c.JSON(200, MetaResponse(400, "drive isn't exist."))
|
c.JSON(200, MetaResponse(400, "drive isn't exist."))
|
||||||
@ -33,6 +38,10 @@ func VideoPreview(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func VideoPreviewPlayInfo(c *gin.Context) {
|
func VideoPreviewPlayInfo(c *gin.Context) {
|
||||||
|
if !conf.Conf.Server.Download {
|
||||||
|
c.JSON(200,MetaResponse(403,"not allowed download and preview"))
|
||||||
|
return
|
||||||
|
}
|
||||||
drive := utils.GetDriveByName(c.Param("drive"))
|
drive := utils.GetDriveByName(c.Param("drive"))
|
||||||
if drive == nil {
|
if drive == nil {
|
||||||
c.JSON(200, MetaResponse(400, "drive isn't exist."))
|
c.JSON(200, MetaResponse(400, "drive isn't exist."))
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// init router
|
// InitRouter init router
|
||||||
func InitRouter(engine *gin.Engine) {
|
func InitRouter(engine *gin.Engine) {
|
||||||
log.Infof("初始化路由...")
|
log.Infof("初始化路由...")
|
||||||
engine.Use(CorsHandler())
|
engine.Use(CorsHandler())
|
||||||
@ -16,11 +16,11 @@ func InitRouter(engine *gin.Engine) {
|
|||||||
engine.NoRoute(func(c *gin.Context) {
|
engine.NoRoute(func(c *gin.Context) {
|
||||||
c.File(conf.Conf.Server.Static + "/index.html")
|
c.File(conf.Conf.Server.Static + "/index.html")
|
||||||
})
|
})
|
||||||
InitApiRouter(engine, conf.Conf.Server.Download)
|
InitApiRouter(engine)
|
||||||
}
|
}
|
||||||
|
|
||||||
// init api router
|
// InitApiRouter init api router
|
||||||
func InitApiRouter(engine *gin.Engine, download bool) {
|
func InitApiRouter(engine *gin.Engine) {
|
||||||
apiV2 := engine.Group("/api")
|
apiV2 := engine.Group("/api")
|
||||||
{
|
{
|
||||||
apiV2.GET("/info", controllers.Info)
|
apiV2.GET("/info", controllers.Info)
|
||||||
@ -29,9 +29,7 @@ func InitApiRouter(engine *gin.Engine, download bool) {
|
|||||||
apiV2.POST("/local_search", controllers.LocalSearch)
|
apiV2.POST("/local_search", controllers.LocalSearch)
|
||||||
apiV2.POST("/global_search", controllers.GlobalSearch)
|
apiV2.POST("/global_search", controllers.GlobalSearch)
|
||||||
apiV2.POST("/rebuild", controllers.RebuildTree)
|
apiV2.POST("/rebuild", controllers.RebuildTree)
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
apiV2.POST("/video_preview_play_info/:drive", controllers.VideoPreviewPlayInfo)
|
||||||
|
Reference in New Issue
Block a user