aliyundrive_open

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: Unlicense Imports: 12 Imported by: 0

README

aliyundrive_open

终于有内测权限了, 开心! 可以参考我另外一个基于 aliyundrive_open 完成的项目:

https://github.com/yanjunhui/aliyundrive_webdav

代码比较简陋, 抛砖引玉, 有兴趣的可以一起完善

方法列表

https://pkg.go.dev/github.com/yanjunhui/aliyundrive_open

简单示例

1. 生成一个客户端实例
var client = aliyundrive_open.NewClient(ClientID, ClientSecret)
2. GetQRCode 获取登录二维码. 直接打开返回的 qrCodeUrl 就可以看到二维码.

sid 参数用于后续 QrCodeStatus 方法获取扫码状态

生成请求选项. 默认配置选项.自定义参数可以再通过其他 Set 方法设置值

func GetQRCode() (result aliyundrive_open.AuthorizeQRCode, err error) {
    option := aliyundrive_open.NewDefaultSingleAuthorizeOption()
    return client.QRCode(option)
}
3. CheckQrCodeStatus 检查二维码状态. 通过 QRCode方法返回的 sid 参数获取二维码状态.

扫码成功后,返回 authCode 用于最后的登录授权获取 access_token 和 refresh_token

func CheckQrCodeStatus(sid string) (result aliyundrive_open.AuthorizeQRCodeStatus, err error) {
    return client.QrCodeStatus(sid)
}
4. Auth 登录授权.

通过 QrCodeStatus 方法返回的 authCode 参数获取 access_token 和 refresh_token

func Auth(authCode string) (result aliyundrive_open.Authorize, err error) {
    return client.Authorize(authCode)
}
5. RefreshToken 刷新 access_token

通过 Auth 方法返回的 refresh_token 参数刷新 access_token

func RefreshToken(refreshToken string) (result aliyundrive_open.Authorize, err error) {
	return client.RefreshToken(refreshToken)
}
6. 完整的登录授权流程
func Login() (result aliyundrive_open.Authorize, err error) {
	//1. 获取登录二维码
	qrCode, err := GetQRCode()
	if err != nil {
		log.Printf("获取二维码失败: %s\n", err)
		return result, err
	}

	//2. 二维码可以通过任意方式加载图片展示给用户. 这里我们就直接通过浏览器打开以下链接
	log.Printf("点击或者复制以下链接通过浏览器打开\n%s\n", qrCode.QrCodeUrl)

	//3. 循环检查二维码状态. 这里可以由前端主动发起请求查询, 也可以由后端主动轮询
	//这里我们就直接使用后端轮询的方式
	//确认登录成功后, 会获得authCode
	authCode := ""
	ticker := time.NewTicker(1 * time.Second)
	for {
		select {
		case <-ticker.C:
			status, err := CheckQrCodeStatus(qrCode.Sid)
			if err != nil {
				log.Printf("获取二维码状态失败: %s\n", err)
				return result, err
			}

			//有三个状态, 我们可以根据状态做不同的处理
			switch status.Status {
			case "WaitLogin": // 二维码未扫描
				continue
			case "ScanSuccess": // 二维码已扫描
				log.Println("二维码已扫描,等待授权确认")
			case "LoginSuccess": // 二维码已确认
				log.Println("二维码已确认")
				authCode = status.AuthCode
			}
		}
		//如果已经获取到了 authCode, 就跳出循环
		if authCode != "" {
			fmt.Println("authCode: ", authCode)
			break
		}
	}

	//4. 登录授权
	//通过 authCode 获取 access_token 和 refresh_token
	authorize, err := Auth(authCode)
	if err != nil {
		log.Printf("登录授权失败: %s\n", err)
		return result, err
	}

	log.Printf("登录授权成功\naccess_token: %s\n\nrefresh_token: %s\n driver_id: %s\n, 过期时间: %s\n", authorize.AccessToken, authorize.RefreshToken, authorize.DriveID, authorize.ExpiresTime.String())

	log.Printf("稍等 3 秒钟, 刷新 access_token\n")

	time.Sleep(3 * time.Second)

	//5. 刷新 access_token
	//通过 refresh_token 刷新 access_token
	authorize, err = RefreshToken(authorize.RefreshToken)
	if err != nil {
		log.Printf("刷新Token失败: %s\n", err)
		return result, err
	}

	log.Printf("刷新Token成功\naccess_token: %s\n\nrefresh_token: %s, 过期时间: %s\n", authorize.AccessToken, authorize.RefreshToken, authorize.ExpiresTime.String())
	return authorize, nil
}
7. GetDriveInfo 通过 access_token 获取云盘信息

这里将获取到该用户云盘的 drive_id, 以后的每一个操作得需要

其实 Auth 方法已经集成 DriveInfo 方法得到了 drive_id

这里仅做示例

