aliyundrive

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: Apache-2.0 Imports: 10 Imported by: 1

README

aliyundrive sdk for go language

阿里云盘 Go SDK ,基于 https://github.com/chyroc/go-aliyundrive 。 因原作者对于细节的把控粒度的分歧、加上本人的精力有限,因此不再往原项目提交 PR,感谢理解。

和原版本有什么不同?

  1. 重点关注接口以及功能的稳定性方面
  2. 精简代码结构
  3. 增加每个功能对应的测试用例
  4. 去除不必要的第三方库(例如控制台二维码输出、自己造轮子的 HTTP 请求库等)
  5. 增加实现配置保存的方式(内存、文件、以及 Redis)

更新记录

  • 20220306 初始化重构版本

安装

go get github.com/mingcheng/aliyundrive

使用

初始化
client := aliyundrive.New(...OptionFunc)

同时,选用持久化方案可以保存登录信息,建议自行配置对应的持久化以及日志方案。

持久化配置

本 SDK 已经实现了部分常见的持久化方案,例如内存(没有持久化)、Redis 以及文件。如果您需要自行持久化方案,实现 Store 的 interface 即可,参见 store 目录中的具体实现。

例如,使用 Redis 作为持久化方案,可以参考以下代码示例:

redisStore, err := NewRedisStore(&redis.Options{
Addr: redisAddr,
})

if err != nil {
return err
}

cli := aliyundrive.New(WithStore(redisStore))
Token

阿里云盘主要使用两种 token 信息,用于辨别用户以及获取用户对应的权限:

  1. access token 用于获得用户对应的权限信息
  2. refresh token 用于获得更新用户的 access token 信息

注意,这两个 token 都是具有有效期的(access token 的有效期按照小时来计算),有关具体如何获得 refresh token,可以参考以下常见问题的章节。

当获得 refresh token 以后,即可或许对应的 access token 以及用户信息,可以使用

token, err := cli.RefreshToken(context.TODO(), &RefreshTokenReq{
RefreshToken: refreshToken,
})

同时,SDK 会根据配置的持久化方案,来保存登录凭证。

信息

当通过 refresh token 获得用户信息以及 access token 以后,既可以通过使用

islogin := cli.IsLogin(context.TODO())

来判断用户是否已经登录成功,当登录成功后即可进行下一步的操作。

用户

获取已登录用户的本身信息,可以使用

self, err := cli.MySelf(context.TODO())

详细可以参见 self_test.go 这个测试用例文件的内容。

同时,如果需要查看对应的用户权限已经网盘的资源等内容,可以使用

info, err := cli.PersonalInfo(context.TODO())

这个函数调用。详细可以参见 personal_info_test.go 这个测试用例文件的内容。

文件和目录

文件调用是 SDK 中的核心功能。在了解文件和目录之前,首先需要了解预设的几个模式以及常量。目前,SDK 封装了几个比较常用的常量,分别对应了以下的内容(以下内容来自 type.go 文件)。

类型

  • TypeFolder // 类型为目录
  • TypeFile // 类型为文件

建立资源的模式

  • ModeRefuse // 当发现目标已经有存在的对象,则拒绝建立对应的目标对象
  • ModeAutoRename // 当有目标对象存在时,自动重命名需要上传的文件或者目录资源

同时,每个文件和目录对象都会有对应的父节点,网盘对应的根节点统一为 RootFileID 这个常量。

列出文件和目录

列出文件和目录有比较复杂的参数以及请求和相应结构,需要了解部分 SQL 相关的信息,可以方便更好的调用这个函数本身的功能。

简单的调用列出根目录的文件内容,可以调用

files, err := cli.Lists(context.TODO(), &FileListReq{
DriveID: self.DefaultDriveID,
})

即可,具体的参数相见 FileListReq 这个结构体其中的内容。

其中,self.DefaultDriveID 为获取用户信息中能够得到,它普遍是目前操作网盘对应的默认 DriveID ,因此很重要。

新建目录

建立目录非常简单,例如在根目录下建立 just-for-example 目录以下的调用即可:

dirInfo, err := cli.CreateFolder(context.TODO(), &CreateFolderReq{
DriveID:      self.DefaultDriveID,
ParentFileID: RootFileID,
Name:         "just-for-example",
})

这里需要说明的是子目录的建立方式,可以使用以下的调用。

dirInfo, err := cli.CreateFolder(context.TODO(), &CreateFolderReq{
  DriveID:       self.DefaultDriveID,
  ParentFileID:  RootFileID,
  Name:          "just/for/example",
  CheckNameMode: ModeRefuse,
})

需要注意的是

  • 子目录的父节点目录需要指定,否则会建立不成功
  • 返回的目录信息是最子节点的信息,例如以上的建立是 example 这个子目录的信息
  • 如果 CheckNameMode 的类型不是 ModeRefuse,那么如果有同名名录的情况下将在父目录建立重新命名的子目录。例如,以上的目录如果有对应的目录,那么将会建立 example(1) 这个目录。
  • 如果 CheckNameMode 类型为 ModeRefuse,那么将会返回已经存在的目录信息
文件和目录信息

用于获取文件和目录的信息,具体的调用方式可以参考 get_test.go 这个文件。

上传文件

具体的调用方式可以参考 get_test.go 这个文件。

删除文件和目录

具体的调用方式可以参考 trash_test.go 这个文件,注意云盘默认不会直接删除文件而是将文件移动到回收站中。

移动文件和目录

具体的调用方式可以参考 move_test.go 这个文件。

重命名文件和目录

具体的调用方式可以参考 rename_test.go 这个文件,注意这只是文件或者目录名称的修改,如果是需要移动文件,则参考移动文件和目录这个章节。

分享

分享部分的功能可以直接参见 share_test.go 这个测试用例。

常见问题

如何获取 Refresh Token?

可以在登录阿里网盘客户端后,打开 Web 控制台粘贴输入 JavaScript 代码

JSON.parse(localStorage.token).refresh_token;

返回的字符串内容就是 Refresh Token 。目前 Token 的有效期未知,目前的测试情况看来有几天的时间。

Documentation

Overview

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

*

  • Copyright 2022 chyroc *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

Index

Constants

View Source
const (
	TypeFolder = "folder"
	TypeFile   = "file"
)
View Source
const (
	ModeRefuse     = "refuse"
	ModeAutoRename = "auto_rename"
)
View Source
const KeyAccessToken = "aliyun_drive_access_token"
View Source
const KeyRefreshToken = "aliyun_drive_refresh_token"
View Source
const RootFileID = "root"

Variables

This section is empty.

Functions

This section is empty.

Types

type AliyunDrive

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

func New

func New(options ...OptionFunc) *AliyunDrive

func (*AliyunDrive) CancelShare

func (r *AliyunDrive) CancelShare(ctx context.Context, req *CancelShareReq) error

func (*AliyunDrive) CreateFolder

func (r *AliyunDrive) CreateFolder(ctx context.Context, request *CreateFolderReq) (*CreateFolderResp, error)

CreateFolder to create folder

func (*AliyunDrive) CreateShare

func (r *AliyunDrive) CreateShare(ctx context.Context, req *CreateShareReq) (*ShareFile, error)

func (*AliyunDrive) DeviceList

func (r *AliyunDrive) DeviceList(ctx context.Context) (*DeviceListResp, error)

func (*AliyunDrive) DownloadURL

func (r *AliyunDrive) DownloadURL(ctx context.Context, request *DownloadReq) (*DownloadResp, error)

func (*AliyunDrive) Get

func (r *AliyunDrive) Get(ctx context.Context, request *GetFileReq) (*GetFileResp, error)

func (*AliyunDrive) GetSBox

func (r *AliyunDrive) GetSBox(ctx context.Context) (*GetSBoxResp, error)

func (*AliyunDrive) IsLogin

func (r *AliyunDrive) IsLogin(ctx context.Context) bool

IsLogin to detect whether user is login

func (*AliyunDrive) List

func (r *AliyunDrive) List(ctx context.Context, request *FileListReq) (*FileListResp, error)

@TODO

func (*AliyunDrive) ListShare

func (r *AliyunDrive) ListShare(ctx context.Context, req *ListShareReq) (*ListShareResp, error)

func (*AliyunDrive) Lists

func (r *AliyunDrive) Lists(ctx context.Context, request *FileListReq) (*FileListResp, error)

func (*AliyunDrive) Move

func (r *AliyunDrive) Move(ctx context.Context, request *MoveReq) (*MoveResp, error)

func (*AliyunDrive) MySelf

func (r *AliyunDrive) MySelf(ctx context.Context) (*GetSelfUserResp, error)

func (*AliyunDrive) Path

func (r *AliyunDrive) Path(ctx context.Context, request *PathReq) (*PathResp, error)

func (*AliyunDrive) PersonalInfo

func (r *AliyunDrive) PersonalInfo(ctx context.Context) (*PersonalInfoResp, error)

func (*AliyunDrive) RefreshToken

func (r *AliyunDrive) RefreshToken(ctx context.Context, request *RefreshTokenReq) (*RefreshTokenResp, error)

func (*AliyunDrive) Rename

func (r *AliyunDrive) Rename(ctx context.Context, request *RenameFileReq) (*RenameFileResp, error)

func (*AliyunDrive) Restore

func (r *AliyunDrive) Restore(ctx context.Context, request *RestoreFileReq) error

func (*AliyunDrive) Token

func (r *AliyunDrive) Token(ctx context.Context, request *TokenReq) (*RefreshTokenResp, error)

func (*AliyunDrive) Trash

func (r *AliyunDrive) Trash(ctx context.Context, request *DeleteFileReq) error

func (*AliyunDrive) UpdateShare

func (r *AliyunDrive) UpdateShare(ctx context.Context, req *UpdateShareReq) (*ShareFile, error)

func (*AliyunDrive) UploadFile

func (r *AliyunDrive) UploadFile(ctx context.Context, request *UploadFileReq) (*UploadFileResp, error)

func (*AliyunDrive) UploadStream

func (r *AliyunDrive) UploadStream(ctx context.Context, request *UploadFileReq, stream io.Reader, streamSize int64) (*UploadFileResp, error)

type CancelShareReq

type CancelShareReq struct {
	ShareId string `json:"share_id"`
}

type CreateFolderReq

type CreateFolderReq struct {
	DriveID       string `json:"drive_id"`
	ParentFileID  string `json:"parent_file_id"`
	Name          string `json:"name"`
	CheckNameMode string `json:"check_name_mode"`
	Type          string `json:"type"`
}

type CreateFolderResp

type CreateFolderResp struct {
	ParentFileID string `json:"parent_file_id"`
	Type         string `json:"type"`
	FileID       string `json:"file_id"`
	DomainID     string `json:"domain_id"`
	DriveID      string `json:"drive_id"`
	FileName     string `json:"file_name"`
	EncryptMode  string `json:"encrypt_mode"`
}

type CreateShareReq

type CreateShareReq struct {
	Expiration     string   `json:"expiration"`
	SyncToHomepage bool     `json:"sync_to_homepage"`
	SharePwd       string   `json:"share_pwd"`
	DriveId        string   `json:"drive_id"`
	FileIdList     []string `json:"file_id_list"`
}

type DeleteFileReq

type DeleteFileReq struct {
	DriveID string `json:"drive_id"`
	FileID  string `json:"file_id"`
}

type DeleteFileResp

type DeleteFileResp struct {
	DomainID    string `json:"domain_id"`
	DriveID     string `json:"drive_id"`
	FileID      string `json:"file_id"`
	AsyncTaskID string `json:"async_task_id"`
}

type DeviceListResp

type DeviceListResp struct {
	Result []struct {
		DeviceId   string `json:"deviceId"`
		DeviceName string `json:"deviceName"`
		ModelName  string `json:"modelName"`
		City       string `json:"city"`
		LoginTime  string `json:"loginTime"`
	} `json:"result"`
}

type DownloadReq added in v1.0.1

type DownloadReq struct {
	DriveID string `json:"drive_id"`
	FileID  string `json:"file_id"`
}

type DownloadResp added in v1.0.1

type DownloadResp struct {
	Method      string `json:"method"`
	URL         string `json:"url"`
	InternalURL string `json:"internal_url"`
	CdnURL      string `json:"cdn_url"`
	Expiration  string `json:"expiration"`
	Size        int    `json:"size"`
	RateLimit   struct {
		PartSpeed int `json:"part_speed"`
		PartSize  int `json:"part_size"`
	} `json:"ratelimit"`
}

type File

type File struct {
	DriveID         string    `json:"drive_id"`
	DomainID        string    `json:"domain_id"`
	FileID          string    `json:"file_id"`
	Name            string    `json:"name"`
	Type            string    `json:"type"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
	Hidden          bool      `json:"hidden"`
	Starred         bool      `json:"starred"`
	Status          string    `json:"status"`
	UserMeta        string    `json:"user_meta,omitempty"`
	ParentFileID    string    `json:"parent_file_id"`
	EncryptMode     string    `json:"encrypt_mode"`
	ContentType     string    `json:"content_type,omitempty"`
	FileExtension   string    `json:"file_extension,omitempty"`
	MimeType        string    `json:"mime_type,omitempty"`
	MimeExtension   string    `json:"mime_extension,omitempty"`
	Size            int64     `json:"size,omitempty"`
	Crc64Hash       string    `json:"crc64_hash,omitempty"`
	ContentHash     string    `json:"content_hash,omitempty"`
	ContentHashName string    `json:"content_hash_name,omitempty"`
	DownloadURL     string    `json:"download_url,omitempty"`
	URL             string    `json:"url,omitempty"`
	Thumbnail       string    `json:"thumbnail,omitempty"`
	Category        string    `json:"category,omitempty"`
	PunishFlag      int       `json:"punish_flag,omitempty"`
}

type FileListReq

type FileListReq struct {
	GetAll                bool   `json:"get_all"`
	ShareID               string `json:"share_id"` // drive_id 和 share_id 必选传其中一个
	DriveID               string `json:"drive_id"` // drive_id 和 share_id 必选传其中一个
	ParentFileID          string `json:"parent_file_id"`
	Marker                string `json:"marker"`
	Limit                 int    `json:"limit"`
	All                   bool   `json:"all"`
	URLExpireSec          int    `json:"url_expire_sec"`
	ImageThumbnailProcess string `json:"image_thumbnail_process"`
	ImageURLProcess       string `json:"image_url_process"`
	VideoThumbnailProcess string `json:"video_thumbnail_process"`
	Fields                string `json:"fields"`
	OrderBy               string `json:"order_by"`
	OrderDirection        string `json:"order_direction"`
}

type FileListResp

type FileListResp struct {
	Items      []*File `json:"items"`
	NextMarker string  `json:"next_marker"`
}

type GetFileReq

type GetFileReq struct {
	DriveID string `json:"drive_id"`
	FileID  string `json:"file_id"`
}

type GetFileResp

type GetFileResp struct {
	File
	Trashed bool `json:"trashed"`
}

type GetSBoxResp

type GetSBoxResp struct {
	DriveID          string `json:"drive_id"`
	UsedSize         int    `json:"sbox_used_size"`
	RealUsedSize     int    `json:"sbox_real_used_size"`
	TotalSize        int64  `json:"sbox_total_size"`
	RecommendVip     string `json:"recommend_vip"`
	PinSetup         bool   `json:"pin_setup"`
	Locked           bool   `json:"locked"`
	InsuranceEnabled bool   `json:"insurance_enabled"`
}

type GetSelfUserResp

type GetSelfUserResp struct {
	DomainID                    string      `json:"domain_id"`
	UserID                      string      `json:"user_id"`
	Avatar                      string      `json:"avatar"`
	CreatedAt                   int64       `json:"created_at"`
	UpdatedAt                   int64       `json:"updated_at"`
	Email                       string      `json:"email"`
	NickName                    string      `json:"nick_name"`
	Phone                       string      `json:"phone"`
	Role                        string      `json:"role"`
	Status                      string      `json:"status"`
	UserName                    string      `json:"user_name"`
	Description                 string      `json:"description"`
	DefaultDriveID              string      `json:"default_drive_id"`
	DenyChangePasswordBySelf    bool        `json:"deny_change_password_by_self"`
	NeedChangePasswordNextLogin bool        `json:"need_change_password_next_login"`
	Permission                  interface{} `json:"permission"`
}

type ListShareReq

type ListShareReq struct {
	Creator         string `json:"creator"`
	IncludeCanceled bool   `json:"include_canceled"`
	Category        string `json:"category"`
	OrderBy         string `json:"order_by"`
	OrderDirection  string `json:"order_direction"`
}

type ListShareResp

type ListShareResp struct {
	Items      []ShareFile `json:"items"`
	NextMarker string      `json:"next_marker"`
}

type MoveReq

type MoveReq struct {
	DriveID        string `json:"drive_id"`
	FileID         string `json:"file_id"`
	ToDriveID      string `json:"to_drive_id"`
	ToParentFileID string `json:"to_parent_file_id"`
}

type MoveResp

type MoveResp struct {
	DomainID string `json:"domain_id"`
	DriveID  string `json:"drive_id"`
	FileID   string `json:"file_id"`
}

type OptionFunc

type OptionFunc func(*AliyunDrive)

func WithLogger

func WithLogger(logger *logrus.Logger) OptionFunc

func WithStore

func WithStore(store Store) OptionFunc

type PathReq

type PathReq struct {
	DriveID string `json:"drive_id"`
	FileID  string `json:"file_id"`
}

type PathResp

type PathResp struct {
	Items []*File `json:"items"`
}

type PersonalInfoResp

type PersonalInfoResp struct {
	RightsInfo struct {
		SpuId      string `json:"spu_id"`
		Name       string `json:"name"`
		IsExpires  bool   `json:"is_expires"`
		Privileges []struct {
			FeatureId     string `json:"feature_id"`
			FeatureAttrId string `json:"feature_attr_id"`
			Quota         int    `json:"quota"`
		} `json:"privileges"`
	} `json:"personal_rights_info"`
	SpaceInfo struct {
		UsedSize  uint `json:"used_size"`
		TotalSize uint `json:"total_size"`
	} `json:"personal_space_info"`
}

type RefreshTokenReq

type RefreshTokenReq struct {
	GrantType    string `json:"grant_type"`
	RefreshToken string `json:"refresh_token"`
}

type RefreshTokenResp

type RefreshTokenResp struct {
	DefaultSboxDriveID string    `json:"default_sbox_drive_id"`
	Role               string    `json:"role"`
	DeviceID           string    `json:"device_id"`
	UserName           string    `json:"user_name"`
	NeedLink           bool      `json:"need_link"`
	ExpireTime         time.Time `json:"expire_time"`
	PinSetup           bool      `json:"pin_setup"`
	NeedRpVerify       bool      `json:"need_rp_verify"`
	Avatar             string    `json:"avatar"`
	UserData           struct {
		// DingDingRobotURL string `json:"DingDingRobotUrl"`
		// EncourageDesc    string `json:"EncourageDesc"`
		// FeedBackSwitch   bool   `json:"FeedBackSwitch"`
		// FollowingDesc    string `json:"FollowingDesc"`
		DingDingRobotURL string `json:"ding_ding_robot_url"`
		EncourageDesc    string `json:"encourage_desc"`
		FeedBackSwitch   bool   `json:"feed_back_switch"`
		FollowingDesc    string `json:"following_desc"`
	} `json:"user_data"`
	TokenType      string        `json:"token_type"`
	AccessToken    string        `json:"access_token"`
	DefaultDriveID string        `json:"default_drive_id"`
	RefreshToken   string        `json:"refresh_token"`
	IsFirstLogin   bool          `json:"is_first_login"`
	UserID         string        `json:"user_id"`
	NickName       string        `json:"nick_name"`
	ExistLink      []interface{} `json:"exist_link"`
	State          string        `json:"state"`
	ExpiresIn      int           `json:"expires_in"`
	Status         string        `json:"status"`
}

type RenameFileReq

type RenameFileReq struct {
	DriveID       string `json:"drive_id"`
	FileID        string `json:"file_id"`
	Name          string `json:"name"`
	CheckNameMode string `json:"check_name_mode"`
}

type RenameFileResp

type RenameFileResp struct {
	DriveID          string `json:"drive_id"`
	UsedSize         int    `json:"sbox_used_size"`
	RealUsedSize     int    `json:"sbox_real_used_size"`
	TotalSize        int64  `json:"sbox_total_size"`
	RecommendVip     string `json:"recommend_vip"`
	PinSetup         bool   `json:"pin_setup"`
	Locked           bool   `json:"locked"`
	InsuranceEnabled bool   `json:"insurance_enabled"`
}

type RestoreFileReq

type RestoreFileReq struct {
	DriveId string `json:"drive_id"`
	FileId  string `json:"file_id"`
}

type ShareFile

type ShareFile struct {
	Popularity    int       `json:"popularity"`
	ShareId       string    `json:"share_id"`
	ShareMsg      string    `json:"share_msg"`
	ShareName     string    `json:"share_name"`
	Description   string    `json:"description"`
	Expiration    string    `json:"expiration"`
	Expired       bool      `json:"expired"`
	SharePwd      string    `json:"share_pwd"`
	ShareUrl      string    `json:"share_url"`
	Creator       string    `json:"creator"`
	DriveId       string    `json:"drive_id"`
	FileId        string    `json:"file_id"`
	FileIdList    []string  `json:"file_id_list"`
	PreviewCount  int       `json:"preview_count"`
	SaveCount     int       `json:"save_count"`
	DownloadCount int       `json:"download_count"`
	Status        string    `json:"status"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
	FirstFile     struct {
		Trashed            bool      `json:"trashed"`
		Category           string    `json:"category"`
		ContentHash        string    `json:"content_hash"`
		ContentHashName    string    `json:"content_hash_name"`
		ContentType        string    `json:"content_type"`
		Crc64Hash          string    `json:"crc64_hash"`
		CreatedAt          time.Time `json:"created_at"`
		DomainId           string    `json:"domain_id"`
		DownloadUrl        string    `json:"download_url"`
		DriveId            string    `json:"drive_id"`
		EncryptMode        string    `json:"encrypt_mode"`
		FileExtension      string    `json:"file_extension"`
		FileId             string    `json:"file_id"`
		Hidden             bool      `json:"hidden"`
		ImageMediaMetadata struct {
			CroppingSuggestion []struct {
				AspectRatio      string `json:"aspect_ratio"`
				CroppingBoundary struct {
					Height int `json:"height"`
					Left   int `json:"left"`
					Top    int `json:"top"`
					Width  int `json:"width"`
				} `json:"cropping_boundary"`
				Score float64 `json:"score"`
			} `json:"cropping_suggestion"`
			Exif         string `json:"exif"`
			Height       int    `json:"height"`
			ImageQuality struct {
				OverallScore float64 `json:"overall_score"`
			} `json:"image_quality"`
			ImageTags []struct {
				Confidence float64 `json:"confidence"`
				Name       string  `json:"name"`
				TagLevel   int     `json:"tag_level"`
				ParentName string  `json:"parent_name,omitempty"`
			} `json:"image_tags"`
			Width int `json:"width"`
		} `json:"image_media_metadata"`
		Labels       []string  `json:"labels"`
		MimeType     string    `json:"mime_type"`
		Name         string    `json:"name"`
		ParentFileId string    `json:"parent_file_id"`
		PunishFlag   int       `json:"punish_flag"`
		Size         int       `json:"size"`
		Starred      bool      `json:"starred"`
		Status       string    `json:"status"`
		Thumbnail    string    `json:"thumbnail"`
		Type         string    `json:"type"`
		UpdatedAt    time.Time `json:"updated_at"`
		UploadId     string    `json:"upload_id"`
		Url          string    `json:"url"`
		UserMeta     string    `json:"user_meta"`
	} `json:"first_file"`
	IsPhotoCollection bool   `json:"is_photo_collection"`
	SyncToHomepage    bool   `json:"sync_to_homepage"`
	PopularityStr     string `json:"popularity_str"`
	FullShareMsg      string `json:"full_share_msg"`
	DisplayName       string `json:"display_name"`
}

type Store

type Store interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, data []byte) error
}

type Token

type Token struct {
	AccessToken  string    `json:"access_token"`
	ExpiredAt    time.Time `json:"expired_at"`
	RefreshToken string    `json:"refresh_token"`
}

type TokenReq

type TokenReq struct {
	Code      string `json:"code"`
	LoginType string `json:"loginType"`
	DeviceID  string `json:"deviceId"`
}

type UpdateShareReq

type UpdateShareReq struct {
	ShareId    string `json:"share_id"`
	Expiration string `json:"expiration"`
}

type UploadFileReq

type UploadFileReq struct {
	DriveID       string `json:"drive_id"`
	ParentID      string `json:"parent_id"`
	FilePath      string `json:"file_path"`
	CheckNameMode string `json:"check_name_mode"`
	Name          string `json:"name"`
}

type UploadFileResp

type UploadFileResp struct {
	DriveID            string    `json:"drive_id"`
	DomainID           string    `json:"domain_id"`
	FileID             string    `json:"file_id"`
	Name               string    `json:"name"`
	Type               string    `json:"type"`
	ContentType        string    `json:"content_type"` // application/oct-stream
	CreatedAt          time.Time `json:"created_at"`
	UpdatedAt          time.Time `json:"updated_at"`
	FileExtension      string    `json:"file_extension"`
	Hidden             bool      `json:"hidden"`
	Size               int       `json:"size"`
	Starred            bool      `json:"starred"`
	Status             string    `json:"status"` // available
	UploadID           string    `json:"upload_id"`
	ParentFileID       string    `json:"parent_file_id"`
	Crc64Hash          string    `json:"crc64_hash"`
	ContentHash        string    `json:"content_hash"`
	ContentHashName    string    `json:"content_hash_name"` // sha1
	Category           string    `json:"category"`
	EncryptMode        string    `json:"encrypt_mode"`
	ImageMediaMetadata struct {
		ImageQuality struct{} `json:"image_quality"`
	} `json:"image_media_metadata"`
	Location string `json:"location"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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