This commit is contained in:
ziggi
2023-10-20 22:35:34 +02:00
parent 19db62f547
commit 764a6e7c5e
8 changed files with 78 additions and 91 deletions

View File

@@ -4,7 +4,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
// "strings"
"filer/pkg/logger"
@@ -23,20 +23,22 @@ type Handler struct {
func NewHandler(conf *HandlerConfig) (*Handler, error) {
var err error
hand := &Handler{
log: logger.NewLogger("handler"),
datadir: conf.Datadir,
log: logger.NewLogger("handler"),
}
return hand, err
}
func (hand *Handler) GetFile(gctx *gin.Context) {
filePath := gctx.FullPath()
filePath := gctx.Request.URL.Path
localFilePath := filepath.Join(hand.datadir, filePath)
if strings.Contains(localFilePath, "/../") {
gctx.Status(http.StatusBadRequest)
return
}
if len(filePath) > 0 && fileExists(localFilePath) {
hand.log.Debugf("Send file %s", localFilePath)
// if strings.Contains(localFilePath, "/../") {
// gctx.Status(http.StatusBadRequest)
// return
// }
if filePath != "" && fileExists(localFilePath) {
gctx.FileAttachment(localFilePath, filepath.Base(filePath))
return
} else {