mirror of https://github.com/Xhofe/alist
feat: add write field to list resp
parent
35b04ffa9c
commit
fba96d024f
|
@ -21,14 +21,13 @@ type User struct {
|
||||||
// 0: can see hidden files
|
// 0: can see hidden files
|
||||||
// 1: can access without password
|
// 1: can access without password
|
||||||
// 2: can add aria2 tasks
|
// 2: can add aria2 tasks
|
||||||
// 3: can mkdir
|
// 3: can mkdir and upload
|
||||||
// 4: can upload
|
// 4: can rename
|
||||||
// 5: can rename
|
// 5: can move
|
||||||
// 6: can move
|
// 6: can copy
|
||||||
// 7: can copy
|
// 7: can remove
|
||||||
// 8: can remove
|
// 8: webdav read
|
||||||
// 9: webdav read
|
// 9: webdav write
|
||||||
// 10: webdav write
|
|
||||||
Permission int32 `json:"permission"`
|
Permission int32 `json:"permission"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,34 +61,30 @@ func (u User) CanAddAria2Tasks() bool {
|
||||||
return u.IsAdmin() || (u.Permission>>2)&1 == 1
|
return u.IsAdmin() || (u.Permission>>2)&1 == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) CanMkdir() bool {
|
func (u User) CanWrite() bool {
|
||||||
return u.IsAdmin() || (u.Permission>>3)&1 == 1
|
return u.IsAdmin() || (u.Permission>>3)&1 == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) CanUpload() bool {
|
func (u User) CanRename() bool {
|
||||||
return u.IsAdmin() || (u.Permission>>4)&1 == 1
|
return u.IsAdmin() || (u.Permission>>4)&1 == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) CanRename() bool {
|
func (u User) CanMove() bool {
|
||||||
return u.IsAdmin() || (u.Permission>>5)&1 == 1
|
return u.IsAdmin() || (u.Permission>>5)&1 == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) CanMove() bool {
|
func (u User) CanCopy() bool {
|
||||||
return u.IsAdmin() || (u.Permission>>6)&1 == 1
|
return u.IsAdmin() || (u.Permission>>6)&1 == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) CanCopy() bool {
|
func (u User) CanRemove() bool {
|
||||||
return u.IsAdmin() || (u.Permission>>7)&1 == 1
|
return u.IsAdmin() || (u.Permission>>7)&1 == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) CanRemove() bool {
|
func (u User) CanWebdavRead() bool {
|
||||||
return u.IsAdmin() || (u.Permission>>8)&1 == 1
|
return u.IsAdmin() || (u.Permission>>8)&1 == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) CanWebdavRead() bool {
|
func (u User) CanWebdavWrite() bool {
|
||||||
return u.IsAdmin() || (u.Permission>>9)&1 == 1
|
return u.IsAdmin() || (u.Permission>>9)&1 == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) CanWebdavWrite() bool {
|
|
||||||
return u.IsAdmin() || (u.Permission>>10)&1 == 1
|
|
||||||
}
|
|
||||||
|
|
|
@ -26,13 +26,13 @@ func FsMkdir(c *gin.Context) {
|
||||||
}
|
}
|
||||||
user := c.MustGet("user").(*model.User)
|
user := c.MustGet("user").(*model.User)
|
||||||
req.Path = stdpath.Join(user.BasePath, req.Path)
|
req.Path = stdpath.Join(user.BasePath, req.Path)
|
||||||
if !user.CanMkdir() {
|
if !user.CanWrite() {
|
||||||
meta, err := db.GetNearestMeta(req.Path)
|
meta, err := db.GetNearestMeta(req.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !canMkdirOrPut(meta, req.Path) {
|
if !canWrite(meta, req.Path) {
|
||||||
common.ErrorResp(c, errs.PermissionDenied, 403)
|
common.ErrorResp(c, errs.PermissionDenied, 403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func FsMkdir(c *gin.Context) {
|
||||||
common.SuccessResp(c)
|
common.SuccessResp(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func canMkdirOrPut(meta *model.Meta, path string) bool {
|
func canWrite(meta *model.Meta, path string) bool {
|
||||||
if meta == nil || !meta.Write {
|
if meta == nil || !meta.Write {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -178,13 +178,13 @@ func FsPut(c *gin.Context) {
|
||||||
path := c.GetHeader("File-Path")
|
path := c.GetHeader("File-Path")
|
||||||
user := c.MustGet("user").(*model.User)
|
user := c.MustGet("user").(*model.User)
|
||||||
path = stdpath.Join(user.BasePath, path)
|
path = stdpath.Join(user.BasePath, path)
|
||||||
if !user.CanUpload() {
|
if !user.CanWrite() {
|
||||||
meta, err := db.GetNearestMeta(path)
|
meta, err := db.GetNearestMeta(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ErrorResp(c, err, 500)
|
common.ErrorResp(c, err, 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !canMkdirOrPut(meta, path) {
|
if !canWrite(meta, path) {
|
||||||
common.ErrorResp(c, errs.PermissionDenied, 403)
|
common.ErrorResp(c, errs.PermissionDenied, 403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ type FsListResp struct {
|
||||||
Content []ObjResp `json:"content"`
|
Content []ObjResp `json:"content"`
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
Readme string `json:"readme"`
|
Readme string `json:"readme"`
|
||||||
|
Write bool `json:"write"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func FsList(c *gin.Context) {
|
func FsList(c *gin.Context) {
|
||||||
|
@ -68,6 +69,7 @@ func FsList(c *gin.Context) {
|
||||||
Content: toObjResp(objs),
|
Content: toObjResp(objs),
|
||||||
Total: int64(total),
|
Total: int64(total),
|
||||||
Readme: getReadme(meta, req.Path),
|
Readme: getReadme(meta, req.Path),
|
||||||
|
Write: user.CanWrite() || canWrite(meta, req.Path),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue