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 webdav
import (
"context"
"encoding/json"
"fmt"
"os"
"path"
@@ -15,18 +14,21 @@ import (
)
type Webdav struct {
config config.WebdavConfig
config config.WebdavStorageConfig
client *gowebdav.Client
}
var ConfigurableItems = []string{"url", "username", "password", "base_path"}
func (w *Webdav) Init(model types.StorageModel) error {
var webdavConfig config.WebdavConfig
if err := json.Unmarshal([]byte(model.Config), &webdavConfig); err != nil {
return fmt.Errorf("failed to unmarshal webdav config: %w", err)
func (w *Webdav) Init(cfg config.StorageConfig) error {
webdavConfig, ok := cfg.(*config.WebdavStorageConfig)
if !ok {
return fmt.Errorf("failed to cast webdav config")
}
w.config = webdavConfig
if err := webdavConfig.Validate(); err != nil {
return err
}
w.config = *webdavConfig
client := gowebdav.NewClient(webdavConfig.URL, webdavConfig.Username, webdavConfig.Password)
if err := client.Connect(); err != nil {
return fmt.Errorf("failed to connect to webdav server: %w", err)
@@ -40,6 +42,10 @@ func (w *Webdav) Type() types.StorageType {
return types.StorageTypeWebdav
}
func (w *Webdav) Name() string {
return w.config.Name
}
func (w *Webdav) Save(ctx context.Context, filePath, storagePath string) error {
if err := w.client.MkdirAll(path.Dir(storagePath), os.ModePerm); err != nil {
logger.L.Errorf("Failed to create directory %s: %v", path.Dir(storagePath), err)