webdav

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeySessionId     = "sessionId"
	KeyContentLength = "contentLength"
	KeyUserId        = "userId"
)
View Source
const CacheExpiredMinute = 60

CacheExpiredMinute 缓存过期分钟

View Source
const DefaultChunkSize = 10 * 1024 * 1024

DefaultChunkSize 默认上传的文件块大小,10MB

View Source
const FileDownloadUrlExpiredSeconds = 14400

FileDownloadUrlExpiredSeconds 文件下载URL过期时间

View Source
const FileUploadExpiredMinute = 1440 // 24小时

FileUploadExpiredMinute 文件上传数据流过期时间

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	*User
	Auth      bool
	NoSniff   bool
	Cors      CorsCfg
	Users     map[string]*User
	LogFormat string
}

Config is the configuration of a WebDAV instance.

func (*Config) ServeHTTP

func (c *Config) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP determines if the request is for this plugins, and if all prerequisites are met.

type CorsCfg

type CorsCfg struct {
	Enabled        bool
	Credentials    bool
	AllowedHeaders []string
	AllowedHosts   []string
	AllowedMethods []string
	ExposedHeaders []string
}

CorsCfg is the CORS config.

type FileDownloadStream

type FileDownloadStream struct {
	// contains filtered or unexported fields
}

type FileUploadStream

type FileUploadStream struct {
	// contains filtered or unexported fields
}

type NoSniffFileInfo

type NoSniffFileInfo struct {
	os.FileInfo
}

NoSniffFileInfo wraps any generic FileInfo interface and bypasses mime type sniffing.

func (NoSniffFileInfo) ContentType

func (w NoSniffFileInfo) ContentType(ctx context.Context) (contentType string, err error)

type PanClientProxy

type PanClientProxy struct {
	PanUser            *config.PanUser
	PanDriveId         string
	PanTransferUrlType int
	// contains filtered or unexported fields
}

func (*PanClientProxy) DownloadFilePart

func (p *PanClientProxy) DownloadFilePart(sessionId, fileId string, offset int64, buffer []byte) (int, error)

DownloadFilePart 下载文件指定数据片段

func (*PanClientProxy) FileInfoByPath

func (p *PanClientProxy) FileInfoByPath(pathStr string) (fileInfo *aliyunpan.FileEntity, error *apierror.ApiError)

FileInfoByPath 通过文件路径获取网盘文件信息

func (*PanClientProxy) FileListGetAll

func (p *PanClientProxy) FileListGetAll(pathStr string) (aliyunpan.FileList, *apierror.ApiError)

FileListGetAll 获取文件路径下的所有子文件列表

func (*PanClientProxy) Mkdir

func (p *PanClientProxy) Mkdir(pathStr string, perm os.FileMode) error

Mkdir 创建目录

func (*PanClientProxy) Move

func (p *PanClientProxy) Move(oldpath, newpath string) error

Move 移动文件

func (*PanClientProxy) RemoveAll

func (p *PanClientProxy) RemoveAll(pathStr string) error

RemoveAll 删除文件

func (*PanClientProxy) Rename

func (p *PanClientProxy) Rename(oldpath, newpath string) error

Rename 重命名文件

func (*PanClientProxy) UploadFileCache

func (p *PanClientProxy) UploadFileCache(userId, pathStr string) (*FileUploadStream, error)

func (*PanClientProxy) UploadFilePart

func (p *PanClientProxy) UploadFilePart(userId, pathStr string, offset int64, buffer []byte) (int, error)

UploadFilePart 上传文件数据块

func (*PanClientProxy) UploadFilePrepare

func (p *PanClientProxy) UploadFilePrepare(userId, pathStr string, fileSize int64, chunkSize int64) (*FileUploadStream, error)

UploadFilePrepare 创建文件上传

type Rule

type Rule struct {
	Regex  bool
	Allow  bool
	Modify bool
	Path   string
	Regexp *regexp.Regexp
}

