feat!: (WIP) switched back to using config files config storages because the conversation handling is shit

This commit is contained in:
krau
2025-02-19 11:05:30 +08:00
parent 80696c9661
commit 692e970772
24 changed files with 584 additions and 645 deletions

View File

@@ -2,7 +2,6 @@ package local
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
@@ -13,19 +12,22 @@ import (
)
type Local struct {
config config.LocalConfig
config config.LocalStorageConfig
}
var ConfigurableItems = []string{
"base_path",
}
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)
func (l *Local) Init(cfg config.StorageConfig) error {
localConfig, ok := cfg.(*config.LocalStorageConfig)
if !ok {
return fmt.Errorf("failed to cast local config")
}
l.config = localConfig
if err := localConfig.Validate(); err != nil {
return 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)
@@ -37,6 +39,10 @@ func (l *Local) Type() types.StorageType {
return types.StorageTypeLocal
}
func (l *Local) Name() string {
return l.config.Name
}
func (l *Local) Save(ctx context.Context, filePath, storagePath string) error {
absPath, err := filepath.Abs(storagePath)
if err != nil {