cloud

package
v0.0.0-...-175ccbd Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: AGPL-3.0 Imports: 29 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupported             = errors.New("not supported yet")         // ErrUnsupported 描述了尚未支持的操作
	ErrCloudObjectNotFound     = errors.New("cloud object not found")    // ErrCloudObjectNotFound 描述了云端存储服务中的对象不存在的错误
	ErrCloudAuthFailed         = errors.New("cloud account auth failed") // ErrCloudAuthFailed 描述了云端存储服务鉴权失败的错误
	ErrCloudServiceUnavailable = errors.New("cloud service unavailable") // ErrCloudServiceUnavailable 描述了云端存储服务不可用的错误
	ErrSystemTimeIncorrect     = errors.New("system time incorrect")     // ErrSystemTimeIncorrect 描述了系统时间不正确的错误
	ErrDeprecatedVersion       = errors.New("deprecated version")        // ErrDeprecatedVersion 描述了版本过低的错误
	ErrCloudCheckFailed        = errors.New("cloud check failed")        // ErrCloudCheckFailed 描述了云端存储服务检查失败的错误
	ErrCloudIndexChanged       = errors.New("cloud index changed")       // ErrCloudIndexChanged 描述了云端快照已变更的错误
)

Functions

func IsValidCloudDirName

func IsValidCloudDirName(cloudDirName string) bool

Types

type BaseCloud

type BaseCloud struct {
	*Conf
	Cloud
}

BaseCloud 描述了云端存储服务的基础实现。

func (*BaseCloud) AddTraffic

func (baseCloud *BaseCloud) AddTraffic(*Traffic)

func (*BaseCloud) CreateRepo

func (baseCloud *BaseCloud) CreateRepo(name string) (err error)

func (*BaseCloud) DownloadObject

func (baseCloud *BaseCloud) DownloadObject(filePath string) (data []byte, err error)

func (*BaseCloud) GetAvailableSize

func (baseCloud *BaseCloud) GetAvailableSize() int64

func (*BaseCloud) GetChunks

func (baseCloud *BaseCloud) GetChunks(checkChunkIDs []string) (chunkIDs []string, err error)

func (*BaseCloud) GetConf

func (baseCloud *BaseCloud) GetConf() *Conf

func (*BaseCloud) GetIndex

func (baseCloud *BaseCloud) GetIndex(id string) (index *entity.Index, err error)

func (*BaseCloud) GetIndexes

func (baseCloud *BaseCloud) GetIndexes(page int) (indexes []*entity.Index, pageCount, totalCount int, err error)

func (*BaseCloud) GetRefsFiles

func (baseCloud *BaseCloud) GetRefsFiles() (fileIDs []string, err error)

func (*BaseCloud) GetRepos

func (baseCloud *BaseCloud) GetRepos() (repos []*Repo, size int64, err error)

func (*BaseCloud) GetStat

func (baseCloud *BaseCloud) GetStat() (stat *Stat, err error)

func (*BaseCloud) GetTags

func (baseCloud *BaseCloud) GetTags() (tags []*Ref, err error)

func (*BaseCloud) ListObjects

func (baseCloud *BaseCloud) ListObjects(pathPrefix string) (objInfos map[string]*entity.ObjectInfo, err error)

func (*BaseCloud) RemoveObject

func (baseCloud *BaseCloud) RemoveObject(key string) (err error)

func (*BaseCloud) RemoveRepo

func (baseCloud *BaseCloud) RemoveRepo(name string) (err error)

func (*BaseCloud) UploadObject

func (baseCloud *BaseCloud) UploadObject(filePath string, overwrite bool) (err error)

type Cloud

type Cloud interface {

	// CreateRepo 用于创建名称为 name 的云端仓库。
	CreateRepo(name string) (err error)

	// RemoveRepo 用于删除云端仓库。
	RemoveRepo(name string) (err error)

	// GetRepos 用于获取云端仓库列表 repos,size 为仓库总大小字节数。
	GetRepos() (repos []*Repo, size int64, err error)

	// UploadObject 用于上传对象,overwrite 参数用于指示是否覆盖已有对象。
	UploadObject(filePath string, overwrite bool) (length int64, err error)

	// DownloadObject 用于下载对象数据 data。
	DownloadObject(filePath string) (data []byte, err error)

	// RemoveObject 用于删除对象。
	RemoveObject(filePath string) (err error)

	// GetTags 用于获取快照标记列表。
	GetTags() (tags []*Ref, err error)

	// GetIndexes 用于获取索引列表。
	GetIndexes(page int) (indexes []*entity.Index, pageCount, totalCount int, err error)

	// GetRefsFiles 用于获取所有引用索引中的文件 ID 列表 fileIDs。
	GetRefsFiles() (fileIDs []string, refs []*Ref, err error)

	// GetChunks 用于获取 checkChunkIDs 中不存在的分块 ID 列表 chunkIDs。
	GetChunks(checkChunkIDs []string) (chunkIDs []string, err error)

	// GetStat 用于获取统计信息 stat。
	GetStat() (stat *Stat, err error)

	// GetConf 用于获取配置信息。
	GetConf() *Conf

	// GetAvailableSize 用于获取云端存储可用空间字节数。
	GetAvailableSize() (size int64)

	// AddTraffic 用于统计流量。
	AddTraffic(traffic *Traffic)

	// ListObjects 用于列出指定前缀的对象。
	ListObjects(pathPrefix string) (objInfos map[string]*entity.ObjectInfo, err error)

	// GetIndex 用于获取索引。
	GetIndex(id string) (index *entity.Index, err error)
}

Cloud 描述了云端存储服务,接入云端存储服务时需要实现该接口。

type Conf

type Conf struct {
	Dir      string                 // 存储目录,第三方存储不使用 Dir 区别多租户
	UserID   string                 // 用户 ID,没有的话请传入一个定值比如 "0"
	RepoPath string                 // 本地仓库的绝对路径,如:F:\\SiYuan\\repo\\
	Endpoint string                 // 服务端点
	Extras   map[string]interface{} // 一些可能需要的附加信息

	// S3 对象存储协议所需配置
	S3 *ConfS3

	// WebDAV 协议所需配置
	WebDAV *ConfWebDAV

	// 以下值非官方存储服务不必传入
	Token         string // 云端接口鉴权令牌
	AvailableSize int64  // 云端存储可用空间字节数
	Server        string // 云端接口端点
}

Conf 用于描述云端存储服务配置信息。

type ConfS3

type ConfS3 struct {
	Endpoint      string // 服务端点
	AccessKey     string // Access Key
	SecretKey     string // Secret Key
	Region        string // 存储区域
	Bucket        string // 存储空间
	PathStyle     bool   // 是否使用路径风格寻址
	SkipTlsVerify bool   //  是否跳过 TLS 验证
	Timeout       int    // 超时时间,单位:秒
}

ConfS3 用于描述 S3 对象存储协议所需配置。

type ConfWebDAV

type ConfWebDAV struct {
	Endpoint      string // 服务端点
	Username      string // 用户名
	Password      string // 密码
	SkipTlsVerify bool   // 是否跳过 TLS 验证
	Timeout       int    // 超时时间,单位:秒
}

ConfWebDAV 用于描述 WebDAV 协议所需配置。

type Index

type Index struct {
	ID         string `json:"id"`
	SystemID   string `json:"systemID"`
	SystemName string `json:"systemName"`
	SystemOS   string `json:"systemOS"`
}

Index 描述了云端索引。

type Indexes

type Indexes struct {
	Indexes []*Index `json:"indexes"`
}

Indexes 描述了云端索引列表。

type Ref

type Ref struct {
	Name    string `json:"name"`    // 引用文件名称,比如 latest、tag1
	ID      string `json:"id"`      // 引用 ID
	Updated string `json:"updated"` // 最近更新时间
}

Ref 描述了快照引用。

type Repo

type Repo struct {
	Name    string `json:"name"`
	Size    int64  `json:"size"`
	Updated string `json:"updated"`
}

Repo 描述了云端仓库。

type S3

type S3 struct {
	*BaseCloud
	HTTPClient *http.Client
}

S3 描述了 S3 协议兼容的对象存储服务实现。

func NewS3

func NewS3(baseCloud *BaseCloud, httpClient *http.Client) *S3

func (*S3) DownloadObject

func (s3 *S3) DownloadObject(filePath string) (data []byte, err error)

func (*S3) GetChunks

func (s3 *S3) GetChunks(checkChunkIDs []string) (chunkIDs []string, err error)

func (*S3) GetIndex

func (s3 *S3) GetIndex(id string) (index *entity.Index, err error)

func (*S3) GetIndexes

func (s3 *S3) GetIndexes(page int) (ret []*entity.Index, pageCount, totalCount int, err error)

func (*S3) GetRefsFiles

func (s3 *S3) GetRefsFiles() (fileIDs []string, refs []*Ref, err error)

func (*S3) GetRepos

func (s3 *S3) GetRepos() (repos []*Repo, size int64, err error)

func (*S3) GetTags

func (s3 *S3) GetTags() (tags []*Ref, err error)

func (*S3) ListObjects

func (s3 *S3) ListObjects(pathPrefix string) (ret map[string]*entity.ObjectInfo, err error)

func (*S3) RemoveObject

func (s3 *S3) RemoveObject(key string) (err error)

func (*S3) UploadObject

func (s3 *S3) UploadObject(filePath string, overwrite bool) (length int64, err error)

