mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
feat: 添加文件驱动和本地驱动实现,支持文件操作功能
This commit is contained in:
38
pkg/filedriver/base_driver.go
Normal file
38
pkg/filedriver/base_driver.go
Normal file
@ -0,0 +1,38 @@
|
||||
package filedriver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/LiteyukiStudio/spage/pkg/constants"
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
type FileDriver interface {
|
||||
Save(ctx *app.RequestContext, path string, r io.Reader) error
|
||||
Open(ctx *app.RequestContext, path string) (io.ReadCloser, error)
|
||||
Delete(ctx *app.RequestContext, path string) error
|
||||
Stat(ctx *app.RequestContext, path string) (os.FileInfo, error)
|
||||
Get(ctx *app.RequestContext, path string)
|
||||
ListDir(ctx *app.RequestContext, path string) ([]os.FileInfo, error)
|
||||
}
|
||||
|
||||
type DriverConfig struct {
|
||||
Type string `mapstructure:"file.driver.type"`
|
||||
BasePath string `mapstructure:"file.driver.base_path"`
|
||||
WebDavUrl string `mapstructure:"file.driver.webdav.url"`
|
||||
WebDavUser string `mapstructure:"file.driver.webdav.user"`
|
||||
WebDavPassword string `mapstructure:"file.driver.webdav.password"`
|
||||
WebDavPolicy string `mapstructure:"file.driver.webdav.policy"` // proxy|redirect
|
||||
}
|
||||
|
||||
func GetFileDriver(driverConfig *DriverConfig) (FileDriver, error) {
|
||||
switch driverConfig.Type {
|
||||
case constants.FileDriverLocal:
|
||||
return NewLocalDriver(driverConfig), nil
|
||||
case constants.FileDriverWebdav:
|
||||
return NewWebDAVClientDriver(driverConfig), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported file driver type: %s", driverConfig.Type)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user