func GetDriveInfo(authorize aliyundrive_open.Authorize) {
	driveInfo, err := authorize.DriveInfo()
	if err != nil {
		log.Printf("获取云盘信息失败: %s\n", err)
	return
}

	log.Printf("获取云盘信息成功, drive_id: %s\n", driveInfo.DefaultDriveId)
}
8. GetDrivesSpace 获取空间使用情况
func GetDrivesSpace(authorize aliyundrive_open.Authorize) {
	driveSpace, err := authorize.DrivesSpace()
	if err != nil {
		log.Printf("获取云盘空间使用情况失败: %s\n", err)
		return
	}

	log.Printf("获取云盘空间使用情况成功, 总空间: %d GB, 已使用空间: %d GB\n", driveSpace.PersonalSpaceInfo.TotalSize/1024/1024/1024/1024, driveSpace.PersonalSpaceInfo.UsedSize/1024/1024/1024/1024)
}
9. GetFileList 获取文件列表

这里我们先获取根目录下的文件列表

这里我们使用了 NewFileListOption 方法来生成请求选项. 其余个性化参数可以通过 Set 方法设置

func GetFileList(authorize aliyundrive_open.Authorize, parentID string) {
	if parentID == "" {
		parentID = "root"
		}
		option := aliyundrive_open.NewFileListOption(authorize.DriveID, parentID, "")
		fileList, err := authorize.FileList(option)
		if err != nil {
		log.Printf("获取文件列表情况失败: %s\n", err)
		return
	}

	log.Printf("获取文件列表成功, 文件数量: %d\n", len(fileList.Items))
}
10. GetFileInfo 获取文件信息, 目录和文件都支持
func GetFileInfo(authorize aliyundrive_open.Authorize, fileID string) (file aliyundrive_open.FileInfo, err error) {
	option := aliyundrive_open.NewFileOption(authorize.DriveID, fileID)
	file, err = authorize.File(option)
	if err != nil {
		log.Printf("获取文件信息失败: %s\n", err)
		return
	}

	log.Printf("文件ID: %s 名称: %s, 类型: %s 大小: %d\n", file.FileId, file.Name, file.Type, file.Size)
	return file, err
}
11. GetFilesInfo 批量获取文件信息

这里我们使用了 NewFilesOption 方法来生成请求选项. 其余个性化参数可以通过 Set 方法设置

func GetFilesInfo(authorize aliyundrive_open.Authorize, ids []string) {

	bOption := aliyundrive_open.NewFilesOption(authorize.DriveID, ids)
	bFiles, err := authorize.Files(bOption)
	if err != nil {
		log.Printf("批量获取文件信息失败: %s\n", err)
		return
	}

	log.Printf("批量获取文件信息成功, 文件数量: %d\n", len(bFiles.Items))

	for _, file := range bFiles.Items {
		log.Printf("文件ID: %s 名称: %s, 类型: %s 大小: %d\n", file.FileId, file.Name, file.Type, file.Size)
	}

}
12. 获取文件下载地址
func GetDownloadURL(authorize aliyundrive_open.Authorize, fileID string) {
	option := aliyundrive_open.NewFileDownloadURLOption(authorize.DriveID, fileID)
	downInfo, err := authorize.FileDownloadURL(option)
	if err != nil {
		log.Printf("获取文件下载地址失败: %s\n", err)
		return
	}

	log.Println("文件下载地址: ", downInfo.URL)
}
13. RenameFile 重命名文件
func RenameFile(authorize aliyundrive_open.Authorize, fileID string, newName string) {
	option := aliyundrive_open.NewFileRenameOption(authorize.DriveID, fileID, newName)
	result, err := authorize.FileRename(option)
	if err != nil {
		log.Println(err)
		return
	}

	log.Printf("修改名字成功: %s\n", result.Name)
}
14. GetVideoPlayURL 获取视频播放地址
func GetVideoPlayInfo(authorize aliyundrive_open.Authorize, fileID string) {
	option := aliyundrive_open.NewFileVideoPlayInfoOption(authorize.DriveID, fileID)
	result, err := authorize.FileVideoPlayInfo(option)
	if err != nil {
		log.Println(err)
		return
	}

	for _, playInfo := range result.VideoPreviewPlayInfo.LiveTranscodingTaskList {
		log.Printf("视频播放地址: %s\n", playInfo.Url)
	}
}
15. MoveFile 移动文件
func MoveFile(authorize aliyundrive_open.Authorize, fileID, parentID string) {

	file, err := GetFileInfo(authorize, fileID)
	if err != nil {
		log.Println(err)
		return
	}

	log.Printf("移动前文件 %s(%s) 父目录ID: %s\n", file.Name, file.FileId, file.ParentFileId)

	option := aliyundrive_open.NewFileMoveAndCopyOption(authorize.DriveID, fileID, parentID)
	_, err = authorize.FileMove(option)
	if err != nil {
		log.Println(err)
		return
	}

	file, err = GetFileInfo(authorize, fileID)
	if err != nil {
		log.Println(err)
		return
	}

	log.Printf("移动后文件 %s(%s) 父目录ID: %s\n", file.Name, file.FileId, file.ParentFileId)
}
16. CopyFile 复制文件
func CopyFile(authorize aliyundrive_open.Authorize, fileID, toParentID string) {
	option := aliyundrive_open.NewFileMoveAndCopyOption(authorize.DriveID, fileID, toParentID)
	_, err := authorize.FileCopy(option)
	if err != nil {
		log.Println(err)
		return
	}

	log.Printf("复制文件成功: %s\n", fileID)
}
17. CreateFolder 创建目录
func CreateFolder(authorize aliyundrive_open.Authorize, parentID, folderName string) (result aliyundrive_open.FileCreate, err error) {
	option := aliyundrive_open.NewFileCreateOption(authorize.DriveID, "root", "新目录")
	result, err = authorize.FolderCreate(option)
	if err != nil {
		log.Printf("Token 刷新失败: %s\n", err)
	}
	return result, err
}
18. TrashFile 将文件移入回收站
func TrashFile(authorize aliyundrive_open.Authorize, fileID string) (result aliyundrive_open.FileMoveCopyDelTask, err error) {
	option := aliyundrive_open.NewFileTrashAndDeleteOption(authorize.DriveID, fileID)
	result, err = authorize.FileTrash(option)
	if err != nil {
		log.Printf("Token 刷新失败: %s\n", err)
	}
	return result, err
}
19. 彻底删除文件
func DeleteFile(authorize aliyundrive_open.Authorize, fileID string) (result aliyundrive_open.FileMoveCopyDelTask, err error) {
	option := aliyundrive_open.NewFileTrashAndDeleteOption(authorize.DriveID, fileID)
	result, err = authorize.FileDelete(option)
	if err != nil {
		log.Printf("Token 刷新失败: %s\n", err)
	}
	return result, err
}
20. UploadFile 上传文件
func UploadFile(authorize aliyundrive_open.Authorize, filePath string) (uploadResult aliyundrive_open.FileInfo, err error) {
    file, err := os.Open(filePath)
    if err != nil {
     log.Printf("打开文件失败: %s\n", err)
        return uploadResult, err
    }

    _, name := filepath.Split(file.Name())

    // 上传文件
    option := aliyundrive_open.NewFileUploadOption(authorize.DriveID, "root", name, file)
    uploadResult, err = authorize.FileUpload(option)
    if err != nil {
        log.Printf("上传文件失败: %s\n", err)
    }

    return uploadResult, err
}

Documentation

Index

Constants

View Source
const (
	APIBase = "https://openapi.aliyundrive.com"

	//用户权限相关
	APIAuthorizeMultiple     = APIBase + "/oauth/authorize"               //多种授权方式
	APIAuthorizeQrCode       = APIBase + "/oauth/authorize/qrcode"        //获取二维码, 仅支持扫码登录
	APIAuthorizeQrCodeStatus = APIBase + "/oauth/qrcode/%s/status"        //获取扫码结果
	APIRefreshToken          = APIBase + "/oauth/access_token"            //刷新 access_token
	APIDriveInfo             = APIBase + "/adrive/v1.0/user/getDriveInfo" //获取用户云盘信息
	APISpaceInfo             = APIBase + "/adrive/v1.0/user/getSpaceInfo" //获取空间大小信息

	//文件操作相关
	APIList              = APIBase + "/adrive/v1.0/openFile/list"                    //获取文件列表
	APIFile              = APIBase + "/adrive/v1.0/openFile/get"                     //获取文件信息
	APIFiles             = APIBase + "/adrive/v1.0/openFile/batch/get"               //批量获取文件信息
	APIFileTrash         = APIBase + "/adrive/v1.0/openFile/recyclebin/trash"        //移动文件到垃圾箱
	APIFileDelete        = APIBase + "/adrive/v1.0/openFile/delete"                  //彻底删除文件
	APIFileCreate        = APIBase + "/adrive/v1.0/openFile/create"                  //创建目录/文件
	APIFileComplete      = APIBase + "/adrive/v1.0/openFile/complete"                //创建文件完成
	APIFileDownload      = APIBase + "/adrive/v1.0/openFile/getDownloadUrl"          //获取下载链接
	APIFileVideoPlayInfo = APIBase + "/adrive/v1.0/openFile/getVideoPreviewPlayInfo" //获取视频转码播放信息
	APIFileMove          = APIBase + "/adrive/v1.0/openFile/move"                    //移动文件
	APIFileCopy          = APIBase + "/adrive/v1.0/openFile/copy"                    //复制文件
	APIFileUpdate        = APIBase + "/adrive/v1.0/openFile/update"                  //更新文件

)
View Source
const DefaultPartSize int64 = 1024 * 1024 * 64

Variables

View Source
var DefaultTimeout = time.Second * 30
View Source
var RestyHttpClient = NewRestyClient()
View Source
var UserAgent = "" /* 135-byte string literal not displayed */

Functions

func HttpPost

func HttpPost(url string, header http.Header, reqData interface{}, result interface{}) error

func NewRestyClient

func NewRestyClient() *resty.Client

Types

type Authorize

type Authorize struct {
	TokenType    string    `json:"token_type"`
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	ExpiresIn    int       `json:"expires_in"`
	ExpiresTime  time.Time `json:"expires_time"`
	DriveID      string    `json:"drive_id"`
	ErrorInfo
}

Authorize 登录授权信息