type SiYuan

type SiYuan struct {
	*BaseCloud
}

SiYuan 描述了思源笔记官方云端存储服务实现。

func NewSiYuan

func NewSiYuan(baseCloud *BaseCloud) *SiYuan

func (*SiYuan) AddTraffic

func (siyuan *SiYuan) AddTraffic(traffic *Traffic)

func (*SiYuan) CreateRepo

func (siyuan *SiYuan) CreateRepo(name string) (err error)

func (*SiYuan) DownloadObject

func (siyuan *SiYuan) DownloadObject(filePath string) (ret []byte, err error)

func (*SiYuan) GetChunks

func (siyuan *SiYuan) GetChunks(excludeChunkIDs []string) (chunkIDs []string, err error)

func (*SiYuan) GetIndexes

func (siyuan *SiYuan) GetIndexes(page int) (indexes []*entity.Index, pageCount, totalCount int, err error)

func (*SiYuan) GetRefsFiles

func (siyuan *SiYuan) GetRefsFiles() (fileIDs []string, refs []*Ref, err error)

func (*SiYuan) GetRepos

func (siyuan *SiYuan) GetRepos() (repos []*Repo, size int64, err error)

func (*SiYuan) GetStat

func (siyuan *SiYuan) GetStat() (stat *Stat, err error)

func (*SiYuan) GetTags

func (siyuan *SiYuan) GetTags() (tags []*Ref, err error)

func (*SiYuan) RemoveObject

func (siyuan *SiYuan) RemoveObject(filePath string) (err error)

func (*SiYuan) RemoveRepo

func (siyuan *SiYuan) RemoveRepo(name string) (err error)

func (*SiYuan) UploadObject

func (siyuan *SiYuan) UploadObject(filePath string, overwrite bool) (length int64, err error)

type Stat

type Stat struct {
	Sync      *StatSync   `json:"sync"`      // 同步统计
	Backup    *StatBackup `json:"backup"`    // 备份统计
	AssetSize int64       `json:"assetSize"` // 资源文件大小字节数
	RepoCount int         `json:"repoCount"` // 仓库数量
}

Stat 描述了统计信息。

type StatBackup

type StatBackup struct {
	Count     int    `json:"count"`     // 已标记的快照数量
	Size      int64  `json:"size"`      // 总大小字节数
	FileCount int    `json:"fileCount"` // 总文件数
	Updated   string `json:"updated"`   // 最近更新时间
}

StatBackup 描述了备份统计信息。

type StatSync

type StatSync struct {
	Size      int64  `json:"size"`      // 总大小字节数
	FileCount int    `json:"fileCount"` // 总文件数
	Updated   string `json:"updated"`   // 最近更新时间
}

StatSync 描述了同步统计信息。

type Traffic

type Traffic struct {
	UploadBytes   int64 // 上传字节数
	DownloadBytes int64 // 下载字节数
	APIGet        int   // API GET 请求次数
	APIPut        int   // API PUT 请求次数
}

Traffic 描述了流量信息。

type UploadToken

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

type WebDAV

type WebDAV struct {
	*BaseCloud
	Client *gowebdav.Client
	// contains filtered or unexported fields
}

WebDAV 描述了 WebDAV 云端存储服务实现。

func NewWebDAV

func NewWebDAV(baseCloud *BaseCloud, client *gowebdav.Client) (ret *WebDAV)

func (*WebDAV) DownloadObject

func (webdav *WebDAV) DownloadObject(filePath string) (data []byte, err error)

func (*WebDAV) GetChunks

func (webdav *WebDAV) GetChunks(checkChunkIDs []string) (chunkIDs []string, err error)

func (*WebDAV) GetIndex

func (webdav *WebDAV) GetIndex(id string) (index *entity.Index, err error)

func (*WebDAV) GetIndexes

func (webdav *WebDAV) GetIndexes(page int) (ret []*entity.Index, pageCount, totalCount int, err error)

func (*WebDAV) GetRefsFiles

func (webdav *WebDAV) GetRefsFiles() (fileIDs []string, refs []*Ref, err error)

func (*WebDAV) GetRepos

func (webdav *WebDAV) GetRepos() (repos []*Repo, size int64, err error)

func (*WebDAV) GetTags

func (webdav *WebDAV) GetTags() (tags []*Ref, err error)

func (*WebDAV) ListObjects

func (webdav *WebDAV) ListObjects(pathPrefix string) (ret map[string]*entity.ObjectInfo, err error)

func (*WebDAV) RemoveObject

func (webdav *WebDAV) RemoveObject(filePath string) (err error)

func (*WebDAV) UploadObject

func (webdav *WebDAV) UploadObject(filePath string, overwrite bool) (length int64, err error)

Jump to

Keyboard shortcuts

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