googledrive

package
v3.0.0-...-3edb00a Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenCachePrefix = "googledrive_"
)

Variables

View Source
var (
	// Defualt required scopes
	RequiredScope = []string{
		drive.DriveScope,
		"openid",
		"profile",
		"https://www.googleapis.com/auth/userinfo.profile",
	}

	// ErrInvalidRefreshToken 上传策略无有效的RefreshToken
	ErrInvalidRefreshToken = errors.New("no valid refresh token in this policy")
)

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 Client

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

	ClientID     string
	ClientSecret string
	Redirect     string

	Request           request.Client
	ClusterController cluster.Controller
}

Client Google Drive client

func NewClient

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

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

func (*Client) AccessToken

func (client *Client) AccessToken() string

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, code, refreshToken string) (*Credential, error)

ObtainToken 通过code或refresh_token兑换token

func (*Client) UpdateCredential

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

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

type Credential

type Credential struct {
	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 Driver

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

Driver Google Drive 适配器

func (*Driver) CancelToken

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

func (*Driver) Delete

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

func (*Driver) Get

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

func (*Driver) List

func (d *Driver) List(ctx context.Context, path string, recursive bool) ([]response.Object, error)

func (*Driver) Put

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

func (*Driver) Source

func (d *Driver) Source(ctx context.Context, path string, ttl int64, isDownload bool, speed int) (string, error)

func (*Driver) Thumb

func (d *Driver) Thumb(ctx context.Context, file *model.File) (*response.ContentResponse, error)

func (*Driver) Token

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

type Endpoints

type Endpoints struct {
	UserConsentEndpoint string // OAuth认证的基URL
	TokenEndpoint       string // OAuth token 基URL
	EndpointURL         string // 接口请求的基URL
}

Endpoints OneDrive客户端相关设置

type OAuthError

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

OAuthError OAuth相关接口的错误响应

func (OAuthError) Error

func (err OAuthError) Error() string

Error 实现error接口

type RespError

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

RespError 接口返回错误

func (RespError) Error

func (err RespError) Error() string

Error 实现error接口

Jump to

Keyboard shortcuts

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