refactor: cleanup package names (#5605)

This commit is contained in:
Henrique Dias
2025-12-06 10:52:11 +01:00
committed by GitHub
parent a6934e40ff
commit f029c3005e
33 changed files with 78 additions and 78 deletions

View File

@@ -11,7 +11,7 @@ import (
"slices" "slices"
"strings" "strings"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/files" "github.com/filebrowser/filebrowser/v2/files"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/filebrowser/filebrowser/v2/users"
@@ -146,7 +146,7 @@ func (a *HookAuth) GetValues(s string) {
// SaveUser updates the existing user or creates a new one when not found // SaveUser updates the existing user or creates a new one when not found
func (a *HookAuth) SaveUser() (*users.User, error) { func (a *HookAuth) SaveUser() (*users.User, error) {
u, err := a.Users.Get(a.Server.Root, a.Cred.Username) u, err := a.Users.Get(a.Server.Root, a.Cred.Username)
if err != nil && !errors.Is(err, fbErrors.ErrNotExist) { if err != nil && !errors.Is(err, fberrors.ErrNotExist) {
return nil, err return nil, err
} }

View File

@@ -4,7 +4,7 @@ import (
"errors" "errors"
"net/http" "net/http"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/filebrowser/filebrowser/v2/users"
) )
@@ -21,7 +21,7 @@ type ProxyAuth struct {
func (a ProxyAuth) Auth(r *http.Request, usr users.Store, setting *settings.Settings, srv *settings.Server) (*users.User, error) { func (a ProxyAuth) Auth(r *http.Request, usr users.Store, setting *settings.Settings, srv *settings.Server) (*users.User, error) {
username := r.Header.Get(a.Header) username := r.Header.Get(a.Header)
user, err := usr.Get(srv.Root, username) user, err := usr.Get(srv.Root, username)
if errors.Is(err, fbErrors.ErrNotExist) { if errors.Is(err, fberrors.ErrNotExist) {
return a.createUser(usr, setting, srv, username) return a.createUser(usr, setting, srv, username)
} }
return user, err return user, err

View File

@@ -2,7 +2,7 @@ package cmd
import ( import (
"encoding/json" "encoding/json"
nerrors "errors" "errors"
"fmt" "fmt"
"os" "os"
"strings" "strings"
@@ -12,7 +12,7 @@ import (
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/filebrowser/filebrowser/v2/auth" "github.com/filebrowser/filebrowser/v2/auth"
"github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/filebrowser/filebrowser/v2/settings"
) )
@@ -104,7 +104,7 @@ func getProxyAuth(flags *pflag.FlagSet, defaultAuther map[string]interface{}) (a
} }
if header == "" { if header == "" {
return nil, nerrors.New("you must set the flag 'auth.header' for method 'proxy'") return nil, errors.New("you must set the flag 'auth.header' for method 'proxy'")
} }
return &auth.ProxyAuth{Header: header}, nil return &auth.ProxyAuth{Header: header}, nil
@@ -163,7 +163,7 @@ func getHookAuth(flags *pflag.FlagSet, defaultAuther map[string]interface{}) (au
} }
if command == "" { if command == "" {
return nil, nerrors.New("you must set the flag 'auth.command' for method 'hook'") return nil, errors.New("you must set the flag 'auth.command' for method 'hook'")
} }
return &auth.HookAuth{Command: command}, nil return &auth.HookAuth{Command: command}, nil
@@ -186,7 +186,7 @@ func getAuthentication(flags *pflag.FlagSet, defaults ...interface{}) (settings.
case auth.MethodHookAuth: case auth.MethodHookAuth:
auther, err = getHookAuth(flags, defaultAuther) auther, err = getHookAuth(flags, defaultAuther)
default: default:
return "", nil, errors.ErrInvalidAuthMethod return "", nil, fberrors.ErrInvalidAuthMethod
} }
if err != nil { if err != nil {
@@ -361,7 +361,7 @@ func getSettings(flags *pflag.FlagSet, set *settings.Settings, ser *settings.Ser
flags.Visit(visit) flags.Visit(visit)
} }
err := nerrors.Join(errs...) err := errors.Join(errs...)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -1,4 +1,4 @@
package errors package fberrors
import ( import (
"errors" "errors"

View File

@@ -23,7 +23,7 @@ import (
"github.com/spf13/afero" "github.com/spf13/afero"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/filebrowser/filebrowser/v2/rules"
) )
@@ -168,7 +168,7 @@ func stat(opts *FileOptions) (*FileInfo, error) {
// algorithm. The checksums data is saved on File object. // algorithm. The checksums data is saved on File object.
func (i *FileInfo) Checksum(algo string) error { func (i *FileInfo) Checksum(algo string) error {
if i.IsDir { if i.IsDir {
return fbErrors.ErrIsDirectory return fberrors.ErrIsDirectory
} }
if i.Checksums == nil { if i.Checksums == nil {
@@ -193,7 +193,7 @@ func (i *FileInfo) Checksum(algo string) error {
case "sha512": case "sha512":
h = sha512.New() h = sha512.New()
default: default:
return fbErrors.ErrInvalidOption return fberrors.ErrInvalidOption
} }
_, err = io.Copy(h, reader) _, err = io.Copy(h, reader)

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"encoding/json" "encoding/json"
@@ -13,7 +13,7 @@ import (
"github.com/golang-jwt/jwt/v5/request" "github.com/golang-jwt/jwt/v5/request"
fbAuth "github.com/filebrowser/filebrowser/v2/auth" fbAuth "github.com/filebrowser/filebrowser/v2/auth"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/filebrowser/filebrowser/v2/users"
) )
@@ -185,7 +185,7 @@ var signupHandler = func(_ http.ResponseWriter, r *http.Request, d *data) (int,
log.Printf("new user: %s, home dir: [%s].", user.Username, userHome) log.Printf("new user: %s, home dir: [%s].", user.Username, userHome)
err = d.store.Users.Save(user) err = d.store.Users.Save(user)
if errors.Is(err, fbErrors.ErrExist) { if errors.Is(err, fberrors.ErrExist) {
return http.StatusConflict, err return http.StatusConflict, err
} else if err != nil { } else if err != nil {
return http.StatusInternalServerError, err return http.StatusInternalServerError, err

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"bufio" "bufio"

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"log" "log"

View File

@@ -1,6 +1,6 @@
//go:build !dev //go:build !dev
package http package fbhttp
// global headers to append to every response // global headers to append to every response
var globalHeaders = map[string]string{ var globalHeaders = map[string]string{

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"io/fs" "io/fs"

View File

@@ -1,5 +1,5 @@
//go:generate go-enum --sql --marshal --names --file $GOFILE //go:generate go-enum --sql --marshal --names --file $GOFILE
package http package fbhttp
import ( import (
"bytes" "bytes"

View File

@@ -1,7 +1,7 @@
// Code generated by go-enum // Code generated by go-enum
// DO NOT EDIT! // DO NOT EDIT!
package http package fbhttp
import ( import (
"database/sql/driver" "database/sql/driver"

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"errors" "errors"

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"fmt" "fmt"

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"errors" "errors"

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"context" "context"
@@ -17,7 +17,7 @@ import (
"github.com/shirou/gopsutil/v4/disk" "github.com/shirou/gopsutil/v4/disk"
"github.com/spf13/afero" "github.com/spf13/afero"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/files" "github.com/filebrowser/filebrowser/v2/files"
"github.com/filebrowser/filebrowser/v2/fileutils" "github.com/filebrowser/filebrowser/v2/fileutils"
) )
@@ -44,7 +44,7 @@ var resourceGetHandler = withUser(func(w http.ResponseWriter, r *http.Request, d
if checksum := r.URL.Query().Get("checksum"); checksum != "" { if checksum := r.URL.Query().Get("checksum"); checksum != "" {
err := file.Checksum(checksum) err := file.Checksum(checksum)
if errors.Is(err, fbErrors.ErrInvalidOption) { if errors.Is(err, fberrors.ErrInvalidOption) {
return http.StatusBadRequest, nil return http.StatusBadRequest, nil
} else if err != nil { } else if err != nil {
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
@@ -238,7 +238,7 @@ func checkParent(src, dst string) error {
rel = filepath.ToSlash(rel) rel = filepath.ToSlash(rel)
if !strings.HasPrefix(rel, "../") && rel != ".." && rel != "." { if !strings.HasPrefix(rel, "../") && rel != ".." && rel != "." {
return fbErrors.ErrSourceIsParent return fberrors.ErrSourceIsParent
} }
return nil return nil
@@ -304,13 +304,13 @@ func patchAction(ctx context.Context, action, src, dst string, d *data, fileCach
switch action { switch action {
case "copy": case "copy":
if !d.user.Perm.Create { if !d.user.Perm.Create {
return fbErrors.ErrPermissionDenied return fberrors.ErrPermissionDenied
} }
return fileutils.Copy(d.user.Fs, src, dst, d.settings.FileMode, d.settings.DirMode) return fileutils.Copy(d.user.Fs, src, dst, d.settings.FileMode, d.settings.DirMode)
case "rename": case "rename":
if !d.user.Perm.Rename { if !d.user.Perm.Rename {
return fbErrors.ErrPermissionDenied return fberrors.ErrPermissionDenied
} }
src = path.Clean("/" + src) src = path.Clean("/" + src)
dst = path.Clean("/" + dst) dst = path.Clean("/" + dst)
@@ -335,7 +335,7 @@ func patchAction(ctx context.Context, action, src, dst string, d *data, fileCach
return fileutils.MoveFile(d.user.Fs, src, dst, d.settings.FileMode, d.settings.DirMode) return fileutils.MoveFile(d.user.Fs, src, dst, d.settings.FileMode, d.settings.DirMode)
default: default:
return fmt.Errorf("unsupported action %s: %w", action, fbErrors.ErrInvalidRequestParams) return fmt.Errorf("unsupported action %s: %w", action, fberrors.ErrInvalidRequestParams)
} }
} }

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"net/http" "net/http"

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"encoding/json" "encoding/json"

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"crypto/rand" "crypto/rand"
@@ -14,7 +14,7 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/share" "github.com/filebrowser/filebrowser/v2/share"
) )
@@ -38,7 +38,7 @@ var shareListHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
} else { } else {
s, err = d.store.Share.FindByUserID(d.user.ID) s, err = d.store.Share.FindByUserID(d.user.ID)
} }
if errors.Is(err, fbErrors.ErrNotExist) { if errors.Is(err, fberrors.ErrNotExist) {
return renderJSON(w, r, []*share.Link{}) return renderJSON(w, r, []*share.Link{})
} }
@@ -58,7 +58,7 @@ var shareListHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
var shareGetsHandler = withPermShare(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { var shareGetsHandler = withPermShare(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
s, err := d.store.Share.Gets(r.URL.Path, d.user.ID) s, err := d.store.Share.Gets(r.URL.Path, d.user.ID)
if errors.Is(err, fbErrors.ErrNotExist) { if errors.Is(err, fberrors.ErrNotExist) {
return renderJSON(w, r, []*share.Link{}) return renderJSON(w, r, []*share.Link{})
} }

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"encoding/json" "encoding/json"

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"bytes" "bytes"

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"context" "context"

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"encoding/json" "encoding/json"
@@ -12,7 +12,7 @@ import (
"golang.org/x/text/cases" "golang.org/x/text/cases"
"golang.org/x/text/language" "golang.org/x/text/language"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/users" "github.com/filebrowser/filebrowser/v2/users"
) )
@@ -36,7 +36,7 @@ func getUserID(r *http.Request) (uint, error) {
func getUser(_ http.ResponseWriter, r *http.Request) (*modifyUserRequest, error) { func getUser(_ http.ResponseWriter, r *http.Request) (*modifyUserRequest, error) {
if r.Body == nil { if r.Body == nil {
return nil, fbErrors.ErrEmptyRequest return nil, fberrors.ErrEmptyRequest
} }
req := &modifyUserRequest{} req := &modifyUserRequest{}
@@ -46,7 +46,7 @@ func getUser(_ http.ResponseWriter, r *http.Request) (*modifyUserRequest, error)
} }
if req.What != "user" { if req.What != "user" {
return nil, fbErrors.ErrInvalidDataType return nil, fberrors.ErrInvalidDataType
} }
return req, nil return req, nil
@@ -87,7 +87,7 @@ var usersGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *
var userGetHandler = withSelfOrAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { var userGetHandler = withSelfOrAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
u, err := d.store.Users.Get(d.server.Root, d.raw.(uint)) u, err := d.store.Users.Get(d.server.Root, d.raw.(uint))
if errors.Is(err, fbErrors.ErrNotExist) { if errors.Is(err, fberrors.ErrNotExist) {
return http.StatusNotFound, err return http.StatusNotFound, err
} }
@@ -122,7 +122,7 @@ var userPostHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *
} }
if req.Data.Password == "" { if req.Data.Password == "" {
return http.StatusBadRequest, fbErrors.ErrEmptyPassword return http.StatusBadRequest, fberrors.ErrEmptyPassword
} }
req.Data.Password, err = users.ValidateAndHashPwd(req.Data.Password, d.settings.MinimumPasswordLength) req.Data.Password, err = users.ValidateAndHashPwd(req.Data.Password, d.settings.MinimumPasswordLength)

View File

@@ -1,4 +1,4 @@
package http package fbhttp
import ( import (
"encoding/json" "encoding/json"

View File

@@ -1,7 +1,7 @@
package settings package settings
import ( import (
"github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/filebrowser/filebrowser/v2/rules"
"github.com/filebrowser/filebrowser/v2/users" "github.com/filebrowser/filebrowser/v2/users"
) )
@@ -72,7 +72,7 @@ var defaultEvents = []string{
// Save saves the settings for the current instance. // Save saves the settings for the current instance.
func (s *Storage) Save(set *Settings) error { func (s *Storage) Save(set *Settings) error {
if len(set.Key) == 0 { if len(set.Key) == 0 {
return errors.ErrEmptyKey return fberrors.ErrEmptyKey
} }
if set.Defaults.Locale == "" { if set.Defaults.Locale == "" {

View File

@@ -3,7 +3,7 @@ package share
import ( import (
"time" "time"
"github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
) )
// StorageBackend is the interface to implement for a share storage. // StorageBackend is the interface to implement for a share storage.
@@ -79,7 +79,7 @@ func (s *Storage) GetByHash(hash string) (*Link, error) {
if err := s.Delete(link.Hash); err != nil { if err := s.Delete(link.Hash); err != nil {
return nil, err return nil, err
} }
return nil, errors.ErrNotExist return nil, fberrors.ErrNotExist
} }
return link, nil return link, nil

View File

@@ -4,7 +4,7 @@ import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/filebrowser/filebrowser/v2/auth" "github.com/filebrowser/filebrowser/v2/auth"
"github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/filebrowser/filebrowser/v2/settings"
) )
@@ -25,7 +25,7 @@ func (s authBackend) Get(t settings.AuthMethod) (auth.Auther, error) {
case auth.MethodNoAuth: case auth.MethodNoAuth:
auther = &auth.NoAuth{} auther = &auth.NoAuth{}
default: default:
return nil, errors.ErrInvalidAuthMethod return nil, fberrors.ErrInvalidAuthMethod
} }
return auther, get(s.db, "auther", auther) return auther, get(s.db, "auther", auther)

View File

@@ -6,7 +6,7 @@ import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/asdine/storm/v3/q" "github.com/asdine/storm/v3/q"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/share" "github.com/filebrowser/filebrowser/v2/share"
) )
@@ -18,7 +18,7 @@ func (s shareBackend) All() ([]*share.Link, error) {
var v []*share.Link var v []*share.Link
err := s.db.All(&v) err := s.db.All(&v)
if errors.Is(err, storm.ErrNotFound) { if errors.Is(err, storm.ErrNotFound) {
return v, fbErrors.ErrNotExist return v, fberrors.ErrNotExist
} }
return v, err return v, err
@@ -28,7 +28,7 @@ func (s shareBackend) FindByUserID(id uint) ([]*share.Link, error) {
var v []*share.Link var v []*share.Link
err := s.db.Select(q.Eq("UserID", id)).Find(&v) err := s.db.Select(q.Eq("UserID", id)).Find(&v)
if errors.Is(err, storm.ErrNotFound) { if errors.Is(err, storm.ErrNotFound) {
return v, fbErrors.ErrNotExist return v, fberrors.ErrNotExist
} }
return v, err return v, err
@@ -38,7 +38,7 @@ func (s shareBackend) GetByHash(hash string) (*share.Link, error) {
var v share.Link var v share.Link
err := s.db.One("Hash", hash, &v) err := s.db.One("Hash", hash, &v)
if errors.Is(err, storm.ErrNotFound) { if errors.Is(err, storm.ErrNotFound) {
return nil, fbErrors.ErrNotExist return nil, fberrors.ErrNotExist
} }
return &v, err return &v, err
@@ -48,7 +48,7 @@ func (s shareBackend) GetPermanent(path string, id uint) (*share.Link, error) {
var v share.Link var v share.Link
err := s.db.Select(q.Eq("Path", path), q.Eq("Expire", 0), q.Eq("UserID", id)).First(&v) err := s.db.Select(q.Eq("Path", path), q.Eq("Expire", 0), q.Eq("UserID", id)).First(&v)
if errors.Is(err, storm.ErrNotFound) { if errors.Is(err, storm.ErrNotFound) {
return nil, fbErrors.ErrNotExist return nil, fberrors.ErrNotExist
} }
return &v, err return &v, err
@@ -58,7 +58,7 @@ func (s shareBackend) Gets(path string, id uint) ([]*share.Link, error) {
var v []*share.Link var v []*share.Link
err := s.db.Select(q.Eq("Path", path), q.Eq("UserID", id)).Find(&v) err := s.db.Select(q.Eq("Path", path), q.Eq("UserID", id)).Find(&v)
if errors.Is(err, storm.ErrNotFound) { if errors.Is(err, storm.ErrNotFound) {
return v, fbErrors.ErrNotExist return v, fberrors.ErrNotExist
} }
return v, err return v, err

View File

@@ -7,7 +7,7 @@ import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/users" "github.com/filebrowser/filebrowser/v2/users"
) )
@@ -25,14 +25,14 @@ func (st usersBackend) GetBy(i interface{}) (user *users.User, err error) {
case string: case string:
arg = "Username" arg = "Username"
default: default:
return nil, fbErrors.ErrInvalidDataType return nil, fberrors.ErrInvalidDataType
} }
err = st.db.One(arg, i, user) err = st.db.One(arg, i, user)
if err != nil { if err != nil {
if errors.Is(err, storm.ErrNotFound) { if errors.Is(err, storm.ErrNotFound) {
return nil, fbErrors.ErrNotExist return nil, fberrors.ErrNotExist
} }
return nil, err return nil, err
} }
@@ -44,7 +44,7 @@ func (st usersBackend) Gets() ([]*users.User, error) {
var allUsers []*users.User var allUsers []*users.User
err := st.db.All(&allUsers) err := st.db.All(&allUsers)
if errors.Is(err, storm.ErrNotFound) { if errors.Is(err, storm.ErrNotFound) {
return nil, fbErrors.ErrNotExist return nil, fberrors.ErrNotExist
} }
if err != nil { if err != nil {
@@ -76,7 +76,7 @@ func (st usersBackend) Update(user *users.User, fields ...string) error {
func (st usersBackend) Save(user *users.User) error { func (st usersBackend) Save(user *users.User) error {
err := st.db.Save(user) err := st.db.Save(user)
if errors.Is(err, storm.ErrAlreadyExists) { if errors.Is(err, storm.ErrAlreadyExists) {
return fbErrors.ErrExist return fberrors.ErrExist
} }
return err return err
} }

View File

@@ -5,13 +5,13 @@ import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
) )
func get(db *storm.DB, name string, to interface{}) error { func get(db *storm.DB, name string, to interface{}) error {
err := db.Get("config", name, to) err := db.Get("config", name, to)
if errors.Is(err, storm.ErrNotFound) { if errors.Is(err, storm.ErrNotFound) {
return fbErrors.ErrNotExist return fberrors.ErrNotExist
} }
return err return err

View File

@@ -6,17 +6,17 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
fbErrors "github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
) )
// ValidateAndHashPwd validates and hashes a password. // ValidateAndHashPwd validates and hashes a password.
func ValidateAndHashPwd(password string, minimumLength uint) (string, error) { func ValidateAndHashPwd(password string, minimumLength uint) (string, error) {
if uint(len(password)) < minimumLength { if uint(len(password)) < minimumLength {
return "", fbErrors.ErrShortPassword{MinimumLength: minimumLength} return "", fberrors.ErrShortPassword{MinimumLength: minimumLength}
} }
if _, ok := commonPasswords[password]; ok { if _, ok := commonPasswords[password]; ok {
return "", fbErrors.ErrEasyPassword return "", fberrors.ErrEasyPassword
} }
return HashPwd(password) return HashPwd(password)

View File

@@ -4,7 +4,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
) )
// StorageBackend is the interface to implement for a users storage. // StorageBackend is the interface to implement for a users storage.
@@ -109,16 +109,16 @@ func (s *Storage) Delete(id interface{}) error {
return err return err
} }
if user.ID == 1 { if user.ID == 1 {
return errors.ErrRootUserDeletion return fberrors.ErrRootUserDeletion
} }
return s.back.DeleteByUsername(id) return s.back.DeleteByUsername(id)
case uint: case uint:
if id == 1 { if id == 1 {
return errors.ErrRootUserDeletion return fberrors.ErrRootUserDeletion
} }
return s.back.DeleteByID(id) return s.back.DeleteByID(id)
default: default:
return errors.ErrInvalidDataType return fberrors.ErrInvalidDataType
} }
} }

View File

@@ -5,7 +5,7 @@ import (
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/filebrowser/filebrowser/v2/errors" fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/files" "github.com/filebrowser/filebrowser/v2/files"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/filebrowser/filebrowser/v2/rules"
) )
@@ -64,11 +64,11 @@ func (u *User) Clean(baseScope string, fields ...string) error {
switch field { switch field {
case "Username": case "Username":
if u.Username == "" { if u.Username == "" {
return errors.ErrEmptyUsername return fberrors.ErrEmptyUsername
} }
case "Password": case "Password":
if u.Password == "" { if u.Password == "" {
return errors.ErrEmptyPassword return fberrors.ErrEmptyPassword
} }
case "ViewMode": case "ViewMode":
if u.ViewMode == "" { if u.ViewMode == "" {