func (*Authorize) DriveInfo

func (a *Authorize) DriveInfo() (result DriveInfo, err error)

DriveInfo 获取云盘信息

func (*Authorize) DriveSpace

func (a *Authorize) DriveSpace() (result SpaceInfo, err error)

DriveSpace 获取云盘空间信息

func (*Authorize) File

func (a *Authorize) File(option *FileOption) (result FileInfo, err error)

File 获取文件信息

func (*Authorize) FileCopy

func (a *Authorize) FileCopy(option *FileOption) (result FileMoveCopyDelTask, err error)

FileCopy 复制文件

func (*Authorize) FileCreate

func (a *Authorize) FileCreate(option *FileOption) (result FileCreate, err error)

FileCreate 创建文件

func (*Authorize) FileDelete

func (a *Authorize) FileDelete(option *FileOption) (result FileMoveCopyDelTask, err error)

FileDelete 删除文件

func (*Authorize) FileDownloadURL

func (a *Authorize) FileDownloadURL(option *FileOption) (result FileDownloadURL, err error)

FileDownloadURL 获取文件下载链接

func (*Authorize) FileList

func (a *Authorize) FileList(option *FileOption) (result FileList, err error)

FileList 获取文件列表

func (*Authorize) FileMove

func (a *Authorize) FileMove(option *FileOption) (result FileMoveCopyDelTask, err error)

FileMove 移动文件

func (*Authorize) FileMoveAndCopy

func (a *Authorize) FileMoveAndCopy(option *FileOption, isMove bool) (result FileMoveCopyDelTask, err error)

FileMoveAndCopy 移动/复制文件

func (*Authorize) FileRename

func (a *Authorize) FileRename(option *FileOption) (result FileInfo, err error)

FileRename 重命名文件

func (*Authorize) FileReplaceName

func (a *Authorize) FileReplaceName(fileID, old, new string) error

FileReplaceName 批量替换文件名内指定字符(官方接口二次封装), 支持单文件和目录内所有子文件

func (*Authorize) FileTrash

func (a *Authorize) FileTrash(option *FileOption) (result FileMoveCopyDelTask, err error)

FileTrash 放入回收站

func (*Authorize) FileUpload

func (a *Authorize) FileUpload(option *FileOption) (result FileInfo, err error)

FileUpload 上传文件

func (*Authorize) FileVideoPlayInfo

func (a *Authorize) FileVideoPlayInfo(option *FileOption) (result FileVideoPlayInfo, err error)

FileVideoPlayInfo 获取视频转码播放信息

func (*Authorize) Files

func (a *Authorize) Files(options []*FileOption) (result FileList, err error)

Files 批量获取文件信息

func (*Authorize) FolderCreate

func (a *Authorize) FolderCreate(option *FileOption) (result FileCreate, err error)

FolderCreate 创建目录

func (*Authorize) HttpPost

func (a *Authorize) HttpPost(url string, reqData interface{}, result interface{}) error

HttpPost 请求

type AuthorizeOption

type AuthorizeOption struct {
	ClientID     string  `json:"client_id"`              // 开放平台应用ID
	ClientSecret string  `json:"client_secret"`          // 开放平台应用密钥
	Scopes       []Scope `json:"scopes"`                 // 授权范围
	Width        int     `json:"width,omitempty"`        // 二维码宽度
	Height       int     `json:"height,omitempty"`       // 二维码高度
	RedirectUri  string  `json:"redirect_uri,omitempty"` // 回调地址
	State        string  `json:"state,omitempty"`        // 防止CSRF攻击
}

H5页多种登录方式选项

func NewDefaultMultipleAuthorizeOption

func NewDefaultMultipleAuthorizeOption(redirectUri string) *AuthorizeOption

NewDefaultMultipleAuthorizeOption 创建默认授权选项 网页多种登录方式, 回调地址为必传,否则无法接收code.如无法满足条件,请使用使用 "单一扫码方式" 默认参数取消掉手机号权限(如果有需要, 请单独设置)

func NewDefaultSingleAuthorizeOption

func NewDefaultSingleAuthorizeOption() *AuthorizeOption

NewDefaultSingleAuthorizeOption 创建默认单一扫码方式授权选项 默认参数取消掉手机号权限(如果有需要, 请单独设置)

func NewMultipleAuthorizeOption

func NewMultipleAuthorizeOption(redirectUri string) *AuthorizeOption

NewMultipleAuthorizeOption 创建H5页多登陆方式授权选项

func NewSingleAuthorizeOption

func NewSingleAuthorizeOption() *AuthorizeOption

NewSingleAuthorizeOption 创建单一扫码方式授权选项

func (*AuthorizeOption) SetScopes

func (option *AuthorizeOption) SetScopes(scopes []Scope) *AuthorizeOption

SetScopes 设置授权范围

func (*AuthorizeOption) SetState

func (option *AuthorizeOption) SetState(state string) *AuthorizeOption

SetState 设置防止CSRF攻击

func (*AuthorizeOption) SetWidthAndHeight added in v0.0.4

func (option *AuthorizeOption) SetWidthAndHeight(width, height int) *AuthorizeOption

