chore: add refresh arg in list func

This commit is contained in:
Noah Hsu 2022-08-29 19:15:52 +08:00
parent 97d4114e38
commit 68a125491b
4 changed files with 11 additions and 5 deletions

View File

@ -17,6 +17,7 @@ var notify = NewNotify()
var client rpc.Client var client rpc.Client
func InitClient(timeout int) (string, error) { func InitClient(timeout int) (string, error) {
client = nil
uri := setting.GetByKey(conf.Aria2Uri) uri := setting.GetByKey(conf.Aria2Uri)
secret := setting.GetByKey(conf.Aria2Secret) secret := setting.GetByKey(conf.Aria2Secret)
return InitAria2Client(uri, secret, timeout) return InitAria2Client(uri, secret, timeout)

View File

@ -13,8 +13,8 @@ import (
// So, the purpose of this package is to convert virtual path to actual path // So, the purpose of this package is to convert virtual path to actual path
// then pass the actual path to the operations package // then pass the actual path to the operations package
func List(ctx context.Context, path string) ([]model.Obj, error) { func List(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) {
res, err := list(ctx, path) res, err := list(ctx, path, refresh...)
if err != nil { if err != nil {
log.Errorf("failed list %s: %+v", path, err) log.Errorf("failed list %s: %+v", path, err)
return nil, err return nil, err

View File

@ -13,7 +13,7 @@ import (
) )
// List files // List files
func list(ctx context.Context, path string) ([]model.Obj, error) { func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) {
meta := ctx.Value("meta").(*model.Meta) meta := ctx.Value("meta").(*model.Meta)
user := ctx.Value("user").(*model.User) user := ctx.Value("user").(*model.User)
storage, actualPath, err := operations.GetStorageAndActualPath(path) storage, actualPath, err := operations.GetStorageAndActualPath(path)
@ -26,7 +26,7 @@ func list(ctx context.Context, path string) ([]model.Obj, error) {
} }
objs, err := operations.List(ctx, storage, actualPath, model.ListArgs{ objs, err := operations.List(ctx, storage, actualPath, model.ListArgs{
ReqPath: path, ReqPath: path,
}) }, refresh...)
if err != nil { if err != nil {
log.Errorf("%+v", err) log.Errorf("%+v", err)
if len(virtualFiles) != 0 { if len(virtualFiles) != 0 {

View File

@ -22,6 +22,7 @@ type ListReq struct {
common.PageReq common.PageReq
Path string `json:"path" form:"path"` Path string `json:"path" form:"path"`
Password string `json:"password" form:"password"` Password string `json:"password" form:"password"`
Refresh bool `json:"refresh"`
} }
type DirReq struct { type DirReq struct {
@ -67,7 +68,11 @@ func FsList(c *gin.Context) {
common.ErrorStrResp(c, "password is incorrect", 403) common.ErrorStrResp(c, "password is incorrect", 403)
return return
} }
objs, err := fs.List(c, req.Path) if !user.CanWrite() && !canWrite(meta, req.Path) && req.Refresh {
common.ErrorStrResp(c, "Refresh without permission", 403)
return
}
objs, err := fs.List(c, req.Path, req.Refresh)
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return