mirror of https://github.com/stashapp/stash.git
Refresh package managers after setup (#4397)
* Refresh package managers after setup * Fix default plugins/scrapers paths
This commit is contained in:
parent
9bd36408ee
commit
6ee7e6112b
|
@ -3,6 +3,7 @@ package api
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
@ -26,6 +27,10 @@ func getPackageManager(typeArg PackageType) (*pkg.Manager, error) {
|
|||
return nil, ErrInvalidPackageType
|
||||
}
|
||||
|
||||
if pm == nil {
|
||||
return nil, fmt.Errorf("%s package manager not initialized", typeArg)
|
||||
}
|
||||
|
||||
return pm, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -21,7 +20,6 @@ import (
|
|||
"github.com/stashapp/stash/pkg/job"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models/paths"
|
||||
"github.com/stashapp/stash/pkg/pkg"
|
||||
"github.com/stashapp/stash/pkg/plugin"
|
||||
"github.com/stashapp/stash/pkg/scene"
|
||||
"github.com/stashapp/stash/pkg/scraper"
|
||||
|
@ -102,9 +100,6 @@ func Initialize(cfg *config.Config, l *log.Logger) (*Manager, error) {
|
|||
scanSubs: &subscriptionManager{},
|
||||
}
|
||||
|
||||
mgr.RefreshPluginSourceManager()
|
||||
mgr.RefreshScraperSourceManager()
|
||||
|
||||
if !cfg.IsNewSystem() {
|
||||
logger.Infof("using config file: %s", cfg.GetConfigFile())
|
||||
|
||||
|
@ -135,25 +130,6 @@ func Initialize(cfg *config.Config, l *log.Logger) (*Manager, error) {
|
|||
return mgr, nil
|
||||
}
|
||||
|
||||
func initialisePackageManager(localPath string, srcPathGetter pkg.SourcePathGetter) *pkg.Manager {
|
||||
const timeout = 10 * time.Second
|
||||
httpClient := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
},
|
||||
Timeout: timeout,
|
||||
}
|
||||
|
||||
return &pkg.Manager{
|
||||
Local: &pkg.Store{
|
||||
BaseDir: localPath,
|
||||
ManifestFile: pkg.ManifestFile,
|
||||
},
|
||||
PackagePathGetter: srcPathGetter,
|
||||
Client: httpClient,
|
||||
}
|
||||
}
|
||||
|
||||
func formatDuration(t time.Duration) string {
|
||||
switch {
|
||||
case t >= time.Minute: // 1m23s or 2h45m12s
|
||||
|
@ -208,7 +184,11 @@ func (s *Manager) postInit(ctx context.Context) error {
|
|||
s.PluginCache.RegisterSessionStore(s.SessionStore)
|
||||
|
||||
s.RefreshPluginCache()
|
||||
s.RefreshPluginSourceManager()
|
||||
|
||||
s.RefreshScraperCache()
|
||||
s.RefreshScraperSourceManager()
|
||||
|
||||
s.RefreshStreamManager()
|
||||
s.RefreshDLNA()
|
||||
|
||||
|
|
|
@ -4,9 +4,11 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/internal/dlna"
|
||||
"github.com/stashapp/stash/internal/log"
|
||||
|
@ -145,12 +147,31 @@ func (s *Manager) RefreshDLNA() {
|
|||
}
|
||||
}
|
||||
|
||||
func createPackageManager(localPath string, srcPathGetter pkg.SourcePathGetter) *pkg.Manager {
|
||||
const timeout = 10 * time.Second
|
||||
httpClient := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
},
|
||||
Timeout: timeout,
|
||||
}
|
||||
|
||||
return &pkg.Manager{
|
||||
Local: &pkg.Store{
|
||||
BaseDir: localPath,
|
||||
ManifestFile: pkg.ManifestFile,
|
||||
},
|
||||
PackagePathGetter: srcPathGetter,
|
||||
Client: httpClient,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Manager) RefreshScraperSourceManager() {
|
||||
s.ScraperPackageManager = initialisePackageManager(s.Config.GetScrapersPath(), s.Config.GetScraperPackagePathGetter())
|
||||
s.ScraperPackageManager = createPackageManager(s.Config.GetScrapersPath(), s.Config.GetScraperPackagePathGetter())
|
||||
}
|
||||
|
||||
func (s *Manager) RefreshPluginSourceManager() {
|
||||
s.PluginPackageManager = initialisePackageManager(s.Config.GetPluginsPath(), s.Config.GetPluginPackagePathGetter())
|
||||
s.PluginPackageManager = createPackageManager(s.Config.GetPluginsPath(), s.Config.GetPluginPackagePathGetter())
|
||||
}
|
||||
|
||||
func setSetupDefaults(input *SetupInput) {
|
||||
|
@ -179,10 +200,6 @@ func (s *Manager) Setup(ctx context.Context, input SetupInput) error {
|
|||
setSetupDefaults(&input)
|
||||
cfg := s.Config
|
||||
|
||||
if err := cfg.SetInitialConfig(); err != nil {
|
||||
return fmt.Errorf("error setting initial configuration: %v", err)
|
||||
}
|
||||
|
||||
// create the config directory if it does not exist
|
||||
// don't do anything if config is already set in the environment
|
||||
if !config.FileEnvSet() {
|
||||
|
@ -207,6 +224,10 @@ func (s *Manager) Setup(ctx context.Context, input SetupInput) error {
|
|||
s.Config.SetConfigFile(configFile)
|
||||
}
|
||||
|
||||
if err := cfg.SetInitialConfig(); err != nil {
|
||||
return fmt.Errorf("error setting initial configuration: %v", err)
|
||||
}
|
||||
|
||||
// create the generated directory if it does not exist
|
||||
if !cfg.HasOverride(config.Generated) {
|
||||
if exists, _ := fsutil.DirExists(input.GeneratedLocation); !exists {
|
||||
|
|
Loading…
Reference in New Issue