Rule is a dissalow/allow rule.

type User

type User struct {
	Username string
	Password string
	Scope    string
	Modify   bool    // 用户是否具备修改权限
	Rules    []*Rule // 根据访问路径进行精细化权限控制
	Handler  *webdav.Handler
}

User contains the settings of each user.

func (User) Allowed

func (u User) Allowed(url string, noModification bool) bool

Allowed checks if the user has permission to access a directory/file

type WebDavDir

type WebDavDir struct {
	webdav.Dir
	NoSniff bool
	// contains filtered or unexported fields
}

文件系统

func (WebDavDir) Mkdir

func (d WebDavDir) Mkdir(ctx context.Context, name string, perm os.FileMode) error

func (WebDavDir) OpenFile

func (d WebDavDir) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error)

func (WebDavDir) RemoveAll

func (d WebDavDir) RemoveAll(ctx context.Context, name string) error

func (WebDavDir) Rename

func (d WebDavDir) Rename(ctx context.Context, oldName, newName string) error

func (WebDavDir) Stat

func (d WebDavDir) Stat(ctx context.Context, name string) (os.FileInfo, error)

type WebDavFile

type WebDavFile struct {
	webdav.File
	// contains filtered or unexported fields
}

WebDavFile 文件实例

func (*WebDavFile) Close

func (f *WebDavFile) Close() error

func (*WebDavFile) Read

func (f *WebDavFile) Read(p []byte) (int, error)

func (*WebDavFile) Readdir

func (f *WebDavFile) Readdir(count int) (fis []os.FileInfo, err error)

Readdir 获取文件目录

func (*WebDavFile) Seek

func (f *WebDavFile) Seek(offset int64, whence int) (int64, error)

func (*WebDavFile) Stat

func (f *WebDavFile) Stat() (os.FileInfo, error)

func (*WebDavFile) Write

func (f *WebDavFile) Write(p []byte) (int, error)

type WebDavFileInfo

type WebDavFileInfo struct {
	os.FileInfo
	// contains filtered or unexported fields
}

WebDavFileInfo 文件信息

func NewWebDavFileInfo

func NewWebDavFileInfo(fileItem *aliyunpan.FileEntity) WebDavFileInfo

func (*WebDavFileInfo) ContentType

func (f *WebDavFileInfo) ContentType(ctx context.Context) (contentType string, err error)

func (*WebDavFileInfo) IsDir

func (f *WebDavFileInfo) IsDir() bool

func (*WebDavFileInfo) ModTime

func (f *WebDavFileInfo) ModTime() time.Time

func (*WebDavFileInfo) Mode

func (f *WebDavFileInfo) Mode() os.FileMode

func (*WebDavFileInfo) Name

func (f *WebDavFileInfo) Name() string

func (*WebDavFileInfo) Size

func (f *WebDavFileInfo) Size() int64

func (*WebDavFileInfo) Sys

func (f *WebDavFileInfo) Sys() interface{}

type WebdavConfig

type WebdavConfig struct {
	// 指定Webdav使用哪个账号的云盘资源
	PanUserId       string          `json:"panUserId"`
	PanDriveId      string          `json:"panDriveId"`
	PanUser         *config.PanUser `json:"-"`
	UploadChunkSize int             `json:"uploadChunkSize"` // 上传文件分片数据块大小,该数值不能太小,建议大于等于512KB
	TransferUrlType int             `json:"transferUrlType"` // 上传/下载URL类别,1-默认,2-阿里云ECS

	Address string       `json:"address"`
	Port    int          `json:"port"`
	Prefix  string       `json:"prefix"`
	Users   []WebdavUser `json:"users"`
}

func (*WebdavConfig) StartServer

func (w *WebdavConfig) StartServer()

type WebdavUser

type WebdavUser struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Scope    string `json:"scope"`
	Mode     string `json:"mode"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL