drive

package
v0.0.0-...-e191490 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package drive helps you to manage you aliyun drive files.

Index

Constants

View Source
const (
	FolderKind  = "folder"
	FileKind    = "file"
	AnyKind     = "any"
	MaxPartSize = 1024 * 1024 * 1024 // 1 GiB
	Hour        = 60 * 60
)

Variables

View Source
var (
	ErrorLivpUpload     = errors.New("uploading .livp to album is not supported")
	ErrorAlreadyExisted = errors.New("already existed")
	ErrorMissingFields  = errors.New("required fields: ParentId, Name")
)

Functions

func CalcSha1

func CalcSha1(in *os.File) (*os.File, string, error)

Types

type AlbumInfo

type AlbumInfo struct {
	Data struct {
		DriveId string `json:"driveId"`
	} `json:"data"`
}

type Config

type Config struct {
	RefreshToken   string `json:"refresh_token"`
	DeviceId       string `json:"device_id"`
	IsAlbum        bool   `json:"is_album,omitempty"`
	HttpClient     *http.Client
	OnRefreshToken func(refreshToken string)
	UseInternalUrl bool `json:"use_internal_url,omitempty"`
}

func (Config) String

func (config Config) String() string

type CreateDeviceSessionResult

type CreateDeviceSessionResult struct {
	Success bool `json:"success"`
}

type DownloadUrl

type DownloadUrl struct {
	Size        int64             `json:"size"`
	StreamsUrl  map[string]string `json:"streams_url,omitempty"`
	Url         string            `json:"url"`
	InternalUrl string            `json:"internal_url"`
	Expiration  string            `json:"expiration"` // 2006-01-02T15:04:05.999Z
}

type Drive

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

func (*Drive) About

func (drive *Drive) About(ctx context.Context) (*PersonalSpaceInfo, error)

func (*Drive) CalcProof

func (drive *Drive) CalcProof(fileSize int64, in *os.File) (string, error)
func (drive *Drive) CancelShareLink(ctx context.Context, shareID string) error

cancel shareLink by shareID

func (*Drive) Copy

func (drive *Drive) Copy(ctx context.Context, nodeId string, dstParentNodeId string, dstName string) (string, error)

https://help.aliyun.com/document_detail/175927.html#pdscopyfilerequest

func (*Drive) CreateFile

func (drive *Drive) CreateFile(ctx context.Context, node Node, in io.Reader) (string, error)

func (*Drive) CreateFileWithProof

func (drive *Drive) CreateFileWithProof(ctx context.Context, node Node, in io.Reader, sha1Code string, proofCode string) (string, error)

func (*Drive) CreateFolder

func (drive *Drive) CreateFolder(ctx context.Context, node Node) (string, error)

func (*Drive) CreateFolderRecursively

func (drive *Drive) CreateFolderRecursively(ctx context.Context, fullPath string) (string, error)
func (drive *Drive) CreateShareLink(ctx context.Context, node []Node, pwd string, expiresIn int64) (string, string, string, error)

create share link, para: ctx, file node list, pwd, expiresIn(second) return shareID, pwd, expiration

func (*Drive) GetShareInfo

func (drive *Drive) GetShareInfo(ctx context.Context, shareID string) (string, string, string, []string, error)

get share info by shareID return value may vary

func (*Drive) GetShareLinkByAnonymous

func (drive *Drive) GetShareLinkByAnonymous(ctx context.Context, shareID string) (Expiration string, Creator string, err error)

func (*Drive) GetShareToken

func (drive *Drive) GetShareToken(ctx context.Context, pwd string, shareID string) (shareToken string, error error)

get share_token using pwd and shareID How to use share_token: https://help.aliyun.com/document_detail/397603.html

func (*Drive) List

func (drive *Drive) List(nodeId string) Pager

func (*Drive) ListAll

func (drive *Drive) ListAll(ctx context.Context, nodeId string) ([]Node, error)
func (drive *Drive) ListShareLinks(ctx context.Context) ([]SharedFile, string, error)

func (*Drive) Move

func (drive *Drive) Move(ctx context.Context, nodeId string, dstParentNodeId string, dstName string) (string, error)

func (*Drive) Open

func (drive *Drive) Open(ctx context.Context, node *Node, headers map[string]string) (io.ReadCloser, error)

func (*Drive) Remove

func (drive *Drive) Remove(ctx context.Context, nodeId string) error

func (*Drive) Search

func (drive *Drive) Search(ctx context.Context, name string) ([]Node, error)

func (*Drive) String

func (drive *Drive) String() string

func (*Drive) Update

func (drive *Drive) Update(ctx context.Context, node Node) (string, error)

type FileProof

type FileProof struct {
	DriveID         string      `json:"drive_id"`
	PartInfoList    []*PartInfo `json:"part_info_list"`
	ParentFileID    string      `json:"parent_file_id"`
	Name            string      `json:"name"`
	Type            string      `json:"type"`
	CheckNameMode   string      `json:"check_name_mode"`
	Size            int64       `json:"size"`
	ContentHash     string      `json:"content_hash"`
	ContentHashName string      `json:"content_hash_name"`
	ProofCode       string      `json:"proof_code"`
	ProofVersion    string      `json:"proof_version"`
	Meta            string      `json:"meta,omitempty"`
}

type Fs

type Fs interface {
	About(ctx context.Context) (*PersonalSpaceInfo, error)
	Get(ctx context.Context, nodeId string) (*Node, error)
	GetByPath(ctx context.Context, fullPath string, kind string) (*Node, error)
	List(nodeId string) Pager
	ListAll(ctx context.Context, nodeId string) ([]Node, error)

	// CreateFolder creates a folder to aliyun drive.
	//
	// required Node fields: ParentId, Name.
	//
	// may return ErrorMissingFields if required fields are missing.
	CreateFolder(ctx context.Context, node Node) (nodeIdOut string, err error)
	Move(ctx context.Context, nodeId string, dstParentNodeId string, dstName string) (nodeIdOut string, err error)
	Remove(ctx context.Context, nodeId string) error
	Open(ctx context.Context, node *Node, headers map[string]string) (io.ReadCloser, error)

	// CreateFile puts a file to aliyun drive.
	//
	// required Node fields: ParentId, Name.
	//
	// may return ErrorMissingFields if required fields are missing.
	CreateFile(ctx context.Context, node Node, in io.Reader) (nodeIdOut string, err error)
	CalcProof(fileSize int64, in *os.File) (proof string, err error)

	// CreateFileWithProof puts a file to aliyun drive.
	//
	// required Node fields: ParentId, Name.
	//
	// may return ErrorMissingFields if required fields are missing.
	CreateFileWithProof(ctx context.Context, node Node, in io.Reader, sha1Code string, proofCode string) (nodeIdOut string, err error)
	Copy(ctx context.Context, nodeId string, dstParentNodeId string, dstName string) (nodeIdOut string, err error)
	CreateFolderRecursively(ctx context.Context, fullPath string) (nodeIdOut string, err error)
	Update(ctx context.Context, node Node) (nodeIdOut string, err error)

	CreateShareLink(ctx context.Context, node []Node, pwd string, expiresIn int64) (ShareID string, SharePwd string, Expiration string, err error)
	ListShareLinks(ctx context.Context) (items []SharedFile, nextMarker string, err error)
	GetShareInfo(ctx context.Context, shareID string) (ShareID string, Pwd string, Expiration string, FileIDList []string, err error)
	GetShareToken(ctx context.Context, pwd string, shareID string) (shareToken string, error error)
	CancelShareLink(ctx context.Context, shareID string) error
	GetShareLinkByAnonymous(ctx context.Context, shareID string) (Expiration string, Creator string, err error)
	Search(ctx context.Context, name string) ([]Node, error)
}

func NewFs

func NewFs(ctx context.Context, config *Config) (Fs, error)

type HTTPStatusError

type HTTPStatusError interface {
	error
	StatusCode() int
}

type ListNodes

type ListNodes struct {
	Items      []Node `json:"items"`
	NextMarker string `json:"next_marker"`
}

type ListSharedFile

type ListSharedFile struct {
	Items      []SharedFile `json:"items"`
	NextMarker string       `json:"next_marker"`
}

type Node

type Node struct {
	Url      string `json:"url,omitempty"`
	Type     string `json:"type"`                   // folder | file
	Hash     string `json:"content_hash,omitempty"` // sha1
	Name     string `json:"name"`
	NodeId   string `json:"file_id"`
	ParentId string `json:"parent_file_id,omitempty"`
	Size     int64  `json:"size,omitempty"`
	Updated  string `json:"updated_at"`
	Meta     string `json:"meta,omitempty"`
	// contains filtered or unexported fields
}

func (*Node) GetName

func (n *Node) GetName() string

func (*Node) GetTime

func (n *Node) GetTime() (time.Time, error)

func (*Node) IsDirectory

func (n *Node) IsDirectory() bool

func (Node) String

func (n Node) String() string

type NodeId

type NodeId struct {
	NodeId string `json:"file_id"`
}

type Pager

type Pager interface {
	Next() bool
	Nodes(ctx context.Context) ([]Node, error)
}

type PartInfo

type PartInfo struct {
	PartNumber        int    `json:"part_number"`
	UploadUrl         string `json:"upload_url"`
	InternalUploadURL string `json:"internal_upload_url"`
}

type PersonalInfo

type PersonalInfo struct {
	PersonalSpaceInfo PersonalSpaceInfo `json:"personal_space_info"`
}

type PersonalSpaceInfo

type PersonalSpaceInfo struct {
	Used  int64 `json:"used_size"`
	Total int64 `json:"total_size"`
}

type ProofResult

type ProofResult struct {
	PartInfoList []PartInfo `json:"part_info_list,omitempty"`
	Exist        bool       `json:"exist,omitempty"`
	FileId       string     `json:"file_id"`
	RapidUpload  bool       `json:"rapid_upload"`
	UploadId     string     `json:"upload_id"`
	FileName     string     `json:"file_name"`
}

type ShareToken

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

type SharedFile

type SharedFile struct {
	DriveID    string   `json:"drive_id,omitempty"`
	Pwd        string   `json:"share_pwd,omitempty"`
	ShareID    string   `json:"share_id"`
	Creator    string   `json:"creator,omitempty"`
	ShareName  string   `json:"share_name,omitempty"`
	Expiration string   `json:"expiration"`
	FileIDList []string `json:"file_id_list,omitempty"`
}

type Token

type Token struct {
	AccessToken  string `json:"access_token"`
	ExpiresIn    int64  `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
}

type User

type User struct {
	DriveId string `json:"default_drive_id"`
	UserId  string `json:"user_id"`
}

Jump to

Keyboard shortcuts

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