alipanopen

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 6 Imported by: 1

README

阿里云盘开放平台接口 SDK

Go Reference

阿里云盘开放接口官方文档: https://www.yuque.com/aliyundrive/zpfszx

Documentation

Index

Constants

View Source
const (
	ROOT_FOLDER_ID = "root" // 跟目录ID

	FILE_TYPE_FILE   = "file"   // 文件类型:文件
	FILE_TYPE_FOLDER = "folder" // 文件类型:文件夹

	CHECK_NAME_MODE_REFUSE = "refuse" // 重名检测策略:拒绝
)
View Source
const (
	ALIPAN_OPENAPI_HOST = "https://openapi.aliyundrive.com"

	HEADER_HOST          = "Host"
	HEADER_REFERER       = "Referer"
	HEADER_USER_AGENT    = "User-Agent"
	HEADER_RANGE         = "Range"
	HEADER_ACCEPT        = "Accept"
	HEADER_AUTHORIZATION = "Authorization"

	METHOD_GET  = "GET"
	METHOD_POST = "POST"

	API_OAUTH_USER_INFO        = "/oauth/users/info"
	API_GET_DRIVE_INFO         = "/adrive/v1.0/user/getDriveInfo"
	API_OAUTH_ACCESS_TOKEN     = "/oauth/access_token"
	API_OAUTH_AUTHORIZE_QRCODE = "/oauth/authorize/qrcode"
	API_FILE_GET               = "/adrive/v1.0/openFile/get"
	API_FILE_GET_BY_PATH       = "/adrive/v1.0/openFile/get_by_path"
	API_FILE_LIST              = "/adrive/v1.0/openFile/list"
	API_FILE_CREATE            = "/adrive/v1.0/openFile/create"
	API_FILE_DELETE            = "/adrive/v1.0/openFile/delete"
	API_FILE_TRASH             = "/adrive/v1.0/openFile/recyclebin/trash"
	API_FILE_COMPLETE          = "/adrive/v1.0/openFile/complete"
	API_FILE_MOVE              = "/adrive/v1.0/openFile/move"
	API_FILE_UPDATE            = "/adrive/v1.0/openFile/update"
	API_FILE_GET_UPLOAD_URL    = "/adrive/v1.0/openFile/getUploadUrl"
	API_FILE_GET_DOWNLOAD_URL  = "/adrive/v1.0/openFile/getDownloadUrl"
)
View Source
const (
	QRCODE_STATUS_WAITLOGIN     = "WaitLogin"     // 等待扫码
	QRCODE_STATUS_SCANSUCCESS   = "ScanSuccess"   // 已扫描
	QRCODE_STATUS_LOGINSUCCESS  = "LoginSuccess"  // 已授权登录
	QRCODE_STATUS_QRCODEEXPIRED = "QRCodeExpired" // 已过期
)

二维码状态

View Source
const (
	SCOPE_USER_BASE      = "user:base"      // 允许获取用户基础信息
	SCOPE_FILE_ALL_READ  = "file:all:read"  // 允许读用户文件
	SCOPE_FILE_ALL_WRITE = "file:all:write" // 允许写用户文件
)

权限信息

