refactor: modularize downloader architecture

This commit is contained in:
OpenClaw Agent
2026-09-16 06:41:45 +08:00
parent 6c585ff835
commit 285064d144
11 changed files with 766 additions and 558 deletions
+41
View File
@@ -0,0 +1,41 @@
package main
import (
"os"
"time"
"github.com/studio-b12/gowebdav"
)
type WebDAVStorage struct{ client *gowebdav.Client }
func NewWebDAVStorage(cfg Config) *WebDAVStorage {
c := gowebdav.NewClient(cfg.WebDAVURL, cfg.WebDAVUser, cfg.WebDAVPass)
c.SetTimeout(10 * time.Minute)
return &WebDAVStorage{client: c}
}
func (s *WebDAVStorage) MkdirAll(remoteDir string) error { return s.client.MkdirAll(remoteDir, 0755) }
func (s *WebDAVStorage) ExistsSameSize(remotePath string, size int64) (bool, error) {
fi, err := s.client.Stat(remotePath)
if err != nil {
return false, err
}
return fi.Size() == size, nil
}
func (s *WebDAVStorage) Upload(localPath, remotePath string) error {
f, err := os.Open(localPath)
if err != nil {
return err
}
defer f.Close()
return s.client.WriteStream(remotePath, f, 0644)
}
func (s *WebDAVStorage) Remove(remotePath string) error { return s.client.Remove(remotePath) }
func (s *WebDAVStorage) Stat(remotePath string) error {
_, err := s.client.Stat(remotePath)
return err
}