type AuthorizeQRCode

type AuthorizeQRCode struct {
	QrCodeUrl string `json:"qrCodeUrl"`
	Sid       string `json:"sid"`
	ErrorInfo
}

AuthorizeQRCode 授权二维码数据

type AuthorizeQRCodeStatus

type AuthorizeQRCodeStatus struct {
	Status   string `json:"status"` //状态有三种: waiting, success, failed
	AuthCode string `json:"authCode"`
	ErrorInfo
}

type CheckNameMode

type CheckNameMode string

CheckNameMode 重命名时检查文件名模式

const (
	CheckNameModeRefuse     CheckNameMode = "refuse"      // 重名时拒绝创建文件
	CheckNameModeAutoRename CheckNameMode = "auto_rename" //自动重命名
	CheckNameModeIgnore     CheckNameMode = "ignore"      //允许重命名
)

type Client

type Client struct {
	ClientId     string //开放平台应用ID
	ClientSecret string //开放平台应用密钥
	DriveID      string //阿里云盘ID
}

func NewClient

func NewClient(clientID, secret string) *Client

func (*Client) Authorize

func (c *Client) Authorize(authCode string) (result Authorize, err error)

Authorize 授权登录

func (*Client) AuthorizeURL

func (c *Client) AuthorizeURL(option *AuthorizeOption) (authURL string, err error)

AuthorizeURL 构建 H5前端 授权页面. 需要一个回调地址接收 code 拼接示例 https://openapi.aliyundrive.com/oauth/authorize?client_id=xxx&redirect_uri=xxx&scope=user:base,user:phone,file:all:read,file:all:write&state=xxx

func (*Client) QRCode

func (c *Client) QRCode(option *AuthorizeOption) (result AuthorizeQRCode, err error)

QRCode 获取登录二维码信息

func (*Client) QrCodeStatus

func (c *Client) QrCodeStatus(sid string) (result AuthorizeQRCodeStatus, err error)

QrCodeStatus 获取二维码状态

func (*Client) ReceiveAuthorizeCode added in v0.0.4

func (c *Client) ReceiveAuthorizeCode(req *http.Request) (result Authorize, err error)

ReceiveAuthorizeCode 接收前端授权 code, 并获得授权

func (*Client) RefreshToken

func (c *Client) RefreshToken(refreshToken string) (result Authorize, err error)

RefreshToken 刷新 token

type DriveInfo

type DriveInfo struct {
	Avatar         string        `json:"avatar"`
	Email          string        `json:"email"`
	Phone          string        `json:"phone"`
	Role           string        `json:"role"`
	Status         string        `json:"status"`
	Description    string        `json:"description"`
	Punishments    []interface{} `json:"punishments"`
	PunishFlagEnum int           `json:"punishFlagEnum"`
	UserId         string        `json:"user_id"`
	DomainId       string        `json:"domain_id"`
	UserName       string        `json:"user_name"`
	NickName       string        `json:"nick_name"`
	DefaultDriveId string        `json:"default_drive_id"`
	CreatedAt      int64         `json:"created_at"`
	UpdatedAt      int64         `json:"updated_at"`
	UserData       struct {
		BackUpConfig struct {
			// contains filtered or unexported fields
		} `json:"back_up_config"`
	} `json:"user_data"`
	PunishFlag int `json:"punish_flag"`
	ErrorInfo
}

DriveInfo 云盘信息

type ErrorInfo

type ErrorInfo struct {
	Code      string `json:"code,omitempty"`
	Message   string `json:"message,omitempty"`
	RequestId string `json:"requestId,omitempty"`
}

type FileCategory

type FileCategory string

FileCategory 返回文件类型分类

const (
	FileCategoryVideo  FileCategory = "video"  // 视频
	FileCategoryAudio  FileCategory = "audio"  // 音频
	FileCategoryImage  FileCategory = "image"  // 图片
	FileCategoryDoc    FileCategory = "doc"    // 文档
	FileCategoryZip    FileCategory = "zip"    // 压缩包
	FileCategoryOthers FileCategory = "others" // 其他
)

func (FileCategory) String

func (fc FileCategory) String() string

type FileCreate

type FileCreate struct {
	DriveId      string `json:"drive_id"`
	FileId       string `json:"file_id"`
	ParentFileId string `json:"parent_file_id"`
	FileName     string `json:"file_name"`

	Trashed         interface{} `json:"trashed"`
	Name            interface{} `json:"name"`
	Thumbnail       interface{} `json:"thumbnail"`
	Type            string      `json:"type"`
	Category        interface{} `json:"category"`
	Hidden          interface{} `json:"hidden"`
	Status          interface{} `json:"status"`
	Description     interface{} `json:"description"`
	Meta            interface{} `json:"meta"`
	Url             interface{} `json:"url"`
	Size            interface{} `json:"size"`
	Starred         interface{} `json:"starred"`
	Available       interface{} `json:"available"`
	Exist           interface{} `json:"exist"`
	UserTags        interface{} `json:"user_tags"`
	MimeType        interface{} `json:"mime_type"`
	FileExtension   interface{} `json:"file_extension"`
	RevisionId      string      `json:"revision_id"`
	ContentHash     interface{} `json:"content_hash"`
	ContentHashName interface{} `json:"content_hash_name"`
	EncryptMode     string      `json:"encrypt_mode"`
	DomainId        string      `json:"domain_id"`
	DownloadUrl     interface{} `json:"download_url"`
	UserMeta        interface{} `json:"user_meta"`
	ContentType     interface{} `json:"content_type"`
	CreatedAt       interface{} `json:"created_at"`
	UpdatedAt       interface{} `json:"updated_at"`
	LocalCreatedAt  interface{} `json:"local_created_at"`
	LocalModifiedAt interface{} `json:"local_modified_at"`
	TrashedAt       interface{} `json:"trashed_at"`
	PunishFlag      interface{} `json:"punish_flag"`
	UploadId        string      `json:"upload_id"`
	Location        string      `json:"location"`
	RapidUpload     bool        `json:"rapid_upload"`
	PartInfoList    []struct {
		Etag        interface{} `json:"etag"`
		PartNumber  int         `json:"part_number"`
		PartSize    interface{} `json:"part_size"`
		UploadUrl   string      `json:"upload_url"`
		ContentType string      `json:"content_type"`
	} `json:"part_info_list"`

	ErrorInfo
}

type FileDownloadURL

type FileDownloadURL struct {
	URL        string    `json:"url"`
	Expiration string    `json:"expiration"`
	ExpireTime time.Time `json:"expire_time"`
	ErrorInfo
}

type FileInfo

type FileInfo struct {
	Trashed            bool      `json:"trashed"`
	DriveId            string    `json:"drive_id"`
	FileId             string    `json:"file_id"`
	Category           string    `json:"category,omitempty"`
	ContentHash        string    `json:"content_hash,omitempty"`
	ContentHashName    string    `json:"content_hash_name,omitempty"`
	ContentType        string    `json:"content_type,omitempty"`
	Crc64Hash          string    `json:"crc64_hash,omitempty"`
	CreatedAt          time.Time `json:"created_at"`
	DomainId           string    `json:"domain_id"`
	DownloadUrl        string    `json:"download_url,omitempty"` // Deprecated: download_url 即将废弃
	EncryptMode        string    `json:"encrypt_mode"`
	FileExtension      string    `json:"file_extension,omitempty"`
	Hidden             bool      `json:"hidden"`
	MimeType           string    `json:"mime_type,omitempty"`
	Name               string    `json:"name"`
	ParentFileId       string    `json:"parent_file_id"`
	PunishFlag         int       `json:"punish_flag,omitempty"`
	Size               int64     `json:"size,omitempty"`
	Starred            bool      `json:"starred"`
	Status             string    `json:"status"`
	Thumbnail          string    `json:"thumbnail,omitempty"`
	Type               FileType  `json:"type"`
	UpdatedAt          time.Time `json:"updated_at"`
	Url                string    `json:"url,omitempty"`
	UserMeta           string    `json:"user_meta,omitempty"`
	SyncFlag           bool      `json:"sync_flag,omitempty"`
	VideoMediaMetadata struct {
		Duration              string `json:"duration"`
		Height                int    `json:"height"`
		VideoMediaAudioStream []struct {
			BitRate       string `json:"bit_rate"`
			ChannelLayout string `json:"channel_layout"`
			Channels      int    `json:"channels"`
			CodeName      string `json:"code_name"`
			Duration      string `json:"duration"`
			SampleRate    string `json:"sample_rate"`
		} `json:"video_media_audio_stream"`
		VideoMediaVideoStream []struct {
			Bitrate  string `json:"bitrate"`
			Clarity  string `json:"clarity"`
			CodeName string `json:"code_name"`
			Duration string `json:"duration"`
			Fps      string `json:"fps"`
		} `json:"video_media_video_stream"`
		Width int `json:"width"`
	} `json:"video_media_metadata,omitempty"`
	ExFieldsInfo struct {
	} `json:"ex_fields_info,omitempty"`
	ErrorInfo
}

func (*FileInfo) IsDir

func (f *FileInfo) IsDir() bool

type FileList

type FileList struct {
	Items      []FileInfo `json:"items"`
	NextMarker string     `json:"next_marker"`
	ErrorInfo
}

type FileMoveCopyDelTask

type FileMoveCopyDelTask struct {
	DriveID     string `json:"drive_id"`
	FileID      string `json:"file_id"`
	AsyncTaskID string `json:"async_task_id"`
	Exist       bool   `json:"exist"`
	ErrorInfo
}

type FileOption

