mirror of https://github.com/Xhofe/alist
🎇 hide files while webdav visitor
parent
0a901a2eb0
commit
6d34e88360
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/Xhofe/alist/drivers/base"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
|
@ -85,3 +86,18 @@ func SuccessResp(c *gin.Context, data ...interface{}) {
|
|||
Data: data[0],
|
||||
})
|
||||
}
|
||||
|
||||
func Hide(meta *model.Meta, files []model.File) []model.File {
|
||||
//meta, _ := model.GetMetaByPath(path)
|
||||
if meta != nil && meta.Hide != "" {
|
||||
tmpFiles := make([]model.File, 0)
|
||||
hideFiles := strings.Split(meta.Hide, ",")
|
||||
for _, item := range files {
|
||||
if !utils.IsContain(hideFiles, item.Name) {
|
||||
tmpFiles = append(tmpFiles, item)
|
||||
}
|
||||
}
|
||||
files = tmpFiles
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
|
|
@ -10,24 +10,8 @@ import (
|
|||
"github.com/Xhofe/alist/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Hide(meta *model.Meta, files []model.File) []model.File {
|
||||
//meta, _ := model.GetMetaByPath(path)
|
||||
if meta != nil && meta.Hide != "" {
|
||||
tmpFiles := make([]model.File, 0)
|
||||
hideFiles := strings.Split(meta.Hide, ",")
|
||||
for _, item := range files {
|
||||
if !utils.IsContain(hideFiles, item.Name) {
|
||||
tmpFiles = append(tmpFiles, item)
|
||||
}
|
||||
}
|
||||
files = tmpFiles
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
func Pagination(files []model.File, req *common.PathReq) (int, []model.File) {
|
||||
pageNum, pageSize := req.PageNum, req.PageSize
|
||||
total := len(files)
|
||||
|
@ -100,7 +84,7 @@ func Path(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
if !ok {
|
||||
files = Hide(meta, files)
|
||||
files = common.Hide(meta, files)
|
||||
}
|
||||
c.JSON(200, common.Resp{
|
||||
Code: 200,
|
||||
|
@ -159,7 +143,7 @@ func Path(c *gin.Context) {
|
|||
})
|
||||
} else {
|
||||
if !ok {
|
||||
files = Hide(meta, files)
|
||||
files = common.Hide(meta, files)
|
||||
}
|
||||
if driver.Config().LocalSort {
|
||||
model.SortFiles(files, account)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/server/webdav"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
|
@ -58,6 +59,8 @@ func WebDAVAuth(c *gin.Context) {
|
|||
(conf.GetStr("Visitor WebDAV username") == "" &&
|
||||
conf.GetStr("Visitor WebDAV password") == "") {
|
||||
if !utils.IsContain([]string{"PUT", "DELETE", "PROPPATCH", "MKCOL", "COPY", "MOVE"}, c.Request.Method) {
|
||||
ctx := context.WithValue(c.Request.Context(), "visitor", true)
|
||||
c.Request = c.Request.WithContext(ctx)
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func (fs *FileSystem) File(rawPath string) (*model.File, error) {
|
|||
return driver.File(path_, account)
|
||||
}
|
||||
|
||||
func (fs *FileSystem) Files(rawPath string) ([]model.File, error) {
|
||||
func (fs *FileSystem) Files(ctx context.Context, rawPath string) ([]model.File, error) {
|
||||
rawPath = utils.ParsePath(rawPath)
|
||||
if model.AccountsCount() > 1 && rawPath == "/" {
|
||||
files, err := model.GetAccountFiles()
|
||||
|
@ -56,7 +56,20 @@ func (fs *FileSystem) Files(rawPath string) ([]model.File, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return driver.Files(path_, account)
|
||||
files, err := driver.Files(path_, account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
meta, _ := model.GetMetaByPath(rawPath)
|
||||
if visitor := ctx.Value("visitor"); visitor != nil {
|
||||
if visitor.(bool) {
|
||||
log.Debug("visitor")
|
||||
files = common.Hide(meta, files)
|
||||
}
|
||||
} else {
|
||||
log.Debug("admin")
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func ClientIP(r *http.Request) string {
|
||||
|
@ -260,7 +273,7 @@ func walkFS(
|
|||
depth = 0
|
||||
}
|
||||
|
||||
files, err := fs.Files(name)
|
||||
files, err := fs.Files(ctx, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue