mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-10 17:52:44 +08:00
feat: (WIP) migrate storage configuration to user-specific models and remove deprecated storage loading
This commit is contained in:
@@ -49,8 +49,13 @@ func (a *Alist) getToken() error {
|
||||
}
|
||||
|
||||
func (a *Alist) refreshToken(cfg config.AlistConfig) {
|
||||
tokenExp := cfg.TokenExp
|
||||
if tokenExp <= 0 {
|
||||
logger.L.Warn("Invalid token expiration time, using default value")
|
||||
tokenExp = 3600
|
||||
}
|
||||
for {
|
||||
time.Sleep(time.Duration(cfg.TokenExp) * time.Second)
|
||||
time.Sleep(time.Duration(tokenExp) * time.Second)
|
||||
if err := a.getToken(); err != nil {
|
||||
logger.L.Errorf("Failed to refresh jwt token: %v", err)
|
||||
continue
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/krau/SaveAny-Bot/dao"
|
||||
"github.com/krau/SaveAny-Bot/storage/alist"
|
||||
"github.com/krau/SaveAny-Bot/storage/local"
|
||||
"github.com/krau/SaveAny-Bot/storage/webdav"
|
||||
@@ -24,24 +23,6 @@ var (
|
||||
|
||||
var Storages = make(map[uint]Storage)
|
||||
|
||||
// LoadExistingStorages loads existing storages from the database, and initializes them
|
||||
//
|
||||
// Should only be called at startup
|
||||
func LoadExistingStorages() error {
|
||||
storageModels, err := dao.GetActiveStorages()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, storageModel := range storageModels {
|
||||
storage, err := NewStorage(storageModel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
Storages[storageModel.ID] = storage
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get storage from model, if it exists, otherwise create and init a new storage
|
||||
func GetStorageFromModel(model types.StorageModel) (Storage, error) {
|
||||
if model.ID == 0 {
|
||||
|
||||
Reference in New Issue
Block a user