type FileOption struct {
	DriveID             string               `json:"drive_id"`              // 云盘ID(必填)
	ParentFileID        string               `json:"parent_file_id"`        // 目录ID(目录/必填)
	FileID              string               `json:"file_id,omitempty"`     // 文件ID(文件必填)
	Name                string               `json:"name"`                  // 文件名(重命名必填)
	Path                string               `json:"path"`                  // 文件完整路径(不包括 /root)
	ExpireSec           int64                `json:"expire_sec"`            // 下载链接有效期(链接必填)
	URLExpireSec        int64                `json:"url_expire_sec"`        // 视频播放地址有效期(播放必填)
	ToParentFileID      string               `json:"to_parent_file_id"`     // 移动到的目录ID(移动必填)
	CheckNameMode       CheckNameMode        `json:"check_name_mode"`       // 重命名时检查文件名模式(重命名)
	NewName             string               `json:"new_name"`              // 移动时重名时的新文件名(移动)
	Marker              string               `json:"marker"`                // 分页标记(目录)
	Limit               int64                `json:"limit"`                 // 分页大小(目录)
	OrderBy             OrderSortedField     `json:"order_by"`              // 排序字段(目录)
	OrderDirection      OrderSortedDirection `json:"order_direction"`       // 排序方式(目录)
	Category            string               `json:"category"`              // 指定返回的文件类型(目录/文件)
	Type                FileType             `json:"type"`                  // 指定返回文件还是目录, type不为空时, category参数无效(目录)
	VideoThumbnailTime  int64                `json:"video_thumbnail_time"`  // 视频预览时间 (单位:秒) (目录/文件)
	VideoThumbnailWidth int64                `json:"video_thumbnail_width"` // 视频预览宽度 (目录/文件)
	ImageThumbnailWidth int64                `json:"image_thumbnail_width"` // 视频预览图片宽度 (目录/文件)
	Fields              string               `json:"fields"`                // 只返回指定字段 (目录)
	//ParallelUpload      bool                 `json:"parallel_upload"`       // Deprecated: 并发上传已经停止支持
	PartInfoList []FileUpdatePartInfo `json:"part_info_list"` // 分片上传信息(上传)
	OpenFile     *os.File             `json:"-"`              // 文件流(上传)
	UploadID     string               `json:"upload_id"`      // 上传ID(上传)
}

FileOption 文件列表参数

func NewFileCreateOption

func NewFileCreateOption(parentFileID, name string) *FileOption

NewFileCreateOption 创建文件参数

func NewFileDownloadURLOption

func NewFileDownloadURLOption(fileID string) *FileOption

NewFileDownloadURLOption 创建获取单个文件下载链接默认参数

func NewFileListOption

func NewFileListOption(parentFileID, marker string) *FileOption

NewFileListOption 创建默认文件列表参数

func NewFileMoveAndCopyOption

func NewFileMoveAndCopyOption(fileID, toParentFileID string) *FileOption

NewFileMoveAndCopyOption 创建文件复制/移动参数

func NewFileOption

func NewFileOption(fileID string) *FileOption

NewFileOption 创建获取单个文件默认参数

func NewFileOptionByPath added in v0.0.6

func NewFileOptionByPath(path string) *FileOption

NewFileOptionByPath 根据文件路径获取文件信息

func NewFileRenameOption

func NewFileRenameOption(fileID, newName string) *FileOption

NewFileRenameOption 创建重命名参数

func NewFileTrashAndDeleteOption

func NewFileTrashAndDeleteOption(fileID string) *FileOption

NewFileTrashAndDeleteOption 创建文件删除参数

func NewFileUploadOption

func NewFileUploadOption(parentFileID, name string, of *os.File) *FileOption

NewFileUploadOption 创建文件上传参数

func NewFileVideoPlayInfoOption

func NewFileVideoPlayInfoOption(fileID string) *FileOption

NewFileVideoPlayInfoOption 创建获取视频播放信息参数

func NewFilesOption

func NewFilesOption(fileIDs []string) (options []*FileOption)

NewFilesOption 创建获取多个文件默认参数

func (*FileOption) SetCategory

func (option *FileOption) SetCategory(category []FileCategory) *FileOption

SetCategory 设置返回文件类型分类

func (*FileOption) SetCheckNameMode

func (option *FileOption) SetCheckNameMode(checkNameMode CheckNameMode) *FileOption

SetCheckNameMode 设置重命名时检查文件名模式

func (*FileOption) SetDriveID added in v0.0.6

func (option *FileOption) SetDriveID(driveID string) *FileOption

SetDriveID 设置目录ID

func (*FileOption) SetExpireSec

func (option *FileOption) SetExpireSec(expireSec int64) *FileOption

SetExpireSec 设置下载链接有效期

func (*FileOption) SetFields added in v0.0.6

func (option *FileOption) SetFields(fields []string) *FileOption

SetFields 设置返回字段

func (*FileOption) SetFileID

func (option *FileOption) SetFileID(fileID string) *FileOption

SetFileID 设置文件ID

func (*FileOption) SetFilePath added in v0.0.6

func (option *FileOption) SetFilePath(path string) *FileOption

SetFilePath 设置文件ID

func (*FileOption) SetLimit

func (option *FileOption) SetLimit(limit int64) *FileOption

SetLimit 设置分页大小

func (*FileOption) SetMarker

func (option *FileOption) SetMarker(marker string) *FileOption

SetMarker 设置分页标记

func (*FileOption) SetName

func (option *FileOption) SetName(name string) *FileOption

SetName 设置文件名

func (*FileOption) SetNewName

