alist/server/controllers/fsget.go

52 lines
1.2 KiB
Go
Raw Normal View History

2022-06-27 13:15:39 +00:00
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"
)
type FsGetReq struct {
Path string `json:"path" form:"path"`
Password string `json:"password" form:"password"`
}
type FsGetResp struct {
2022-06-27 13:34:13 +00:00
ObjResp
RawURL string `json:"raw_url"`
2022-06-27 13:15:39 +00:00
}
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
}
2022-06-28 07:12:40 +00:00
obj, err := fs.Get(c, req.Path)
2022-06-27 13:15:39 +00:00
if err != nil {
common.ErrorResp(c, err, 500, true)
return
}
common.SuccessResp(c, FsGetResp{
2022-06-27 13:34:13 +00:00
ObjResp: ObjResp{
2022-06-28 07:12:40 +00:00
Name: obj.GetName(),
Size: obj.GetSize(),
IsDir: obj.IsDir(),
Modified: obj.ModTime(),
Sign: Sign(obj),
2022-06-27 13:34:13 +00:00
},
// TODO: set raw url
2022-06-27 13:15:39 +00:00
})
}