feat: (WIP) migrate storage configuration to user-specific models and remove deprecated storage loading

This commit is contained in:
krau
2025-02-18 19:45:06 +08:00
parent 968547b005
commit dfde65c28e
8 changed files with 193 additions and 36 deletions

View File

@@ -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

View File

@@ -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 {