func (option *FileOption) SetNewName(newName string) *FileOption

SetNewName 设置移动时重名时的新文件名

func (*FileOption) SetOrder

func (option *FileOption) SetOrder(direction OrderSortedDirection) *FileOption

SetOrder 设置排序方式

func (*FileOption) SetOrderBy

func (option *FileOption) SetOrderBy(orderBy OrderSortedField) *FileOption

SetOrderBy 设置排序字段

func (*FileOption) SetParentFileID

func (option *FileOption) SetParentFileID(parentFileID string) *FileOption

SetParentFileID 设置目录ID

func (*FileOption) SetResponseFields

func (option *FileOption) SetResponseFields(fields []ResponseFieldName) *FileOption

SetResponseFields 设置返回字段

func (*FileOption) SetThumbnailWidth

func (option *FileOption) SetThumbnailWidth(width int64) *FileOption

SetThumbnailWidth 设置视频预览宽度

func (*FileOption) SetType

func (option *FileOption) SetType(fileType FileType) *FileOption

SetType 设置返回文件类型

func (*FileOption) SetURLExpireSec

func (option *FileOption) SetURLExpireSec(urlExpireSec int64) *FileOption

SetURLExpireSec 设置视频播放地址有效期

func (*FileOption) SetUploadOpenFile

func (option *FileOption) SetUploadOpenFile(f *os.File) *FileOption

SetUploadOpenFile 设置上传数据流

func (*FileOption) SetVideoThumbnailTime

func (option *FileOption) SetVideoThumbnailTime(time int64) *FileOption

SetVideoThumbnailTime 设置视频预览时间

type FileType

type FileType string

FileType 返回文件类型

const (
	FileTypeAll    FileType = "all"    // 所有
	FileTypeFile   FileType = "file"   // 文件
	FileTypeFolder FileType = "folder" // 目录
)

type FileUpdatePartInfo

type FileUpdatePartInfo struct {
	ParallelSha1Ctx ParallelSha1Ctx `json:"parallel_sha1_ctx"` // 分片sha1
	PartNumber      int64           `json:"part_number"`       // 分片序号

}

FileUpdatePartInfo 分片上传选项

type FileVideoPlayInfo

type FileVideoPlayInfo struct {
	DriveId              string `json:"drive_id"`
	FileId               string `json:"file_id"`
	VideoPreviewPlayInfo struct {
		Category string `json:"category"`
		Meta     struct {
			Duration float64 `json:"duration"`
			Width    int     `json:"width"`
			Height   int     `json:"height"`
		} `json:"meta"`
		LiveTranscodingTaskList []struct {
			TemplateId     string `json:"template_id"`
			TemplateName   string `json:"template_name"`
			TemplateWidth  int    `json:"template_width"`
			TemplateHeight int    `json:"template_height"`
			Status         string `json:"status"`
			Stage          string `json:"stage"`
			Url            string `json:"url"`
		} `json:"live_transcoding_task_list"`
	} `json:"video_preview_play_info"`
	ErrorInfo
}

type OrderSortedDirection

type OrderSortedDirection string

OrderSortedDirection 排序方式

const (
	OrderSortedDirectionAsc  OrderSortedDirection = "ASC"
	OrderSortedDirectionDesc OrderSortedDirection = "DESC"
)

type OrderSortedField

type OrderSortedField string

OrderSortedField 排序字段

const (
	OrderFieldCreated OrderSortedField = "created_at"
	OrderFieldUpdate  OrderSortedField = "updated_at"
	OrderFieldSize    OrderSortedField = "size"
	OrderFieldName    OrderSortedField = "name"
)

type ParallelSha1Ctx

type ParallelSha1Ctx struct {
	PartOffset int64    `json:"part_offset"` // 分片偏移量
	PartSize   int64    `json:"part_size"`   // 分片大小
	H          []uint32 `json:"h"`           // 分片sha1
}

type ResponseFieldName

type ResponseFieldName string

ResponseFieldName 指定返回的字段类型

const (
	ResponseFieldURL           ResponseFieldName = "url"
	ResponseFieldThumbnail     ResponseFieldName = "thumbnail"
	ResponseFieldVideoMetadata ResponseFieldName = "video_metadata"
)

func (ResponseFieldName) String

func (rf ResponseFieldName) String() string

type Scope

type Scope string

Scope AuthorizeOption 授权类型

const (
	ScopeBase  Scope = "user:base"                                         // 授权获取用户ID, 头像, 昵称
	ScopePhone Scope = "user:phone"                                        // 获取手机号
	ScopeRead  Scope = "file:all:read"                                     // 所有文件读取权限
	ScopeWrite Scope = "file:all:write"                                    // 所有文件写入权限
	ScopeAll   Scope = "file:all:read,file:all:write,user:base,user:phone" // 所有权限
)

func (Scope) String

func (s Scope) String() string

type SpaceInfo

type SpaceInfo struct {
	PersonalSpaceInfo struct {
		UsedSize  int64 `json:"used_size"`
		TotalSize int64 `json:"total_size"`
	} `json:"personal_space_info"`
	ErrorInfo
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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