🚧 构建目录树
This commit is contained in:
52
server/controllers/v2/get.go
Normal file
52
server/controllers/v2/get.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/alist/alidrive"
|
||||
"github.com/Xhofe/alist/server/controllers"
|
||||
"github.com/Xhofe/alist/server/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// get request bean
|
||||
type GetReq struct {
|
||||
File string `json:"file"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// handle list request
|
||||
func Get(c *gin.Context) {
|
||||
var get GetReq
|
||||
if err := c.ShouldBindJSON(&get); err != nil {
|
||||
c.JSON(200, controllers.MetaResponse(400, "Bad Request."))
|
||||
return
|
||||
}
|
||||
log.Debugf("list:%+v", get)
|
||||
path,name:=filepath.Split(get.File)
|
||||
file, err := models.GetFileByParentPathAndName(path,name)
|
||||
if err != nil {
|
||||
c.JSON(200, controllers.MetaResponse(500, err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, controllers.DataResponse(file))
|
||||
}
|
||||
|
||||
// handle download request
|
||||
func Down(c *gin.Context) {
|
||||
filePath:=c.Param("file")
|
||||
log.Debugf("down:%s",filePath)
|
||||
path,name:=filepath.Split(filePath)
|
||||
fileModel, err := models.GetFileByParentPathAndName(path,name)
|
||||
if err != nil {
|
||||
c.JSON(200, controllers.MetaResponse(500, err.Error()))
|
||||
return
|
||||
}
|
||||
file,err:=alidrive.GetDownLoadUrl(fileModel.FileId)
|
||||
if err != nil {
|
||||
c.JSON(200, controllers.MetaResponse(500,err.Error()))
|
||||
return
|
||||
}
|
||||
c.Redirect(301,file.Url)
|
||||
return
|
||||
}
|
30
server/controllers/v2/list.go
Normal file
30
server/controllers/v2/list.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/alist/server/controllers"
|
||||
"github.com/Xhofe/alist/server/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// list request bean
|
||||
type ListReq struct {
|
||||
Path string `json:"path"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// handle list request
|
||||
func List(c *gin.Context) {
|
||||
var list ListReq
|
||||
if err := c.ShouldBindJSON(&list); err != nil {
|
||||
c.JSON(200, controllers.MetaResponse(400, "Bad Request."))
|
||||
return
|
||||
}
|
||||
log.Debugf("list:%+v", list)
|
||||
files, err := models.GetFilesByParentPath(list.Path)
|
||||
if err != nil {
|
||||
c.JSON(200, controllers.MetaResponse(500, err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, controllers.DataResponse(files))
|
||||
}
|
Reference in New Issue
Block a user