mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-08-07 13:33:22 +08:00
feat!: (WIP) decouple storage, users, and configuration files to support multiple users
This commit is contained in:
@@ -2,22 +2,35 @@ package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/duke-git/lancet/v2/fileutil"
|
||||
"github.com/krau/SaveAny-Bot/config"
|
||||
"github.com/krau/SaveAny-Bot/logger"
|
||||
"github.com/krau/SaveAny-Bot/types"
|
||||
)
|
||||
|
||||
type Local struct{}
|
||||
type Local struct {
|
||||
config config.LocalConfig
|
||||
}
|
||||
|
||||
func (l *Local) Init() {
|
||||
err := os.MkdirAll(config.Cfg.Storage.Local.BasePath, os.ModePerm)
|
||||
if err != nil {
|
||||
logger.L.Fatalf("Failed to create local storage directory: %s", err)
|
||||
os.Exit(1)
|
||||
func (l *Local) Init(model types.StorageModel) error {
|
||||
var localConfig config.LocalConfig
|
||||
if err := json.Unmarshal([]byte(model.Config), &localConfig); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal local config: %w", err)
|
||||
}
|
||||
l.config = localConfig
|
||||
err := os.MkdirAll(localConfig.BasePath, os.ModePerm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create local storage directory: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *Local) Type() types.StorageType {
|
||||
return types.StorageTypeLocal
|
||||
}
|
||||
|
||||
func (l *Local) Save(ctx context.Context, filePath, storagePath string) error {
|
||||
@@ -30,3 +43,7 @@ func (l *Local) Save(ctx context.Context, filePath, storagePath string) error {
|
||||
}
|
||||
return fileutil.CopyFile(filePath, storagePath)
|
||||
}
|
||||
|
||||
func (l *Local) JoinStoragePath(task types.Task) string {
|
||||
return filepath.Join(l.config.BasePath, task.StoragePath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user