View Source
const (
	GRANT_TYPE_REFRESH_TOKEN      = "refresh_token"
	GRANT_TYPE_AUTHORIZATION_CODE = "authorization_code"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient() *Client

新建client

func (*Client) CompleteFile

func (client *Client) CompleteFile(ctx context.Context, reqBody *CompleteFileReq) (*CompleteFileResp, error)

完成文件创建

func (*Client) CreateFile

func (client *Client) CreateFile(ctx context.Context, reqBody *CreateFileReq) (*CreateFileResp, error)

创建文件

func (*Client) CreateFolder

func (client *Client) CreateFolder(ctx context.Context, reqBody *CreateFolderReq) (*File, error)

创建文件夹

func (*Client) DeleteFile

func (client *Client) DeleteFile(ctx context.Context, reqBody *DeleteFileReq) error

删除文件

func (*Client) GetAccessToken

func (client *Client) GetAccessToken() string

func (*Client) GetCurrentUser

func (client *Client) GetCurrentUser(ctx context.Context) (*User, error)

获取当前用户信息

func (*Client) GetDownloadUrl

func (client *Client) GetDownloadUrl(ctx context.Context, reqBody *GetFileDownloadUrlReq) (*GetFileDownloadUrlResp, error)

获取文件下载地址

func (*Client) GetDriveInfo

func (client *Client) GetDriveInfo(ctx context.Context) (*GetDriveInfoResp, error)

获取当前用户空间信息

func (*Client) GetFile added in v0.4.0

func (client *Client) GetFile(ctx context.Context, reqBody *GetFileReq) (*File, error)

获取文件详情

func (*Client) GetFileByPath added in v0.4.0

func (client *Client) GetFileByPath(ctx context.Context, reqBody *GetFileByPathReq) (*File, error)

通过文件路径获取文件详情

func (*Client) GetQrCode

func (client *Client) GetQrCode(ctx context.Context, reqBody *GetQrCodeReq) (*GetQrCodeResp, error)

获取二维码

func (*Client) GetQrCodeStatus

func (client *Client) GetQrCodeStatus(ctx context.Context, sid string) (*GetQrCodeStatusResp, error)

获取二维码状态

func (*Client) GetUploadUrl

func (client *Client) GetUploadUrl(ctx context.Context, reqBody *GetUploadUrlReq) (*GetUploadUrlResp, error)

获取文件上传地址

func (*Client) ListFile added in v0.4.1

func (client *Client) ListFile(ctx context.Context, reqBody *ListFileReq) (*ListFileResp, error)

列举文件夹下文件

func (*Client) MoveFile

func (client *Client) MoveFile(ctx context.Context, reqBody *MoveFileReq) error

移动文件

func (*Client) RefreshToken

func (client *Client) RefreshToken(ctx context.Context, reqBody *RefreshTokenReq) (*RefreshTokenResp, error)

刷新获取新的用户 token

func (*Client) SetAccessToken

func (client *Client) SetAccessToken(accessToken string)

func (*Client) SetHost

func (client *Client) SetHost(host string)

func (*Client) SetRestyClient

func (client *Client) SetRestyClient(restyClient *resty.Client)

func (*Client) TrashFile

func (client *Client) TrashFile(ctx context.Context, reqBody *TrashFileReq) error

将文件移入回收站

func (*Client) UpdateFileName

func (client *Client) UpdateFileName(ctx context.Context, reqBody *UpdateFileNameReq) error

更新文件名

type CompleteFileReq

type CompleteFileReq struct {
	DriveId  string `json:"drive_id"`
	FileId   string `json:"file_id"`
	UploadId string `json:"upload_id"`
}

type CompleteFileResp

type CompleteFileResp struct {
	ContentHash string `json:"content_hash"`
	Size        int64  `json:"size"`
}

type CreateFileReq

type CreateFileReq struct {
	Name            string `json:"name"`           // 文件名
	DriveId         string `json:"drive_id"`       // 文件所属空间ID
	ParentFileId    string `json:"parent_file_id"` // 文件ID
	Type            string `json:"type"`           // 文件类型
	ContentHash     string `json:"content_hash"`   // 文件内容sha1
	ContentHashName string `json:"content_hash_name"`
	CheckNameMode   string `json:"check_name_mode"` // 重名检测策略
	Size            int64  `json:"size"`            // 文件大小
}

type CreateFileResp

type CreateFileResp struct {
	DriveId      string           `json:"drive_id"`
	FileId       string           `json:"file_id"`
	UploadId     string           `json:"upload_id"`
	PartInfoList []UploadPartInfo `json:"part_info_list"`
}

type CreateFolderReq

type CreateFolderReq struct {
	Name          string `json:"name"`            // 文件夹名称
	DriveId       string `json:"drive_id"`        // 所属空间ID
	ParentFileId  string `json:"parent_file_id"`  // 父文件夹ID
	Type          string `json:"type"`            // 固定是 folder
	CheckNameMode string `json:"check_name_mode"` // 重名检测策略
}

type DeleteFileReq added in v0.3.0

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

type EmptyStruct

type EmptyStruct struct{}

type ErrorResponse

type ErrorResponse struct {
	StatusCode int    `json:"-"`
	Code       string `json:"code"`
	Message    string `json:"message"`
}

func (*ErrorResponse) Error added in v0.4.0

func (e *ErrorResponse) Error() string

type File

type File struct {
	FileName     string    `json:"name"`           // 名称
	FileSize     int64     `json:"size"`           // 大小
	UpdatedAt    time.Time `json:"updated_at"`     // 更新时间
	ContentHash  string    `json:"content_hash"`   // 文件内容sha1
	Type         string    `json:"type"`           // 文件类型
	DriveId      string    `json:"drive_id"`       // 所属空间ID
	FileId       string    `json:"file_id"`        // 文件ID
	ParentFileId string    `json:"parent_file_id"` // 父文件夹ID
}

文件模型

type GetDriveInfoResp

type GetDriveInfoResp struct {
	DefaultDriveId  string `json:"default_drive_id"`  // 默认空间ID
	ResourceDriveId string `json:"resource_drive_id"` // 资源库空间ID
	BackupDriveId   string `json:"backup_drive_id"`   // 备份盘空间ID
}

type GetFileByPathReq added in v0.4.0

type GetFileByPathReq struct {
	DriveId  string `json:"drive_id"`
	FilePath string `json:"file_path"`
}

type GetFileDownloadUrlReq added in v0.3.0

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

type GetFileDownloadUrlResp

type GetFileDownloadUrlResp struct {
	Url        string    `json:"url"`
	Expiration time.Time `json:"expiration"`
}

type GetFileReq added in v0.4.0

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

type GetQrCodeReq added in v0.3.0

type GetQrCodeReq struct {
	ClientId     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	Scopes       []string `json:"scopes"`
}

type GetQrCodeResp

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

type GetQrCodeStatusResp

type GetQrCodeStatusResp struct {
	Status   string `json:"status"`
	AuthCode string `json:"authCode"`
}

type GetUploadPartInfoReq

type GetUploadPartInfoReq struct {
	PartNumber int `json:"part_number"`
}

type GetUploadUrlReq

type GetUploadUrlReq struct {
	DriveId      string                 `json:"drive_id"`
	FileId       string                 `json:"file_id"`
	UploadId     string                 `json:"upload_id"`
	PartInfoList []GetUploadPartInfoReq `json:"part_info_list"`
}

type GetUploadUrlResp

type GetUploadUrlResp struct {
	DriveId      string           `json:"drive_id"`
	FileId       string           `json:"file_id"`
	UploadId     string           `json:"upload_id"`
	PartInfoList []UploadPartInfo `json:"part_info_list"`
}

type ListFileReq

type ListFileReq struct {
	DriveId      string `json:"drive_id"`
	ParentFileId string `json:"parent_file_id"`

	Limit  int    `json:"limit"`  // 单页数量
	Marker string `json:"marker"` // 分页用
}

type ListFileResp

type ListFileResp struct {
	Items      []*File `json:"items"`
	NextMarker string  `json:"next_marker"` // 分页用
}

type MoveFileReq

type MoveFileReq struct {
	DriveId string `json:"drive_id"`
	FileId  string `json:"file_id"`
	NewName string `json:"new_name"` // 新文件名

	CheckNameMode  string `json:"check_name_mode"`
	Overwrite      bool   `json:"overwrite"`
	ToParentFileId string `json:"to_parent_file_id"` // 目的文件夹ID
}

type RefreshTokenReq added in v0.3.0

type RefreshTokenReq struct {
	ClientId     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	GrantType    string `json:"grant_type"`
	RefreshToken string `json:"refresh_token"`
	Code         string `json:"code"`
}

type RefreshTokenResp

type RefreshTokenResp struct {
	AccessToken  string `json:"access_token"`  // 用户token
	RefreshToken string `json:"refresh_token"` // 刷新token
	ExpiresIn    int    `json:"expires_in"`    // 单位秒
}

type TrashFileReq added in v0.3.0

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

type UpdateFileNameReq

type UpdateFileNameReq struct {
	DriveId       string `json:"drive_id"`
	FileId        string `json:"file_id"`
	Name          string `json:"name"`
	CheckNameMode string `json:"check_name_mode"`
}

type UploadPartInfo

type UploadPartInfo struct {
	PartNumber int    `json:"part_number"`
	PartSize   int64  `json:"part_size"`
	UploadUrl  string `json:"upload_url"`
}

type User

type User struct {
	Id   string `json:"id"`   // 用户ID
	Name string `json:"name"` // 用户昵称
}

Jump to

Keyboard shortcuts

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