forked from upstream/filebrowser
+10








3c02eedca6
Co-authored-by: Kevin B. <kurami32_kbm@proton.me> Co-authored-by: Gabriel Górski <me@glaeqen.eu> Co-authored-by: Joel Godfrey <82655889+BaccanoMob@users.noreply.github.com> Co-authored-by: Shane Chiu <71911511+pwn2ooown@users.noreply.github.com> Co-authored-by: carloda <35763669+carloda@users.noreply.github.com> Co-authored-by: Taufik Hidayat <taufikdev88@gmail.com> Co-authored-by: Stephan Paternotte <Stephan-P@users.noreply.github.com> Co-authored-by: SIDDHU SINGH <siddhu3116@gmail.com> Co-authored-by: Gaurav Kalal <117557391+Gorupa@users.noreply.github.com> Co-authored-by: Nebula <40148908+nebula-it@users.noreply.github.com> Co-authored-by: Juan Soler <juansoler@gmail.com> Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com> Co-authored-by: Anatolii Prylutskyi <anpryl@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Graham Steffaniak <graham@debian-lake.ghome.net> Co-authored-by: Neil <kylelzzz02@icloud.com> Co-authored-by: Graham <info@quantumx-apps.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package settings
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gtsteffaniak/filebrowser/backend/internal/database/users"
|
|
)
|
|
|
|
// InitializeUserResolvers sets up the global resolvers and config providers in the users package
|
|
// This should be called once during application initialization
|
|
func InitializeUserResolvers() {
|
|
// Set up the source name resolver
|
|
users.SetSourceNameResolver(func(sourceName string) (string, error) {
|
|
source, ok := Config.Server.NameToSource[sourceName]
|
|
if !ok {
|
|
return "", fmt.Errorf("source name not found: %s", sourceName)
|
|
}
|
|
return source.Path, nil
|
|
})
|
|
|
|
// Set up the source config provider
|
|
users.SetSourceConfig(&users.SourceConfigProvider{
|
|
GetSourceByPath: func(path string) (users.SourceInfo, bool) {
|
|
source, ok := Config.Server.SourceMap[path]
|
|
if !ok {
|
|
return users.SourceInfo{}, false
|
|
}
|
|
return users.SourceInfo{
|
|
Path: source.Path,
|
|
Name: source.Name,
|
|
DefaultUserScope: source.Config.DefaultUserScope,
|
|
}, true
|
|
},
|
|
GetSourceByName: func(name string) (users.SourceInfo, bool) {
|
|
source, ok := Config.Server.NameToSource[name]
|
|
if !ok {
|
|
return users.SourceInfo{}, false
|
|
}
|
|
return users.SourceInfo{
|
|
Path: source.Path,
|
|
Name: source.Name,
|
|
DefaultUserScope: source.Config.DefaultUserScope,
|
|
}, true
|
|
},
|
|
GetAllSources: func() []users.SourceInfo {
|
|
sources := make([]users.SourceInfo, 0, len(Config.Server.Sources))
|
|
for _, source := range Config.Server.Sources {
|
|
sources = append(sources, users.SourceInfo{
|
|
Path: source.Path,
|
|
Name: source.Name,
|
|
DefaultUserScope: source.Config.DefaultUserScope,
|
|
})
|
|
}
|
|
return sources
|
|
},
|
|
GetDefaultScopes: func() []users.BackendScope {
|
|
return Config.UserDefaults.DefaultScopes
|
|
},
|
|
})
|
|
}
|