Documentation ¶
Index ¶
- Constants
- Variables
- func ChecksumFileSha1(file *os.File) (string, error)
- func Min(lhs, rhs int64) int64
- func PrefixSlash(path string) string
- func RemovePrefixSlash(path string) string
- func ToMD5(content string) string
- func ToSHA1WithReader(content io.Reader) (string, error)
- type AliyunDrive
- func (d *AliyunDrive) AddCredential(credential *Credential) (*Credential, error)
- func (d *AliyunDrive) CompleteUpload(credential *Credential, fileId, uploadId string) (*models.CompleteFileUploadResponse, error)
- func (d *AliyunDrive) ComputePreHash(content io.Reader) (string, error)
- func (d *AliyunDrive) ComputeProofCodeV1(credential *Credential, file *os.File, size int64) (string, error)
- func (d *AliyunDrive) CreateDirectory(credential *Credential, parentFileId, name string) (*models.File, error)
- func (d *AliyunDrive) CreateWithFolders(credential *Credential, options *CreateWithFoldersOptions) (http.Response, error)
- func (d *AliyunDrive) Download(credential *Credential, fileId, requestRange string) (*http2.Response, error)
- func (d *AliyunDrive) EvictCacheWithPrefix(keyPrefix string) int
- func (d *AliyunDrive) GetByPath(credential *Credential, fullPath string) (*models.FileResponse, error)
- func (d *AliyunDrive) GetCredentialFromUserId(userId string) *Credential
- func (d *AliyunDrive) GetDownloadURL(credential *Credential, fileId string) (*models.DownloadURLResponse, error)
- func (d *AliyunDrive) GetFile(credential *Credential, fileId string) (*models.FileResponse, error)
- func (d *AliyunDrive) GetFolderFiles(credential *Credential, options *FolderFilesOptions) (*models.FolderFilesResponse, error)
- func (d *AliyunDrive) GetUserInfo(credential *Credential) (*models.UserInfo, error)
- func (d *AliyunDrive) GetVideoPreviewPlayInfo(credential *Credential, fileId string) (*models.VideoPreviewPlayInfoResponse, error)
- func (d *AliyunDrive) GetVideoPreviewUrl(credential *Credential, fileId string) (*models.VideoPreviewUrlResponse, error)
- func (d *AliyunDrive) MoveFile(credential *Credential, fileId, toParentFileId string) (*http.BaseResponse, error)
- func (d *AliyunDrive) PartUpload(credential *Credential, uploadUrl string, reader io.Reader, ...) error
- func (d *AliyunDrive) RefreshAllToken()
- func (d *AliyunDrive) RefreshToken(credential *Credential) (*models.RefreshTokenResponse, error)
- func (d *AliyunDrive) RemoveFile(credential *Credential, fileId string) (*http.BaseResponse, error)
- func (d *AliyunDrive) RenameFile(credential *Credential, fileId, name string) (*models.RenameFileResponse, error)
- func (d *AliyunDrive) ResolvePathToFileId(credential *Credential, fullpath string) (string, string, error)
- func (d *AliyunDrive) Search(credential *Credential, keyword, marker string) (*models.SearchResponse, error)
- func (d *AliyunDrive) SearchNameInFolder(credential *Credential, name, parentFileId string) (*models.SearchResponse, error)
- func (d *AliyunDrive) UploadFile(credential *Credential, options *UploadFileOptions) (*models.File, error)
- func (d *AliyunDrive) UploadFileRapid(credential *Credential, options *UploadFileRapidOptions) (file *models.File, rapid bool, err error)
- type CreateWithFoldersOptions
- type Credential
- type FolderFilesOptions
- type Options
- type ProgressCallback
- type ProgressInfo
- type RateLimiterReader
- type UploadFileOptions
- type UploadFileRapidOptions
Constants ¶
const (
DefaultRootFileId = "root"
)
const (
// ThunkSizeDefault 默认 10MB 大小
ThunkSizeDefault = 1024 * 1024 * 10
)
Variables ¶
var ErrPartialFoundPath = errors.New("partial found: only found partial parent")
Functions ¶
func PrefixSlash ¶
func RemovePrefixSlash ¶
Types ¶
type AliyunDrive ¶
type AliyunDrive struct { Credentials map[string]*Credential // contains filtered or unexported fields }
func NewClient ¶
func NewClient(options *Options) *AliyunDrive
func (*AliyunDrive) AddCredential ¶
func (d *AliyunDrive) AddCredential(credential *Credential) (*Credential, error)
AddCredential 增加新的 Credential,同时刷新 RefreshToken
func (*AliyunDrive) CompleteUpload ¶
func (d *AliyunDrive) CompleteUpload(credential *Credential, fileId, uploadId string) (*models.CompleteFileUploadResponse, error)
CompleteUpload 完成分片上传后,通过此接口结束上传(合并分片)
func (*AliyunDrive) ComputePreHash ¶
func (d *AliyunDrive) ComputePreHash(content io.Reader) (string, error)
ComputePreHash 计算文件 PreHash,只计算前 1KB 的 SHA1
func (*AliyunDrive) ComputeProofCodeV1 ¶
func (d *AliyunDrive) ComputeProofCodeV1(credential *Credential, file *os.File, size int64) (string, error)
ComputeProofCodeV1 计算上传的 proof_code, version=v1 proof code 是文件内容的部分片段,主要用于实现秒传 算法:使用 AccessToken MD5 值的前 16 位 HEX 值转换为十进制数并对文件大小取模, 结果作为 proof code 的获取起始位置,取文件内容 8 位 byte 并用 Base64 编码
func (*AliyunDrive) CreateDirectory ¶
func (d *AliyunDrive) CreateDirectory(credential *Credential, parentFileId, name string) (*models.File, error)
CreateDirectory 创建目录
func (*AliyunDrive) CreateWithFolders ¶
func (d *AliyunDrive) CreateWithFolders(credential *Credential, options *CreateWithFoldersOptions) (http.Response, error)
CreateWithFolders 在目录下创建文件,如果非秒传,接下来需要分片上传 响应内容中,如果需要上传,则从 PartInfoList 中获取分片上传地址信息
func (*AliyunDrive) Download ¶
func (d *AliyunDrive) Download(credential *Credential, fileId, requestRange string) (*http2.Response, error)
Download 下载文件
func (*AliyunDrive) EvictCacheWithPrefix ¶
func (d *AliyunDrive) EvictCacheWithPrefix(keyPrefix string) int
EvictCacheWithPrefix 失效 Key 前缀为 keyPrefix 的缓存
func (*AliyunDrive) GetByPath ¶
func (d *AliyunDrive) GetByPath(credential *Credential, fullPath string) (*models.FileResponse, error)
GetByPath 通过 Path 取得文件信息,不存在则错误
func (*AliyunDrive) GetCredentialFromUserId ¶
func (d *AliyunDrive) GetCredentialFromUserId(userId string) *Credential
GetCredentialFromUserId 通过 UserId 取 Credential
func (*AliyunDrive) GetDownloadURL ¶
func (d *AliyunDrive) GetDownloadURL(credential *Credential, fileId string) (*models.DownloadURLResponse, error)
GetDownloadURL 获取下载路经 https://www.aliyundrive.com 获取的 RefreshToken 得到的 URL 需要带 Referrer 下载 移动端 Web 或手机端获取的 RefreshToken 得到的 URL可以直链下载
func (*AliyunDrive) GetFile ¶
func (d *AliyunDrive) GetFile(credential *Credential, fileId string) (*models.FileResponse, error)
GetFile 获取文件信息
func (*AliyunDrive) GetFolderFiles ¶
func (d *AliyunDrive) GetFolderFiles(credential *Credential, options *FolderFilesOptions) (*models.FolderFilesResponse, error)
GetFolderFiles 获取指定目录下的文件列表
func (*AliyunDrive) GetUserInfo ¶
func (d *AliyunDrive) GetUserInfo(credential *Credential) (*models.UserInfo, error)
GetUserInfo get user information
func (*AliyunDrive) GetVideoPreviewPlayInfo ¶
func (d *AliyunDrive) GetVideoPreviewPlayInfo(credential *Credential, fileId string) (*models.VideoPreviewPlayInfoResponse, error)
GetVideoPreviewPlayInfo 获取视频播放信息
func (*AliyunDrive) GetVideoPreviewUrl ¶
func (d *AliyunDrive) GetVideoPreviewUrl(credential *Credential, fileId string) (*models.VideoPreviewUrlResponse, error)
GetVideoPreviewUrl 获取视频预览 URL
func (*AliyunDrive) MoveFile ¶
func (d *AliyunDrive) MoveFile(credential *Credential, fileId, toParentFileId string) (*http.BaseResponse, error)
MoveFile 移动单个文件
func (*AliyunDrive) PartUpload ¶
func (d *AliyunDrive) PartUpload(credential *Credential, uploadUrl string, reader io.Reader, callback ProgressCallback) error
PartUpload 分片数据上传 因服务端使用流式计算 SHA1 值,单个文件的分片需要串行上传,不支持多个分片平行上传
func (*AliyunDrive) RefreshAllToken ¶ added in v1.0.1
func (d *AliyunDrive) RefreshAllToken()
func (*AliyunDrive) RefreshToken ¶
func (d *AliyunDrive) RefreshToken(credential *Credential) (*models.RefreshTokenResponse, error)
RefreshToken 刷新 RefreshToken,更新 AccessToken 和 Credential 里的相关信息
func (*AliyunDrive) RemoveFile ¶
func (d *AliyunDrive) RemoveFile(credential *Credential, fileId string) (*http.BaseResponse, error)
RemoveFile 删除文件
func (*AliyunDrive) RenameFile ¶
func (d *AliyunDrive) RenameFile(credential *Credential, fileId, name string) (*models.RenameFileResponse, error)
RenameFile 重命名文件
func (*AliyunDrive) ResolvePathToFileId ¶
func (d *AliyunDrive) ResolvePathToFileId(credential *Credential, fullpath string) (string, string, error)
ResolvePathToFileId 通过路径查找 fileId 当查询出现错误时,返回 "","", err 当查找到路径前一部分时,返回 fileId, prefix, ErrPartialFoundPath 当全部找到时,返回 fileId, fullpath, nil
func (*AliyunDrive) Search ¶
func (d *AliyunDrive) Search(credential *Credential, keyword, marker string) (*models.SearchResponse, error)
Search 查找文件
func (*AliyunDrive) SearchNameInFolder ¶
func (d *AliyunDrive) SearchNameInFolder(credential *Credential, name, parentFileId string) (*models.SearchResponse, error)
SearchNameInFolder 在目录下查找文件名
func (*AliyunDrive) UploadFile ¶
func (d *AliyunDrive) UploadFile(credential *Credential, options *UploadFileOptions) (*models.File, error)
UploadFile 同步上传文件(非秒传)
func (*AliyunDrive) UploadFileRapid ¶
func (d *AliyunDrive) UploadFileRapid(credential *Credential, options *UploadFileRapidOptions) (file *models.File, rapid bool, err error)
UploadFileRapid 上传文件(秒传) 当文件较大(如1GB以上)时,计算整个文件的 sha1 将花费较大的资源。先执行预秒传匹配到可能的数据才执行秒传。
type Credential ¶
type Credential struct { UserId string Name string AccessToken string RefreshToken string RootFolder string DefaultDriveId string // contains filtered or unexported fields }
func NewCredential ¶
func NewCredential(credential *Credential) *Credential
func (*Credential) RegisterChangeEvent ¶
func (c *Credential) RegisterChangeEvent(fn func(credential *Credential)) *Credential
type FolderFilesOptions ¶
type Options ¶
type Options struct { AutoRefresh bool UploadRate int RefreshDuration string // 刷新周期,默认 @every 1h30m,支持 cron Credential []*Credential }
type ProgressCallback ¶
type ProgressInfo ¶
type RateLimiterReader ¶ added in v1.0.1
type UploadFileOptions ¶
type UploadFileOptions struct { Name string Size int64 ParentFileId string ProgressStart func(info *ProgressInfo) ProgressCallback ProgressCallback ProgressDone func(info *ProgressInfo) Reader io.Reader }
type UploadFileRapidOptions ¶
type UploadFileRapidOptions struct { UploadFileOptions File *os.File ContentHash string }