Merge branch 'master' into feat/viper-config

This commit is contained in:
Henrique Dias 2025-11-16 14:36:44 +01:00
commit a05e562fbf
No known key found for this signature in database
11 changed files with 42 additions and 76 deletions

View File

@ -2,6 +2,19 @@
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines. All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
## [2.47.0](https://github.com/filebrowser/filebrowser/compare/v2.46.1...v2.47.0) (2025-11-16)
### Features
* add TUS settings to the command line ([#5556](https://github.com/filebrowser/filebrowser/issues/5556)) ([e24e1f1](https://github.com/filebrowser/filebrowser/commit/e24e1f1abae9e80add620c4ad65660ca1b575a49))
* remove importer of v1 config ([#5550](https://github.com/filebrowser/filebrowser/issues/5550)) ([ceb5e72](https://github.com/filebrowser/filebrowser/commit/ceb5e723f3ee2c966bb561a804015246450280ca))
### Bug Fixes
* exit 0 when gracefully shutting down ([#5555](https://github.com/filebrowser/filebrowser/issues/5555)) ([5de4099](https://github.com/filebrowser/filebrowser/commit/5de4099cba2cf012d4a213c8eb29c412fc72c151))
## [2.46.1](https://github.com/filebrowser/filebrowser/compare/v2.46.0...v2.46.1) (2025-11-15) ## [2.46.1](https://github.com/filebrowser/filebrowser/compare/v2.46.0...v2.46.1) (2025-11-15)

View File

@ -49,6 +49,7 @@ tasks:
cmds: cmds:
- task: docs:cli:generate - task: docs:cli:generate
- git add www/docs/cli - git add www/docs/cli
- "git commit -m 'chore(docs): update CLI documentation'"
- task: release:dry-run - task: release:dry-run
- task: release:make - task: release:make

View File

@ -48,13 +48,18 @@ func addConfigFlags(flags *pflag.FlagSet) {
flags.String("branding.name", "", "replace 'File Browser' by this name") flags.String("branding.name", "", "replace 'File Browser' by this name")
flags.String("branding.theme", "", "set the theme") flags.String("branding.theme", "", "set the theme")
flags.String("branding.color", "", "set the theme color") flags.String("branding.color", "", "set the theme color")
flags.String("branding.files", "", "path to directory with images and custom styles") flags.String("branding.files", "", "path to directory with images and custom styles")
flags.Bool("branding.disableExternal", false, "disable external links such as GitHub links") flags.Bool("branding.disableExternal", false, "disable external links such as GitHub links")
flags.Bool("branding.disableUsedPercentage", false, "disable used disk percentage graph") flags.Bool("branding.disableUsedPercentage", false, "disable used disk percentage graph")
// NB: these are string so they can be presented as octal in the help text // NB: these are string so they can be presented as octal in the help text
// as that's the conventional representation for modes in Unix. // as that's the conventional representation for modes in Unix.
flags.String("fileMode", fmt.Sprintf("%O", settings.DefaultFileMode), "Mode bits that new files are created with") flags.String("fileMode", fmt.Sprintf("%O", settings.DefaultFileMode), "mode bits that new files are created with")
flags.String("dirMode", fmt.Sprintf("%O", settings.DefaultDirMode), "Mode bits that new directories are created with") flags.String("dirMode", fmt.Sprintf("%O", settings.DefaultDirMode), "mode bits that new directories are created with")
flags.Uint64("tus.chunkSize", settings.DefaultTusChunkSize, "the tus chunk size")
flags.Uint16("tus.retryCount", settings.DefaultTusRetryCount, "the tus retry count")
} }
func getAuthMethod(v *viper.Viper, defaults ...interface{}) (settings.AuthMethod, map[string]interface{}, error) { func getAuthMethod(v *viper.Viper, defaults ...interface{}) (settings.AuthMethod, map[string]interface{}, error) {
@ -196,6 +201,9 @@ func printSettings(ser *settings.Server, set *settings.Settings, auther auth.Aut
fmt.Fprintf(w, "\tTLS Cert:\t%s\n", ser.TLSCert) fmt.Fprintf(w, "\tTLS Cert:\t%s\n", ser.TLSCert)
fmt.Fprintf(w, "\tTLS Key:\t%s\n", ser.TLSKey) fmt.Fprintf(w, "\tTLS Key:\t%s\n", ser.TLSKey)
fmt.Fprintf(w, "\tExec Enabled:\t%t\n", ser.EnableExec) fmt.Fprintf(w, "\tExec Enabled:\t%t\n", ser.EnableExec)
fmt.Fprintln(w, "\nTUS:")
fmt.Fprintf(w, "\tChunk size:\t%d\n", set.Tus.ChunkSize)
fmt.Fprintf(w, "\tRetry count:\t%d\n", set.Tus.RetryCount)
fmt.Fprintln(w, "\nDefaults:") fmt.Fprintln(w, "\nDefaults:")
fmt.Fprintf(w, "\tScope:\t%s\n", set.Defaults.Scope) fmt.Fprintf(w, "\tScope:\t%s\n", set.Defaults.Scope)
fmt.Fprintf(w, "\tHideDotfiles:\t%t\n", set.Defaults.HideDotfiles) fmt.Fprintf(w, "\tHideDotfiles:\t%t\n", set.Defaults.HideDotfiles)

View File

@ -50,6 +50,10 @@ override the options.`,
Theme: v.GetString("branding.theme"), Theme: v.GetString("branding.theme"),
Files: v.GetString("branding.files"), Files: v.GetString("branding.files"),
}, },
Tus: settings.Tus{
ChunkSize: v.GetUint64("tus.chunkSize"),
RetryCount: v.GetUint16("tus.retryCount"),
},
} }
s.FileMode, err = parseFileMode(v.GetString("fileMode")) s.FileMode, err = parseFileMode(v.GetString("fileMode"))

View File

@ -81,6 +81,10 @@ you want to change. Other options will remain unchanged.`,
set.FileMode, err = parseFileMode(v.GetString(key)) set.FileMode, err = parseFileMode(v.GetString(key))
case "dirmode": case "dirmode":
set.DirMode, err = parseFileMode(v.GetString(key)) set.DirMode, err = parseFileMode(v.GetString(key))
case "tus.chunksize":
set.Tus.ChunkSize = v.GetUint64(key)
case "tus.retrycount":
set.Tus.RetryCount = v.GetUint16(key)
} }
if err != nil { if err != nil {

View File

@ -24,7 +24,6 @@ import (
"github.com/filebrowser/filebrowser/v2/auth" "github.com/filebrowser/filebrowser/v2/auth"
"github.com/filebrowser/filebrowser/v2/diskcache" "github.com/filebrowser/filebrowser/v2/diskcache"
fbErrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/frontend" "github.com/filebrowser/filebrowser/v2/frontend"
fbhttp "github.com/filebrowser/filebrowser/v2/http" fbhttp "github.com/filebrowser/filebrowser/v2/http"
"github.com/filebrowser/filebrowser/v2/img" "github.com/filebrowser/filebrowser/v2/img"
@ -250,18 +249,7 @@ user created with the credentials from options "username" and "password".`,
} }
log.Println("Graceful shutdown complete.") log.Println("Graceful shutdown complete.")
switch sig { return nil
case syscall.SIGHUP:
d.err = fbErrors.ErrSighup
case syscall.SIGINT:
d.err = fbErrors.ErrSigint
case syscall.SIGQUIT:
d.err = fbErrors.ErrSigquit
case syscall.SIGTERM:
d.err = fbErrors.ErrSigTerm
}
return d.err
}, pythonConfig{allowNoDB: true}), }, pythonConfig{allowNoDB: true}),
} }

View File

@ -137,7 +137,6 @@ type pythonConfig struct {
type pythonData struct { type pythonData struct {
hadDB bool hadDB bool
store *storage.Storage store *storage.Storage
err error
} }
func python(fn pythonFunc, cfg pythonConfig) cobraFunc { func python(fn pythonFunc, cfg pythonConfig) cobraFunc {

View File

@ -3,15 +3,6 @@ package errors
import ( import (
"errors" "errors"
"fmt" "fmt"
"os"
"syscall"
)
const (
ExitCodeSigTerm = 128 + int(syscall.SIGTERM)
ExitCodeSighup = 128 + int(syscall.SIGHUP)
ExitCodeSigint = 128 + int(syscall.SIGINT)
ExitCodeSigquit = 128 + int(syscall.SIGQUIT)
) )
var ( var (
@ -31,10 +22,6 @@ var (
ErrInvalidRequestParams = errors.New("invalid request params") ErrInvalidRequestParams = errors.New("invalid request params")
ErrSourceIsParent = errors.New("source is parent") ErrSourceIsParent = errors.New("source is parent")
ErrRootUserDeletion = errors.New("user with id 1 can't be deleted") ErrRootUserDeletion = errors.New("user with id 1 can't be deleted")
ErrSigTerm = errors.New("exit on signal: sigterm")
ErrSighup = errors.New("exit on signal: sighup")
ErrSigint = errors.New("exit on signal: sigint")
ErrSigquit = errors.New("exit on signal: sigquit")
) )
type ErrShortPassword struct { type ErrShortPassword struct {
@ -44,44 +31,3 @@ type ErrShortPassword struct {
func (e ErrShortPassword) Error() string { func (e ErrShortPassword) Error() string {
return fmt.Sprintf("password is too short, minimum length is %d", e.MinimumLength) return fmt.Sprintf("password is too short, minimum length is %d", e.MinimumLength)
} }
// GetExitCode returns the exit code for a given error.
func GetExitCode(err error) int {
if err == nil {
return 0
}
exitCodeMap := map[error]int{
ErrSigTerm: ExitCodeSigTerm,
ErrSighup: ExitCodeSighup,
ErrSigint: ExitCodeSigint,
ErrSigquit: ExitCodeSigquit,
}
for e, code := range exitCodeMap {
if errors.Is(err, e) {
return code
}
}
if exitErr, ok := err.(interface{ ExitCode() int }); ok {
return exitErr.ExitCode()
}
var pathErr *os.PathError
if errors.As(err, &pathErr) {
return 1
}
var syscallErr *os.SyscallError
if errors.As(err, &syscallErr) {
return 1
}
var errno syscall.Errno
if errors.As(err, &errno) {
return 1
}
return 1
}

View File

@ -4,11 +4,10 @@ import (
"os" "os"
"github.com/filebrowser/filebrowser/v2/cmd" "github.com/filebrowser/filebrowser/v2/cmd"
"github.com/filebrowser/filebrowser/v2/errors"
) )
func main() { func main() {
if err := cmd.Execute(); err != nil { if err := cmd.Execute(); err != nil {
os.Exit(errors.GetExitCode(err)) os.Exit(1)
} }
} }

View File

@ -34,12 +34,12 @@ filebrowser config init [flags]
--commands strings a list of the commands a user can execute --commands strings a list of the commands a user can execute
--create-user-dir generate user's home directory automatically --create-user-dir generate user's home directory automatically
--dateFormat use date format (true for absolute time, false for relative) --dateFormat use date format (true for absolute time, false for relative)
--dir-mode string Mode bits that new directories are created with (default "0o750") --dir-mode string mode bits that new directories are created with (default "0o750")
--disable-exec disables Command Runner feature (default true) --disable-exec disables Command Runner feature (default true)
--disable-preview-resize disable resize of image previews --disable-preview-resize disable resize of image previews
--disable-thumbnails disable image thumbnails --disable-thumbnails disable image thumbnails
--disable-type-detection-by-header disables type detection by reading file headers --disable-type-detection-by-header disables type detection by reading file headers
--file-mode string Mode bits that new files are created with (default "0o640") --file-mode string mode bits that new files are created with (default "0o640")
-h, --help help for init -h, --help help for init
--hide-login-button hide login button from public pages --hide-login-button hide login button from public pages
--hideDotfiles hide dotfiles --hideDotfiles hide dotfiles
@ -71,6 +71,8 @@ filebrowser config init [flags]
--sorting.asc sorting by ascending order --sorting.asc sorting by ascending order
--sorting.by string sorting mode (name, size or modified) (default "name") --sorting.by string sorting mode (name, size or modified) (default "name")
--token-expiration-time string user session timeout (default "2h") --token-expiration-time string user session timeout (default "2h")
--tus.chunkSize uint the tus chunk size (default 10485760)
--tus.retryCount uint16 the tus retry count (default 5)
--viewMode string view mode for users (default "list") --viewMode string view mode for users (default "list")
``` ```

View File

@ -31,12 +31,12 @@ filebrowser config set [flags]
--commands strings a list of the commands a user can execute --commands strings a list of the commands a user can execute
--create-user-dir generate user's home directory automatically --create-user-dir generate user's home directory automatically
--dateFormat use date format (true for absolute time, false for relative) --dateFormat use date format (true for absolute time, false for relative)
--dir-mode string Mode bits that new directories are created with (default "0o750") --dir-mode string mode bits that new directories are created with (default "0o750")
--disable-exec disables Command Runner feature (default true) --disable-exec disables Command Runner feature (default true)
--disable-preview-resize disable resize of image previews --disable-preview-resize disable resize of image previews
--disable-thumbnails disable image thumbnails --disable-thumbnails disable image thumbnails
--disable-type-detection-by-header disables type detection by reading file headers --disable-type-detection-by-header disables type detection by reading file headers
--file-mode string Mode bits that new files are created with (default "0o640") --file-mode string mode bits that new files are created with (default "0o640")
-h, --help help for set -h, --help help for set
--hide-login-button hide login button from public pages --hide-login-button hide login button from public pages
--hideDotfiles hide dotfiles --hideDotfiles hide dotfiles
@ -68,6 +68,8 @@ filebrowser config set [flags]
--sorting.asc sorting by ascending order --sorting.asc sorting by ascending order
--sorting.by string sorting mode (name, size or modified) (default "name") --sorting.by string sorting mode (name, size or modified) (default "name")
--token-expiration-time string user session timeout (default "2h") --token-expiration-time string user session timeout (default "2h")
--tus.chunkSize uint the tus chunk size (default 10485760)
--tus.retryCount uint16 the tus retry count (default 5)
--viewMode string view mode for users (default "list") --viewMode string view mode for users (default "list")
``` ```