onedrive

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SmallFileSize 单文件上传接口最大尺寸
	SmallFileSize uint64 = 4 * 1024 * 1024
	// ChunkSize 服务端中转分片上传分片大小
	ChunkSize uint64 = 10 * 1024 * 1024
	// ListRetry 列取请求重试次数
	ListRetry = 1
)

Variables

View Source
var (
	// ErrAuthEndpoint 无法解析授权端点地址
	ErrAuthEndpoint = errors.New("无法解析授权端点地址")
	// ErrInvalidRefreshToken 上传策略无有效的RefreshToken
	ErrInvalidRefreshToken = errors.New("上传策略无有效的RefreshToken")
	// ErrDeleteFile 无法删除文件
	ErrDeleteFile = errors.New("无法删除文件")
	// ErrClientCanceled 客户端取消操作
	ErrClientCanceled = errors.New("客户端取消操作")
)
View Source
var GlobalMutex = mutexMap{}

Functions

func NewDriver

func NewDriver(policy *model.Policy) (driver.Handler, error)

NewDriver 从存储策略初始化新的Driver实例

Types

type APIError

type APIError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

APIError 接口返回的错误内容

type BatchRequest

type BatchRequest struct {
	ID      string            `json:"id"`
	Method  string            `json:"method"`
	URL     string            `json:"url"`
	Body    interface{}       `json:"body,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
}

BatchRequest 批量操作单个请求

type BatchRequests

type BatchRequests struct {
	Requests []BatchRequest `json:"requests"`
}

BatchRequests 批量操作请求

type BatchResponse

type BatchResponse struct {
	ID     string `json:"id"`
	Status int    `json:"status"`
}

BatchResponse 批量操作单个响应

type BatchResponses

type BatchResponses struct {
	Responses []BatchResponse `json:"responses"`
}

BatchResponses 批量操作响应

type Client

type Client struct {
	Endpoints  *Endpoints
	Policy     *model.Policy
	Credential *Credential

	ClientID     string
	ClientSecret string
	Redirect     string

	Request           request.Client
	ClusterController cluster.Controller
}

Client OneDrive客户端

func NewClient

func NewClient(policy *model.Policy) (*Client, error)

NewClient 根据存储策略获取新的client

func (*Client) BatchDelete

func (client *Client) BatchDelete(ctx context.Context, dst []string) ([]string, error)

BatchDelete 并行删除给出的文件,返回删除失败的文件,及第一个遇到的错误。此方法将文件分为 20个一组,调用Delete并行删除 TODO 测试

func (*Client) CreateUploadSession

func (client *Client) CreateUploadSession(ctx context.Context, dst string, opts ...Option) (string, error)

CreateUploadSession 创建分片上传会话

func (*Client) Delete

func (client *Client) Delete(ctx context.Context, dst []string) ([]string, error)

Delete 并行删除文件,返回删除失败的文件,及第一个遇到的错误, 由于API限制,最多删除20个

func (*Client) DeleteUploadSession

func (client *Client) DeleteUploadSession(ctx context.Context, uploadURL string) error

DeleteUploadSession 删除上传会话

func (*Client) GetSiteIDByURL

func (client *Client) GetSiteIDByURL(ctx context.Context, siteUrl string) (string, error)

GetSiteIDByURL 通过 SharePoint 站点 URL 获取站点ID

func (*Client) GetThumbURL

func (client *Client) GetThumbURL(ctx context.Context, dst string, w, h uint) (string, error)

GetThumbURL 获取给定尺寸的缩略图URL

func (*Client) GetUploadSessionStatus

func (client *Client) GetUploadSessionStatus(ctx context.Context, uploadURL string) (*UploadSessionResponse, error)

GetUploadSessionStatus 查询上传会话状态

func (*Client) ListChildren

func (client *Client) ListChildren(ctx context.Context, path string) ([]FileInfo, error)

ListChildren 根据路径列取子对象

func (*Client) Meta

func (client *Client) Meta(ctx context.Context, id string, path string) (*FileInfo, error)

Meta 根据资源ID或文件路径获取文件元信息

func (*Client) MonitorUpload

func (client *Client) MonitorUpload(uploadURL, callbackKey, path string, size uint64, ttl int64)

MonitorUpload 监控客户端分片上传进度

func (*Client) OAuthURL

func (client *Client) OAuthURL(ctx context.Context, scope []string) string

OAuthURL 获取OAuth认证页面URL

func (*Client) ObtainToken

func (client *Client) ObtainToken(ctx context.Context, opts ...Option) (*Credential, error)

ObtainToken 通过code或refresh_token兑换token

func (*Client) SimpleUpload

func (client *Client) SimpleUpload(ctx context.Context, dst string, body io.Reader, size int64, opts ...Option) (*UploadResult, error)

SimpleUpload 上传小文件到dst

func (*Client) UpdateCredential

func (client *Client) UpdateCredential(ctx context.Context, isSlave bool) error

UpdateCredential 更新凭证,并检查有效期

func (*Client) Upload

func (client *Client) Upload(ctx context.Context, file fsctx.FileHeader) error

Upload 上传文件

func (*Client) UploadChunk

func (client *Client) UploadChunk(ctx context.Context, uploadURL string, content io.Reader, current *chunk.ChunkGroup) (*UploadSessionResponse, error)

UploadChunk 上传分片

type Credential

type Credential struct {
	TokenType    string `json:"token_type"`
	ExpiresIn    int64  `json:"expires_in"`
	Scope        string `json:"scope"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	UserID       string `json:"user_id"`
}

Credential 获取token时返回的凭证

type CredentialLock

type CredentialLock interface {
	Lock(uint)
	Unlock(uint)
}

CredentialLock 针对存储策略凭证的锁

type Driver

type Driver struct {
	Policy     *model.Policy
	Client     *Client
	HTTPClient request.Client
}

Driver OneDrive 适配器

func (Driver) CancelToken

func (handler Driver) CancelToken(ctx context.Context, uploadSession *serializer.UploadSession) error

取消上传凭证

func (Driver) Delete

func (handler Driver) Delete(ctx context.Context, files []string) ([]string, error)

Delete 删除一个或多个文件, 返回未删除的文件,及遇到的最后一个错误

func (Driver) Get

func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser, error)

Get 获取文件

func (Driver) List

func (handler Driver) List(ctx context.Context, base string, recursive bool) ([]response.Object, error)

List 列取项目

func (Driver) Put

func (handler Driver) Put(ctx context.Context, file fsctx.FileHeader) error

Put 将文件流保存到指定目录

func (Driver) Source

func (handler Driver) Source(
	ctx context.Context,
	path string,
	baseURL url.URL,
	ttl int64,
	isDownload bool,
	speed int,
) (string, error)

Source 获取外链URL

func (Driver) Thumb

func (handler Driver) Thumb(ctx context.Context, path string) (*response.ContentResponse, error)

Thumb 获取文件缩略图

func (Driver) Token

func (handler Driver) Token(ctx context.Context, ttl int64, uploadSession *serializer.UploadSession, file fsctx.FileHeader) (*serializer.UploadCredential, error)

Token 获取上传会话URL

type Endpoints

type Endpoints struct {
	OAuthURL       string // OAuth认证的基URL
	OAuthEndpoints *oauthEndpoint
	EndpointURL    string // 接口请求的基URL

	DriverResource string // 要使用的驱动器
	// contains filtered or unexported fields
}

Endpoints OneDrive客户端相关设置

type FileInfo

type FileInfo struct {
	Name            string          `json:"name"`
	Size            uint64          `json:"size"`
	Image           imageInfo       `json:"image"`
	ParentReference parentReference `json:"parentReference"`
	DownloadURL     string          `json:"@microsoft.graph.downloadUrl"`
	File            *file           `json:"file"`
	Folder          *folder         `json:"folder"`
}

FileInfo 文件元信息

func (*FileInfo) GetSourcePath

func (info *FileInfo) GetSourcePath() string

GetSourcePath 获取文件的绝对路径

type ListResponse

type ListResponse struct {
	Value   []FileInfo `json:"value"`
	Context string     `json:"@odata.context"`
}

ListResponse 列取子项目响应

type OAuthError

type OAuthError struct {
	ErrorType        string `json:"error"`
	ErrorDescription string `json:"error_description"`
	CorrelationID    string `json:"correlation_id"`
}

OAuthError OAuth相关接口的错误响应

func (OAuthError) Error

func (err OAuthError) Error() string

Error 实现error接口

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option 发送请求的额外设置

func WithCode

func WithCode(t string) Option

WithCode 设置接口Code

func WithConflictBehavior

func WithConflictBehavior(t string) Option

WithConflictBehavior 设置文件重名后的处理方式

func WithDriverResource

func WithDriverResource(t bool) Option

WithConflictBehavior 设置文件重名后的处理方式

func WithRefreshToken

func WithRefreshToken(t string) Option

WithRefreshToken 设置接口RefreshToken

type RespError

type RespError struct {
	APIError APIError `json:"error"`
}

RespError 接口返回错误

func (RespError) Error

func (err RespError) Error() string

Error 实现error接口

type Site

type Site struct {
	Description string `json:"description"`
	ID          string `json:"id"`
	Name        string `json:"name"`
	DisplayName string `json:"displayName"`
	WebUrl      string `json:"webUrl"`
}

Site SharePoint 站点信息

type ThumbResponse

type ThumbResponse struct {
	Value []map[string]interface{} `json:"value"`
	URL   string                   `json:"url"`
}

ThumbResponse 获取缩略图的响应

type UploadResult

type UploadResult struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Size uint64 `json:"size"`
}

UploadResult 上传结果

type UploadSessionResponse

type UploadSessionResponse struct {
	DataContext        string   `json:"@odata.context"`
	ExpirationDateTime string   `json:"expirationDateTime"`
	NextExpectedRanges []string `json:"nextExpectedRanges"`
	UploadURL          string   `json:"uploadUrl"`
}

UploadSessionResponse 分片上传会话

Jump to

Keyboard shortcuts

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