This commit is contained in:
Graham Steffaniak 2023-09-01 21:03:45 -05:00
parent 91f4a299c4
commit 667786e487
5 changed files with 15 additions and 53 deletions

View File

@ -89,14 +89,10 @@ user created with the credentials from options "username" and "password".`,
if !d.hadDB { if !d.hadDB {
quickSetup(cmd.Flags(), d) quickSetup(cmd.Flags(), d)
} }
if serverConfig.NumImageProcessors < 1 {
workersCount := serverConfig.NumImageProcessors
log.Println(serverConfig)
if workersCount < 1 {
log.Fatal("Image resize workers count could not be < 1") log.Fatal("Image resize workers count could not be < 1")
} }
imgSvc := img.New(workersCount) imgSvc := img.New(serverConfig.NumImageProcessors)
var fileCache diskcache.Interface = diskcache.NewNoOp() var fileCache diskcache.Interface = diskcache.NewNoOp()
cacheDir := "/tmp" cacheDir := "/tmp"
if cacheDir != "" { if cacheDir != "" {
@ -105,16 +101,12 @@ user created with the credentials from options "username" and "password".`,
} }
fileCache = diskcache.New(afero.NewOsFs(), cacheDir) fileCache = diskcache.New(afero.NewOsFs(), cacheDir)
} }
// initialize indexing and schedule indexing ever n minutes (default 5) // initialize indexing and schedule indexing ever n minutes (default 5)
go search.InitializeIndex(serverConfig.IndexingInterval) go search.InitializeIndex(serverConfig.IndexingInterval)
_, err := os.Stat(serverConfig.Root) _, err := os.Stat(serverConfig.Root)
checkErr(err) checkErr(err)
var listener net.Listener var listener net.Listener
address := serverConfig.Address + ":" + strconv.Itoa(serverConfig.Port) address := serverConfig.Address + ":" + strconv.Itoa(serverConfig.Port)
switch { switch {
case serverConfig.Socket != "": case serverConfig.Socket != "":
listener, err = net.Listen("unix", serverConfig.Socket) listener, err = net.Listen("unix", serverConfig.Socket)
@ -135,17 +127,13 @@ user created with the credentials from options "username" and "password".`,
listener, err = net.Listen("tcp", address) listener, err = net.Listen("tcp", address)
checkErr(err) checkErr(err)
} }
sigc := make(chan os.Signal, 1) sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM) signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
go cleanupHandler(listener, sigc) go cleanupHandler(listener, sigc)
assetsFs := dirFS{Dir: http.Dir("frontend/dist")} assetsFs := dirFS{Dir: http.Dir("frontend/dist")}
handler, err := fbhttp.NewHandler(imgSvc, fileCache, d.store, &serverConfig, assetsFs) handler, err := fbhttp.NewHandler(imgSvc, fileCache, d.store, &serverConfig, assetsFs)
checkErr(err) checkErr(err)
defer listener.Close() defer listener.Close()
log.Println("Listening on", listener.Addr().String()) log.Println("Listening on", listener.Addr().String())
//nolint: gosec //nolint: gosec
if err := http.Serve(listener, handler); err != nil { if err := http.Serve(listener, handler); err != nil {
@ -241,13 +229,12 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) {
Shell: nil, Shell: nil,
Rules: nil, Rules: nil,
} }
var err error var err error
if settings.GlobalConfiguration.Auth.Method == "noAuth" { if settings.GlobalConfiguration.Auth.Method == "noauth" {
set.Auth.Method = "noAuth" set.Auth.Method = "noauth"
err = d.store.Auth.Save(&auth.NoAuth{}) err = d.store.Auth.Save(&auth.NoAuth{})
} else { } else {
set.Auth.Method = "json" set.Auth.Method = "password"
err = d.store.Auth.Save(&auth.JSONAuth{}) err = d.store.Auth.Save(&auth.JSONAuth{})
} }
err = d.store.Settings.Save(set) err = d.store.Settings.Save(set)

View File

@ -1,37 +1,12 @@
general:
key: []
signup: true
createUserDir: false
userHomeBasePath: ""
scope: ""
locale: ""
viewMode: ""
singleClick: false
hideDotfiles: true
dateFormat: false
defaultSortBy: ""
perm:
admin: true
execute: true
create: true
rename: true
modify: true
delete: true
share: true
download: true
shell: []
rules: []
server: server:
indexingInterval: 5 indexingInterval: 5
numImageProcessors: 1 numImageProcessors: 2
socket: "" socket: ""
tlsKey: "" tlsKey: ""
tlsCert: "" tlsCert: ""
enableThumbnails: true enableThumbnails: true
resizePreview: false resizePreview: false
enableExec: false
typeDetectionByHeader: true typeDetectionByHeader: true
authHook: ""
port: 8080 port: 8080
baseURL: "/" baseURL: "/"
address: "" address: ""
@ -44,7 +19,7 @@ auth:
key: "" key: ""
secret: "" secret: ""
header: "" header: ""
method: "noauth" method: noauth
command: "" command: ""
signup: false signup: false
shell: "" shell: ""

View File

@ -49,7 +49,6 @@ var settingsPutHandler = withAdmin(func(w http.ResponseWriter, r *http.Request,
d.settings.Frontend = req.Frontend d.settings.Frontend = req.Frontend
d.settings.Shell = req.Shell d.settings.Shell = req.Shell
d.settings.Commands = req.Commands d.settings.Commands = req.Commands
err = d.store.Settings.Save(d.settings) err = d.store.Settings.Save(d.settings)
return errToStatus(err), err return errToStatus(err), err
}) })

View File

@ -1,7 +1,6 @@
package settings package settings
import ( import (
"io/ioutil"
"log" "log"
"os" "os"
@ -18,7 +17,13 @@ func init() {
} }
defer yamlFile.Close() defer yamlFile.Close()
yamlData, err := ioutil.ReadAll(yamlFile) stat, err := yamlFile.Stat()
if err != nil {
log.Fatalf("Error getting file information: %v", err)
}
yamlData := make([]byte, stat.Size())
_, err = yamlFile.Read(yamlData)
if err != nil { if err != nil {
log.Fatalf("Error reading YAML data: %v", err) log.Fatalf("Error reading YAML data: %v", err)
} }
@ -39,7 +44,7 @@ func setDefaults() {
IndexingInterval: 5, IndexingInterval: 5,
Port: 8080, Port: 8080,
NumImageProcessors: 1, NumImageProcessors: 1,
BaseURL: "/files", BaseURL: "",
}, },
Auth: Auth{ Auth: Auth{
Method: "password", Method: "password",

View File

@ -1,8 +1,6 @@
package bolt package bolt
import ( import (
"fmt"
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/gtsteffaniak/filebrowser/auth" "github.com/gtsteffaniak/filebrowser/auth"
"github.com/gtsteffaniak/filebrowser/errors" "github.com/gtsteffaniak/filebrowser/errors"
@ -26,8 +24,6 @@ func (s authBackend) Get(t string) (auth.Auther, error) {
default: default:
return nil, errors.ErrInvalidAuthMethod return nil, errors.ErrInvalidAuthMethod
} }
fmt.Println("auth.go", t)
return auther, get(s.db, "auther", auther) return auther, get(s.db, "auther", auther)
} }