feat: obj get api
This commit is contained in:
parent
db6b5f8950
commit
c8f10703b7
51
server/controllers/fsget.go
Normal file
51
server/controllers/fsget.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/alist-org/alist/v3/internal/db"
|
||||||
|
"github.com/alist-org/alist/v3/internal/fs"
|
||||||
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
|
"github.com/alist-org/alist/v3/server/common"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
stdpath "path"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FsGetReq struct {
|
||||||
|
Path string `json:"path" form:"path"`
|
||||||
|
Password string `json:"password" form:"password"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type FsGetResp struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
IsDir bool `json:"is_dir"`
|
||||||
|
Modified time.Time `json:"modified"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func FsGet(c *gin.Context) {
|
||||||
|
var req FsGetReq
|
||||||
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
|
common.ErrorResp(c, err, 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user := c.MustGet("user").(*model.User)
|
||||||
|
req.Path = stdpath.Join(user.BasePath, req.Path)
|
||||||
|
meta, _ := db.GetNearestMeta(req.Path)
|
||||||
|
c.Set("meta", meta)
|
||||||
|
if !canAccess(user, meta, req.Path, req.Password) {
|
||||||
|
common.ErrorStrResp(c, "password is incorrect", 401)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := fs.Get(c, req.Path)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResp(c, err, 500, true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
common.SuccessResp(c, FsGetResp{
|
||||||
|
Name: data.GetName(),
|
||||||
|
Size: data.GetSize(),
|
||||||
|
IsDir: data.IsDir(),
|
||||||
|
Modified: data.ModTime(),
|
||||||
|
})
|
||||||
|
}
|
@ -24,12 +24,12 @@ type ObjResp struct {
|
|||||||
Modified time.Time `json:"modified"`
|
Modified time.Time `json:"modified"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListResp struct {
|
type FsListResp struct {
|
||||||
Content []ObjResp `json:"content"`
|
Content []ObjResp `json:"content"`
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func List(c *gin.Context) {
|
func FsList(c *gin.Context) {
|
||||||
var req ListReq
|
var req ListReq
|
||||||
if err := c.ShouldBind(&req); err != nil {
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
@ -50,7 +50,7 @@ func List(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
total, objs := pagination(objs, &req.PageReq)
|
total, objs := pagination(objs, &req.PageReq)
|
||||||
common.SuccessResp(c, ListResp{
|
common.SuccessResp(c, FsListResp{
|
||||||
Content: toObjResp(objs),
|
Content: toObjResp(objs),
|
||||||
Total: int64(total),
|
Total: int64(total),
|
||||||
})
|
})
|
||||||
|
@ -49,7 +49,8 @@ func Init(r *gin.Engine) {
|
|||||||
|
|
||||||
public := api.Group("/public")
|
public := api.Group("/public")
|
||||||
public.GET("/settings", controllers.PublicSettings)
|
public.GET("/settings", controllers.PublicSettings)
|
||||||
public.GET("/list", controllers.List)
|
public.GET("/list", controllers.FsList)
|
||||||
|
public.GET("/get", controllers.FsGet)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Cors(r *gin.Engine) {
|
func Cors(r *gin.Engine) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user