driver

package
v1.0.23 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 24 Imported by: 3

Documentation

Index

Examples

Constants

View Source
const (
	ApiGetVersion = "https://appversion.115.com/1/web/1.0/api/chrome"
	// login
	ApiLoginCheck = "https://passportapi.115.com/app/1.0/web/1.0/check/sso"
	ApiUserInfo   = "https://my.115.com/?ct=ajax&ac=nav"

	// dir
	ApiDirAdd = "https://webapi.115.com/files/add"

	// file
	ApiFileDelete = "https://webapi.115.com/rb/delete"
	ApiFileMove   = "https://webapi.115.com/files/move"
	ApiFileCopy   = "https://webapi.115.com/files/copy"
	ApiFileRename = "https://webapi.115.com/files/batch_rename"

	ApiFileList       = "https://webapi.115.com/files"
	ApiFileListByName = "https://aps.115.com/natsort/files.php"

	ApiFileStat = "https://webapi.115.com/category/get"
	ApiFileInfo = "https://webapi.115.com/files/get_info"

	// share
	ApiShareSnap = "https://webapi.115.com/share/snap"

	// download
	ApiDownloadGetUrl      = "https://proapi.115.com/app/chrome/downurl"
	ApiDownloadGetShareUrl = "https://proapi.115.com/app/share/downurl"

	// upload
	ApiUploadInfo        = "https://proapi.115.com/app/uploadinfo"
	ApiGetUploadEndpoint = "https://uplb.115.com/3.0/getuploadinfo.php"
	ApiUploadInit        = "https://uplb.115.com/4.0/initupload.php"

	// oss
	ApiUploadOSSToken = "https://uplb.115.com/3.0/gettoken.php"

	// qrcode
	ApiQrcodeToken        = "https://qrcodeapi.115.com/api/1.0/web/1.0/token"
	ApiQrcodeStatus       = "https://qrcodeapi.115.com/get/status/"
	ApiQrcodeLogin        = "https://passportapi.115.com/app/1.0/web/1.0/login/qrcode"
	ApiQrcodeLoginWithApp = "https://passportapi.115.com/app/1.0/%s/1.0/login/qrcode"
	ApiQrcodeImage        = "https://qrcodeapi.115.com/api/1.0/mac/1.0/qrcode?uid=%s"
)
View Source
const (
	UADefalut    = "Mozilla/5.0"
	UA115Browser = "Mozilla/5.0 115Browser/23.9.3.2"
	UA115Disk    = "Mozilla/5.0 115disk/30.1.0"
	UA115Desktop = "Mozilla/5.0 115Desktop/2.0.3.6"
	UAIosApp     = "Mozilla/5.0; Darwin/10.0; UDown/30.1.0"
)
View Source
const (
	CookieDomain115 = ".115.com"

	CookieUrl = "https://115.com"

	CookieNameUid  = "UID"
	CookieNameCid  = "CID"
	CookieNameSeid = "SEID"
)
View Source
const (
	OSSRegionID = "oss-cn-shenzhen"
	OSSEndpoint = "cn-shenzhen.oss.aliyuncs.com" // 双栈域名

	OSSUserAgent               = "aliyun-sdk-android/2.9.1"
	OssSecurityTokenHeaderName = "X-OSS-Security-Token"
)
View Source
const (
	KB = 1 << (10 * (iota + 1))
	MB
	GB
)
View Source
const (
	FileOrderByTime = "user_ptime"
	FileOrderByType = "file_type"
	FileOrderBySize = "file_size"
	FileOrderByName = "file_name"

	FileListLimit = int64(56)
)

Variables

View Source
var (
	ErrNotLogin = errors.New("user not login")

	ErrOfflineInvalidLink = errors.New("invalid download link")
	ErrOfflineTaskExisted = errors.New("offline task existed")

	ErrOrderNotSupport = errors.New("file order not supported")

	ErrPasswordIncorrect    = errors.New("password incorrect")
	ErrLoginTwoStepVerify   = errors.New("requires two-step verification")
	ErrAccountNotBindMobile = errors.New("account not binds mobile")
	ErrCredentialInvalid    = errors.New("credential invalid")
	ErrSessionExited        = errors.New("session exited")

	ErrQrcodeExpired = errors.New("qrcode expired")

	// ErrUnexpected is the fall-back error whose code is not handled.
	ErrUnexpected = errors.New("unexpected error")

	// ErrExist means an item which you want to create is already existed.
	ErrExist = errors.New("target already exists")
	// ErrNotExist means an item which you find is not existed.
	ErrNotExist = errors.New("target does not exist")

	ErrInvalidCursor = errors.New("invalid cursor")

	ErrUploadTooLarge = errors.New("upload reach the limit")

	ErrUploadFailed = errors.New("upload failed")

	ErrImportDirectory = errors.New("can not import directory")

	ErrDownloadEmpty = errors.New("can not get download URL")

	ErrDownloadDirectory = errors.New("can not download directory")

	ErrDownloadFileNotExistOrHasDeleted = errors.New("target file does not exist or has deleted")

	ErrDownloadFileTooBig = errors.New("target file is too big to download")

	ErrCyclicCopy = errors.New("cyclic copy")

	ErrCyclicMove = errors.New("cyclic move")

	ErrVideoNotReady = errors.New("video is not ready")

	ErrWrongParams = errors.New("wrong parameters")

	ErrRepeatLogin = errors.New("repeat login")

	ErrFailedToLogin = errors.New("failed to login")

	ErrDoesLoggedOut = errors.New("you have been kicked out by multi-device login management")

	ErrPickCodeNotExist = errors.New("pickcode does not exist")

	ErrSharedInvalid = errors.New("shared link invalid")

	ErrSharedNotFound = errors.New("shared link not found")

	ErrPickCodeIsEmpty = errors.New("empty pickcode")

	ErrUploadSH1Invalid = errors.New("userid/filesize/target/pickcode/ invalid")

	ErrUploadSigInvalid = errors.New("sig invalid")
)
View Source
var (
	LabelColors = []string{

		"#000000",

		"#FF4B30",

		"#F78C26",

		"#FFC032",

		"#43BA80",

		"#2670FC",

		"#8B69FE",

		"#CCCCCC",
	}

	LabelColorMap = map[string]int{
		"#000000": 0,
		"#FF4B30": 1,
		"#F78C26": 2,
		"#FFC032": 3,
		"#43BA80": 4,
		"#2670FC": 5,
		"#8B69FE": 6,
		"#CCCCCC": 7,
	}
)
View Source
var (
	ErrBadCookie = errors.New("bad cookie")
)

cookie err

Functions

func BoolToInt

func BoolToInt(b bool) int

func CheckErr

func CheckErr(err error, result ResultWithErr, restyResp *resty.Response) error

func Date added in v1.0.6

func Date() string

func GetErr

func GetErr(code int, respBody ...string) error

func OssOption added in v1.0.8

func OssOption(params *UploadOSSParams, ossToken *UploadOSSTokenResp) []oss.Option

OssOption get options

func SplitFile added in v1.0.8

func SplitFile(filePath string, fileSize int64) (chunks []oss.FileChunk, err error)

SplitFile pplitFile

Types

type BasicResp added in v1.0.6

type BasicResp struct {
	Errno   StringInt `json:"errno,omitempty"`
	ErrNo   int       `json:"errNo,omitempty"`
	Error   string    `json:"error,omitempty"`
	State   bool      `json:"state,omitempty"`
	Errtype string    `json:"errtype,omitempty"`
	Msg     string    `json:"msg,omitempty"`
}

func (*BasicResp) Err added in v1.0.6

func (resp *BasicResp) Err(respBody ...string) error

type BoolInt

type BoolInt int

func (*BoolInt) UnmarshalJSON

func (v *BoolInt) UnmarshalJSON(b []byte) (err error)

type Credential

type Credential struct {
	UID  string `json:"UID"`
	CID  string `json:"CID"`
	SEID string `json:"SEID"`
}

func (*Credential) FromCookie

func (cr *Credential) FromCookie(cookie string) error

FromCookie get uid, cid, seid from cookie string

type DataString added in v1.0.20

type DataString string

func (*DataString) UnmarshalJSON added in v1.0.20

func (v *DataString) UnmarshalJSON(b []byte) (err error)

type DirInfo added in v1.0.10

type DirInfo struct {
	// Directory ID.
	ID string
	// Directory Name.
	Name string
}

DirInfo only used in FileInfo.

type DownloadData added in v1.0.5

type DownloadData map[string]*DownloadInfo

type DownloadInfo added in v1.0.5

type DownloadInfo struct {
	FileName string          `json:"file_name"`
	FileSize StringInt64     `json:"file_size"`
	PickCode string          `json:"pick_code"`
	Url      FileDownloadUrl `json:"url"`
	Header   http.Header
}

func (*DownloadInfo) Get added in v1.0.7

func (info *DownloadInfo) Get() (io.ReadSeeker, error)

Get Download file from download info url

type DownloadResp added in v1.0.20

type DownloadResp struct {
	BasicResp
	EncodedData DataString `json:"data,omitempty"`
}

type File

type File struct {
	// Marks is the file a directory.
	IsDirectory bool
	// Unique identifier of the file on the cloud storage.
	FileID string
	// FileID of the parent directory.
	ParentID string

	// Base name of the file.
	Name string
	// Size in bytes of the file.
	Size int64
	// IDentifier used for downloading or playing the file.
	PickCode string
	// SHA1 hash of file content, in HEX format.
	Sha1 string

	// Is file stared
	Star bool
	// File labels
	Labels []*Label

	// Create time of the file.
	CreateTime time.Time
	// Update time of the file.
	UpdateTime time.Time
}

func (*File) From added in v1.0.23

func (f *File) From(fileInfo *FileInfo) *File

func (File) GetID added in v1.0.5

func (f File) GetID() string

func (File) GetName added in v1.0.5

func (f File) GetName() string

func (File) GetPath added in v1.0.5

func (f File) GetPath() string

func (File) GetSize added in v1.0.5

func (f File) GetSize() int64

func (File) IsDir added in v1.0.5

func (f File) IsDir() bool

func (File) ModTime added in v1.0.5

func (f File) ModTime() time.Time

type FileDownloadUrl added in v1.0.5

type FileDownloadUrl struct {
	Client float64 `json:"client"`
	OSSID  string  `json:"oss_id"`
	Url    string  `json:"url"`
}

type FileInfo

type FileInfo struct {
	AreaID     IntString `json:"aid"`
	CategoryID IntString `json:"cid"`
	FileID     string    `json:"fid"`
	ParentID   string    `json:"pid"`

	Name     string      `json:"n"`
	Type     string      `json:"ico"`
	Size     StringInt64 `json:"s"`
	Sha1     string      `json:"sha"`
	PickCode string      `json:"pc"`

	IsStar StringInt    `json:"m"`
	Labels []*LabelInfo `json:"fl"`

	CreateTime StringInt64 `json:"tp"`
	UpdateTime string      `json:"t"`
}

type FileListResp added in v1.0.6

type FileListResp struct {
	BasicResp

	AreaID     string    `json:"aid"`
	CategoryID IntString `json:"cid"`

	Count int    `json:"count"`
	Order string `json:"order"`
	IsAsc int    `json:"is_asc"`

	Offset   int `json:"offset"`
	Limit    int `json:"limit"`
	PageSize int `json:"page_size"`

	Files []FileInfo `json:"data"`
}

func GetFiles added in v1.0.3

func GetFiles(req *resty.Request, dirID string, opts ...GetFileOptions) (*FileListResp, error)

type FileParentInfo added in v1.0.10

type FileParentInfo struct {
	FileID   int    `json:"file_id"`
	FileName string `json:"file_name"`
}

type FileStatInfo added in v1.0.10

type FileStatInfo struct {
	// Base name of the file.
	Name string
	// Identifier used for downloading or playing the file.
	PickCode string
	// SHA1 hash of file content, in HEX format.
	Sha1 string
	// Marks is file a directory.
	IsDirectory bool
	// Files count under this directory.
	FileCount int
	// Subdirectories count under this directory.
	DirCount int

	// Create time of the file.
	CreateTime time.Time
	// Last update time of the file.
	UpdateTime time.Time

	// Parent directory list.
	Parents []*DirInfo
}

type FileStatResponse added in v1.0.10

type FileStatResponse struct {
	FileCount   StringInt         `json:"count"`
	Size        string            `json:"size"`
	FolderCount StringInt         `json:"folder_count"`
	CreateTime  StringInt64       `json:"ptime"`
	UpdateTime  StringInt64       `json:"utime"`
	IsShare     StringInt         `json:"is_share"`
	FileName    string            `json:"file_name"`
	PickCode    string            `json:"pick_code"`
	Sha1        string            `json:"sha1"`
	IsMark      StringInt         `json:"is_mark"`
	OpenTime    int64             `json:"open_time"`
	IsFile      StringInt         `json:"file_category"`
	Paths       []*FileParentInfo `json:"paths"`
}

func (*FileStatResponse) Err added in v1.0.10

func (r *FileStatResponse) Err(respBody ...string) error

type GetFileInfoResponse added in v1.0.10

type GetFileInfoResponse struct {
	BasicResp
	Files []*FileInfo `json:"data"`
}

type GetFileOption added in v1.0.6

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

GetFileOption get file options

func DefaultGetFileOptions added in v1.0.6

func DefaultGetFileOptions() *GetFileOption

func (*GetFileOption) GetAsc added in v1.0.6

func (o *GetFileOption) GetAsc() string

func (*GetFileOption) GetOffset added in v1.0.6

func (o *GetFileOption) GetOffset() string

func (*GetFileOption) GetOrder added in v1.0.6

func (o *GetFileOption) GetOrder() string

func (*GetFileOption) GetPageSize added in v1.0.6

func (o *GetFileOption) GetPageSize() string

func (*GetFileOption) GetshowDir added in v1.0.6

func (o *GetFileOption) GetshowDir() string

type GetFileOptions added in v1.0.6

type GetFileOptions func(o *GetFileOption)

func WithAsc added in v1.0.7

func WithAsc(d bool) GetFileOptions

func WithLimit added in v1.0.6

func WithLimit(pageSize int64) GetFileOptions

func WithOffset added in v1.0.6

func WithOffset(offset int64) GetFileOptions

func WithOrder added in v1.0.6

func WithOrder(order string) GetFileOptions

func WithShowDirEnable added in v1.0.6

func WithShowDirEnable(e bool) GetFileOptions

type IntString

type IntString string

func (*IntString) UnmarshalJSON

func (v *IntString) UnmarshalJSON(b []byte) (err error)

type Label

type Label struct {
	ID    string
	Name  string
	Color LabelColor
}

type LabelColor

type LabelColor int

type LabelInfo

type LabelInfo struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Color string `json:"color"`

	Sort StringInt `json:"sort"`

	CreateTime int64 `json:"create_time"`
	UpdateTime int64 `json:"update_time"`
}

type LoginApp added in v1.0.22

type LoginApp string
const (
	LoginAppWeb     LoginApp = "web"
	LoginAppAndroid LoginApp = "android"
	LoginAppIOS     LoginApp = "ios"
	LoginAppLinux   LoginApp = "linux"
	LoginAppMac     LoginApp = "mac"
	LoginAppWindows LoginApp = "windows"
	LoginAppTV      LoginApp = "tv"
)

type LoginResp

type LoginResp struct {
	Code     int  `json:"code"`
	CheckSsd bool `json:"check_ssd"`
	Data     struct {
		Expire int64  `json:"expire"`
		Link   string `json:"link"`
		UserID int64  `json:"user_id"`
	} `json:"data"`
	Errno   int    `json:"errno"`
	Error   string `json:"error"`
	Message string `json:"message"`
	State   int    `json:"state"`
	Expire  int    `json:"expire"`
}

func (*LoginResp) Err

func (resp *LoginResp) Err(respBody ...string) error

type MkdirResp

type MkdirResp struct {
	BasicResp
	AreaID IntString `json:"aid"`

	CategoryID   IntString `json:"cid"`
	CategoryName string    `json:"cname"`

	FileID   string `json:"file_id"`
	FileName string `json:"file_name"`
}

type Option

type Option func(c *Pan115Client)

Option driver client options

func InsecureSkipVerify added in v1.0.15

func InsecureSkipVerify(insecureSkipVerify bool) Option

func UA

func UA(userAgent ...string) Option

func WithClient added in v1.0.3

func WithClient(hc *http.Client) Option

func WithDebug added in v1.0.3

func WithDebug() Option

func WithProxy added in v1.0.3

func WithProxy(proxy string) Option

func WithRestyClient added in v1.0.3

func WithRestyClient(resty *resty.Client) Option

func WithTrace added in v1.0.3

func WithTrace() Option

type Pan115Client

type Pan115Client struct {
	Client            *resty.Client
	Request           *resty.Request
	UserID            int64
	Userkey           string
	UploadMetaInfo    *UploadMetaInfo
	UseInternalUpload bool
}

Pan115Client driver client

func Defalut

func Defalut() *Pan115Client

Defalut creates an Client with default settings.

func New

func New(opts ...Option) *Pan115Client

New creates Client with customized options.

func (*Pan115Client) Copy

func (c *Pan115Client) Copy(dirID string, fileIDs ...string) error

Copy copy files or directory into another directory with directroy id

Example
client := Defalut()

err := client.Copy("dirID", "fileID")
if err != nil {
	log.Fatalf("Copy file error: %s", err)
}
Output:

func (*Pan115Client) Delete

func (c *Pan115Client) Delete(fileIDs ...string) error

Delete delete files or directory from file ids

Example
client := Defalut()

err := client.Delete("fileID")
if err != nil {
	log.Fatalf("Delete file error: %s", err)
}
Output:

func (*Pan115Client) Download added in v1.0.5

func (c *Pan115Client) Download(pickCode string) (*DownloadInfo, error)

Download get download info with pickcode

Example
client := Defalut()

info, err := client.Download("pickcode")
if err != nil {
	log.Fatalf("Get download info error: %s", err)
}
rs, err := info.Get()
if err != nil {
	log.Fatalf("Get io reader error: %s", err)
}
f, _ := os.Create("test.mp4") // save to test.mp4
defer func() {
	f.Close()
}()
_, err = f.ReadFrom(rs)
if err != nil {
	log.Fatalf("Copy reader error: %s", err)
}
Output:

func (*Pan115Client) DownloadByShareCode added in v1.0.18

func (c *Pan115Client) DownloadByShareCode(shareCode, receiveCode, fileID string) (*SharedDownloadInfo, error)

DownloadByShareCode get download info with share code

func (*Pan115Client) DownloadWithUA added in v1.0.15

func (c *Pan115Client) DownloadWithUA(pickCode, ua string) (*DownloadInfo, error)

DownloadWithUA get download info with pickcode and user agent

func (*Pan115Client) EnableTrace

func (c *Pan115Client) EnableTrace() *Pan115Client

func (*Pan115Client) GenerateSignature added in v1.0.6

func (c *Pan115Client) GenerateSignature(fileID, target string) string

func (*Pan115Client) GenerateToken added in v1.0.6

func (c *Pan115Client) GenerateToken(fileID, preID, timeStamp, fileSize, signKey, signVal string) string

func (*Pan115Client) GetDigestResult added in v1.0.6

func (c *Pan115Client) GetDigestResult(r io.Reader) (*hash.DigestResult, error)

GetDigestResult get digest of file or stream

func (*Pan115Client) GetFile added in v1.0.10

func (c *Pan115Client) GetFile(fileID string) (*File, error)

GetFile gets information of a file or directory by its ID.

func (*Pan115Client) GetOSSEndpoint added in v1.0.23

func (c *Pan115Client) GetOSSEndpoint(enableInternalUpload bool) string

GetOSSEndpoint get oss endpoint 利用阿里云内网上传文件,需要在阿里云服务器上运行本程序,同时也需要115在服务器的所在地域开通了阿里云OSS

func (*Pan115Client) GetOSSToken added in v1.0.7

func (c *Pan115Client) GetOSSToken() (*UploadOSSTokenResp, error)

GetOSSToken get oss token for oss upload

func (*Pan115Client) GetRequest

func (c *Pan115Client) GetRequest() *resty.Request

func (*Pan115Client) GetShareSnap added in v1.0.18

func (c *Pan115Client) GetShareSnap(shareCode, receiveCode, dirID string, Queries ...Query) (*ShareSnapResp, error)

GetShareSnap get share snap info

func (*Pan115Client) GetUploadEndpoint added in v1.0.22

func (c *Pan115Client) GetUploadEndpoint(endpoint *UploadEndpointResp) error

GetUploadEndpoint get upload endPoint

func (*Pan115Client) GetUploadInfo added in v1.0.6

func (c *Pan115Client) GetUploadInfo() error

GetUploadInfo get some info for upload

func (*Pan115Client) GetUser added in v1.0.10

func (c *Pan115Client) GetUser() (*UserInfo, error)

GetUser get user information

func (*Pan115Client) ImportCookies

func (c *Pan115Client) ImportCookies(cookies map[string]string, domains ...string)

func (*Pan115Client) ImportCredential

func (c *Pan115Client) ImportCredential(cr *Credential) *Pan115Client

ImportCredential import uid, cid, seid

Example
cr := &Credential{}
if err := cr.FromCookie("UID=xxx;CID=xxxx;SEID=xxx;other=xxxx"); err != nil {
	log.Fatalf("Import credentail error: %s", err)
}
client := Defalut().ImportCredential(cr)
if err := client.LoginCheck(); err != nil {
	log.Fatalf("Login error: %s", err)
}
Output:

func (*Pan115Client) List

func (c *Pan115Client) List(dirID string) (*[]File, error)

List list all files and directories

Example
client := Defalut()

files, err := client.List("dirID")
if err != nil {
	log.Fatalf("List file error: %s", err)
}

for _, file := range *files {
	log.Printf("file %v", file)
}
Output:

func (*Pan115Client) ListPage added in v1.0.12

func (c *Pan115Client) ListPage(dirID string, offset, limit int64) (*[]File, error)

ListPage list files and directories with page

func (*Pan115Client) ListWithLimit added in v1.0.13

func (c *Pan115Client) ListWithLimit(dirID string, limit int64) (*[]File, error)

ListWithLimit list all files and directories with limit

func (*Pan115Client) LoginCheck

func (c *Pan115Client) LoginCheck() error

LoginCheck check login status

func (*Pan115Client) Mkdir

func (c *Pan115Client) Mkdir(parentID string, name string) (string, error)

Mkdir make a new directory which name and parent directory id, return directory id

Example
client := Defalut()

cid, err := client.Mkdir("parentID", "name")
if err != nil {
	log.Fatalf("Make directory error: %s", err)
}
log.Printf("cid is  %s", cid)
Output:

func (*Pan115Client) Move

func (c *Pan115Client) Move(dirID string, fileIDs ...string) error

Move move files or directory into another directory with directroy id

Example
client := Defalut()

err := client.Move("dirID", "fileID")
if err != nil {
	log.Fatalf("Move file error: %s", err)
}
Output:

func (*Pan115Client) NewRequest

func (c *Pan115Client) NewRequest() *resty.Request

func (*Pan115Client) QRCodeLogin added in v1.0.10

func (c *Pan115Client) QRCodeLogin(s *QRCodeSession) (*Credential, error)

QRCodeLogin logins user through QRCode with web app. You SHOULD call this method ONLY when `QRCodeStatus.IsAllowed()` is true.

func (*Pan115Client) QRCodeLoginWithApp added in v1.0.22

func (c *Pan115Client) QRCodeLoginWithApp(s *QRCodeSession, app LoginApp) (*Credential, error)

QRCodeLoginWithApp logins user through QRCode with specified app. You SHOULD call this method ONLY when `QRCodeStatus.IsAllowed()` is true.

func (*Pan115Client) QRCodeStart added in v1.0.10

func (c *Pan115Client) QRCodeStart() (*QRCodeSession, error)

QRCodeStart starts a QRCode login session.

func (*Pan115Client) QRCodeStatus added in v1.0.10

func (c *Pan115Client) QRCodeStatus(s *QRCodeSession) (*QRCodeStatus, error)

QRCodeStatus represents the status of a QRCode session.

There are 4 possible status values: - Waiting - Scanned - Allowed - Canceled

func (*Pan115Client) RapidUpload added in v1.0.22

func (c *Pan115Client) RapidUpload(fileSize int64, fileName, dirID, preID, fileID string, r io.ReadSeeker) (*UploadInitResp, error)

RapidUpload rapid upload

func (*Pan115Client) RapidUploadOrByMultipart added in v1.0.23

func (c *Pan115Client) RapidUploadOrByMultipart(dirID, fileName string, fileSize int64, r *os.File, opts ...UploadMultipartOption) error

RapidUploadOrByMultipart upload by mutipart blocks when unable to rapid upload

func (*Pan115Client) RapidUploadOrByOSS added in v1.0.23

func (c *Pan115Client) RapidUploadOrByOSS(dirID, fileName string, fileSize int64, r io.ReadSeeker) error

RapidUploadOrByOSS Upload By OSS when unable to rapid upload file

func (*Pan115Client) Rename

func (c *Pan115Client) Rename(fileID, newName string) error

Rename rename a file or directory with file id and name

Example
client := Defalut()

err := client.Rename("fileID", "newname")
if err != nil {
	log.Fatalf("Rename file error: %s", err)
}
Output:

func (*Pan115Client) SetCookies

func (c *Pan115Client) SetCookies(cs ...*http.Cookie) *Pan115Client

func (*Pan115Client) SetDebug

func (c *Pan115Client) SetDebug(d bool) *Pan115Client

func (*Pan115Client) SetHttpClient

func (c *Pan115Client) SetHttpClient(httpClient *http.Client) *Pan115Client

func (*Pan115Client) SetProxy

func (c *Pan115Client) SetProxy(proxy string) *Pan115Client

func (*Pan115Client) SetUserAgent

func (c *Pan115Client) SetUserAgent(userAgent string) *Pan115Client

func (*Pan115Client) Stat added in v1.0.10

func (c *Pan115Client) Stat(fileID string) (*FileStatInfo, error)

Stat get statistic information of a file or directory

func (*Pan115Client) UploadAvailable added in v1.0.6

func (c *Pan115Client) UploadAvailable() (bool, error)

UploadAvailable check and prepare to upload

func (*Pan115Client) UploadByMultipart added in v1.0.8

func (c *Pan115Client) UploadByMultipart(params *UploadOSSParams, fileSize int64, f *os.File, dirID string, opts ...UploadMultipartOption) error

UploadByMultipart upload by mutipart blocks

func (*Pan115Client) UploadByOSS added in v1.0.7

func (c *Pan115Client) UploadByOSS(params *UploadOSSParams, r io.Reader, dirID string) error

UploadByOSS use aliyun sdk to upload

func (*Pan115Client) UploadDigestRange added in v1.0.14

func (c *Pan115Client) UploadDigestRange(r io.ReadSeeker, rangeSpec string) (result string, err error)

func (*Pan115Client) UploadFastOrByMultipart added in v1.0.8

func (c *Pan115Client) UploadFastOrByMultipart(dirID, fileName string, fileSize int64, r *os.File, opts ...UploadMultipartOption) error

UploadFastOrByMultipart upload by mutipart blocks when unable to rapid upload Deprecated: As of v1.0.22, this function simply calls [RapidUploadOrByMultipart].

func (*Pan115Client) UploadFastOrByOSS added in v1.0.7

func (c *Pan115Client) UploadFastOrByOSS(dirID, fileName string, fileSize int64, r io.ReadSeeker) error

UploadFastOrByOSS Upload By OSS when unable to rapid upload file Deprecated: As of v1.0.22, this function simply calls [RapidUploadOrByOSS].

Example
client := Defalut()

file, err := os.Open("/path/to/file")
if err != nil {
	log.Fatalf("Open file error: %s", err)
}
s, _ := file.Stat()
err = client.UploadFastOrByOSS("dirID", s.Name(), s.Size(), file)
if err != nil {
	log.Fatalf("Upload by oss error: %s", err)
}
Output:

func (*Pan115Client) UploadSHA1 added in v1.0.7

func (c *Pan115Client) UploadSHA1(fileSize int64, fileName, dirID, preID, fileID string, r io.ReadSeeker) (*UploadInitResp, error)

UploadSHA1 upload a sha1, alias of RapidUpload Deprecated: As of v1.0.22, this function simply calls [RapidUpload].

Example
client := Defalut()

file, err := os.Open("/path/to/file")
if err != nil {
	log.Fatalf("Open file error: %s", err)
}
d, _ := client.GetDigestResult(file)
resp, err := client.UploadSHA1(d.Size, "filename", "dirID", d.PreID, d.QuickID, file)
if err != nil {
	log.Fatalf("Fastupload error: %s", err)
}
success, err := resp.Ok()
if err != nil {
	log.Fatalf("Fastupload error: %s", err)
}
if !success {
	log.Printf("file is not exist, need upload")
}
Output:

type QRCodeBasicResp added in v1.0.10

type QRCodeBasicResp struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	State   int    `json:"state"`
	Errno   int    `json:"errno"`
	Error   string `json:"error"`
}

func (*QRCodeBasicResp) Err added in v1.0.10

func (resp *QRCodeBasicResp) Err(respBody ...string) error

type QRCodeLoginResp added in v1.0.10

type QRCodeLoginResp struct {
	QRCodeBasicResp
	Data struct {
		Alert      string     `json:"alert"`
		BindMobile int        `json:"bind_mobile"`
		Credential Credential `json:"cookie"`
		Country    string     `json:"country"`
		Email      string     `json:"email"`
		Face       struct {
			FaceL string `json:"face_l"`
			FaceM string `json:"face_m"`
			FaceS string `json:"face_s"`
		} `json:"face"`
		From          string      `json:"from"`
		IsChangPasswd int         `json:"is_chang_passwd"`
		IsFirstLogin  int         `json:"is_first_login"`
		IsTrusted     interface{} `json:"is_trusted"`
		IsVip         int64       `json:"is_vip"`
		Mark          int         `json:"mark"`
		Mobile        string      `json:"mobile"`
		UserID        int         `json:"user_id"`
		UserName      string      `json:"user_name"`
	} `json:"data"`
}

type QRCodeSession added in v1.0.10

type QRCodeSession struct {
	// The raw data of QRCode, caller should use third-party tools/libraries
	// to convert it into QRCode matrix or image.
	QrcodeContent string `json:"qrcode"`
	Sign          string `json:"sign"`
	Time          int64  `json:"time"`
	UID           string `json:"uid"`
}

func (*QRCodeSession) QRCode added in v1.0.10

func (s *QRCodeSession) QRCode() ([]byte, error)

QRCode get QRCode matrix or image.

func (*QRCodeSession) QRCodeByApi added in v1.0.22

func (s *QRCodeSession) QRCodeByApi() ([]byte, error)

QRCodeByApi get QRCode matrix or image by api.

type QRCodeStatus added in v1.0.10

type QRCodeStatus struct {
	Msg     string `json:"msg"`
	Status  int    `json:"status"`
	Version string `json:"version"`
}

func (*QRCodeStatus) IsAllowed added in v1.0.10

func (s *QRCodeStatus) IsAllowed() bool

func (*QRCodeStatus) IsCanceled added in v1.0.10

func (s *QRCodeStatus) IsCanceled() bool

func (*QRCodeStatus) IsExpired added in v1.0.22

func (s *QRCodeStatus) IsExpired() bool

func (*QRCodeStatus) IsScanned added in v1.0.10

func (s *QRCodeStatus) IsScanned() bool

func (*QRCodeStatus) IsWaiting added in v1.0.10

func (s *QRCodeStatus) IsWaiting() bool

type QRCodeStatusResp added in v1.0.10

type QRCodeStatusResp struct {
	QRCodeBasicResp
	Data QRCodeStatus `json:"data"`
}

type QRCodeTokenResp added in v1.0.10

type QRCodeTokenResp struct {
	QRCodeBasicResp
	Data QRCodeSession `json:"data"`
}

type Query added in v1.0.18

type Query func(query *map[string]string)

func QueryLimit added in v1.0.18

func QueryLimit(limit int) Query

QueryLimit set query limit

func QueryOffset added in v1.0.18

func QueryOffset(offset int) Query

QueryOffset set query offset

type ResultWithErr

type ResultWithErr interface {
	Err(respBody ...string) error
}

type ShareFile added in v1.0.19

type ShareFile struct {
	FileID     string       `json:"fid"`
	UID        int          `json:"uid"`
	CategoryID IntString    `json:"cid"`
	FileName   string       `json:"n"`
	Type       string       `json:"ico"`
	Sha1       string       `json:"sha"`
	Size       StringInt64  `json:"s"`
	Labels     []*LabelInfo `json:"fl"`
	UpdateTime string       `json:"t"`
	IsFile     int          `json:"fc"`
	ParentID   string       `json:"pid"`
}

type ShareSnapResp added in v1.0.18

type ShareSnapResp struct {
	BasicResp
	Data struct {
		Userinfo struct {
			UserID   string `json:"user_id"`
			UserName string `json:"user_name"`
			Face     string `json:"face"`
		} `json:"userinfo"`
		Shareinfo struct {
			SnapID           string      `json:"snap_id"`
			FileSize         StringInt64 `json:"file_size"`
			ShareTitle       string      `json:"share_title"`
			ShareState       string      `json:"share_state"`
			ForbidReason     string      `json:"forbid_reason"`
			CreateTime       StringInt64 `json:"create_time"`
			ReceiveCode      string      `json:"receive_code"`
			ReceiveCount     string      `json:"receive_count"`
			ExpireTime       int64       `json:"expire_time"`
			FileCategory     int64       `json:"file_category"`
			AutoRenewal      string      `json:"auto_renewal"`
			AutoFillRecvcode string      `json:"auto_fill_recvcode"`
			CanReport        int         `json:"can_report"`
			CanNotice        int         `json:"can_notice"`
			HaveVioFile      int         `json:"have_vio_file"`
		} `json:"shareinfo"`
		Count      int         `json:"count"`
		List       []ShareFile `json:"list"`
		ShareState string      `json:"share_state"`
		UserAppeal struct {
			CanAppeal       int `json:"can_appeal"`
			CanShareAppeal  int `json:"can_share_appeal"`
			PopupAppealPage int `json:"popup_appeal_page"`
			CanGlobalAppeal int `json:"can_global_appeal"`
		} `json:"user_appeal"`
	} `json:"data"`
}

type SharedDownloadInfo added in v1.0.18

type SharedDownloadInfo struct {
	FileID   string      `json:"fid"`
	FileName string      `json:"fn"`
	FileSize StringInt64 `json:"fs"`
	URL      struct {
		URL    string      `json:"url"`
		Client int         `json:"client"`
		Desc   interface{} `json:"desc"`
		Isp    interface{} `json:"isp"`
	} `json:"url"`
}

type StringFloat64

type StringFloat64 float64

StringFloat64 uses for json field which maybe a string or a float64.

func (*StringFloat64) UnmarshalJSON

func (v *StringFloat64) UnmarshalJSON(b []byte) (err error)

type StringInt

type StringInt int64

StringInt uses for json field which maybe a string or an int.

func (*StringInt) UnmarshalJSON

func (v *StringInt) UnmarshalJSON(b []byte) (err error)

type StringInt64

type StringInt64 int64

StringInt64 uses for json field which maybe a string or an int64.

func (*StringInt64) UnmarshalJSON

func (v *StringInt64) UnmarshalJSON(b []byte) (err error)

type StringTime added in v1.0.4

type StringTime int64

func (*StringTime) UnmarshalJSON added in v1.0.4

func (v *StringTime) UnmarshalJSON(b []byte) (err error)

type Time

type Time int64

func Now

func Now() Time

func NowMilli

func NowMilli() Time

func (Time) String

func (t Time) String() string

func (Time) ToInt64

func (t Time) ToInt64() int64

type UploadEndpointResp added in v1.0.22

type UploadEndpointResp struct {
	Endpoint    string `json:"endpoint"`
	GetTokenURL string `json:"gettokenurl"`
}

type UploadInfoResp added in v1.0.6

type UploadInfoResp struct {
	BasicResp
	UploadMetaInfo
	UserID  int64  `json:"user_id"`
	Userkey string `json:"userkey"`
}

type UploadInitResp added in v1.0.6

type UploadInitResp struct {
	Request   string `json:"request"`
	ErrorCode int    `json:"statuscode"`
	ErrorMsg  string `json:"statusmsg"`

	Status   BoolInt `json:"status"`
	PickCode string  `json:"pickcode"`
	Target   string  `json:"target"`
	Version  string  `json:"version"`

	// OSS upload fields
	UploadOSSParams

	// Useless fields
	FileID   int    `json:"fileid"`
	FileInfo string `json:"fileinfo"`

	// New fields in upload v4.0
	SignKey   string `json:"sign_key"`
	SignCheck string `json:"sign_check"`
}

func (*UploadInitResp) Err added in v1.0.6

func (r *UploadInitResp) Err(respBody ...string) error

func (*UploadInitResp) Ok added in v1.0.6

func (r *UploadInitResp) Ok() (bool, error)

Ok if fastupload is successful will return true, otherwise return false

type UploadMetaInfo added in v1.0.6

type UploadMetaInfo struct {
	AppID            int64    `json:"app_id"`
	AppVersion       int64    `json:"app_version"`
	IspType          int64    `json:"isp_type"`
	MaxDirLevel      int64    `json:"max_dir_level"`
	MaxDirLevelYun   int64    `json:"max_dir_level_yun"`
	MaxFileNum       int64    `json:"max_file_num"`
	MaxFileNumYun    int64    `json:"max_file_num_yun"`
	SizeLimit        int64    `json:"size_limit"`
	SizeLimitYun     int64    `json:"size_limit_yun"`
	TypeLimit        []string `json:"type_limit"`
	UploadAllowed    bool     `json:"upload_allowed"`
	UploadAllowedMsg string   `json:"upload_allowed_msg"`
}

type UploadMultipartOption added in v1.0.8

type UploadMultipartOption func(o *UploadMultipartOptions)

func UploadMultipartWithThreadsNum added in v1.0.9

func UploadMultipartWithThreadsNum(n int) UploadMultipartOption

func UploadMultipartWithTimeout added in v1.0.9

func UploadMultipartWithTimeout(timeout time.Duration) UploadMultipartOption

func UploadMultipartWithTokenRefreshTime added in v1.0.9

func UploadMultipartWithTokenRefreshTime(refreshTime time.Duration) UploadMultipartOption

type UploadMultipartOptions added in v1.0.8

type UploadMultipartOptions struct {
	ThreadsNum       int
	Timeout          time.Duration
	TokenRefreshTime time.Duration
}

func DefalutUploadMultipartOptions added in v1.0.9

func DefalutUploadMultipartOptions() *UploadMultipartOptions

type UploadOSSParams added in v1.0.7

type UploadOSSParams struct {
	SHA1     string `json:"-"`
	Bucket   string `json:"bucket"`
	Object   string `json:"object"`
	Callback struct {
		Callback    string `json:"callback"`
		CallbackVar string `json:"callback_var"`
	} `json:"callback"`
}

type UploadOSSTokenResp added in v1.0.7

type UploadOSSTokenResp struct {
	AccessKeyID     string    `json:"AccessKeyID"`
	AccessKeySecret string    `json:"AccessKeySecret"`
	Expiration      time.Time `json:"Expiration"`
	SecurityToken   string    `json:"SecurityToken"`
	StatusCode      string    `json:"StatusCode"`
}

func (*UploadOSSTokenResp) Err added in v1.0.7

func (r *UploadOSSTokenResp) Err(respBody ...string) error

type UserInfo added in v1.0.10

type UserInfo struct {
	Device      int           `json:"device"`
	Rank        int           `json:"rank"`
	Liang       int           `json:"liang"`
	Mark        int           `json:"mark"`
	Mark1       int           `json:"mark1"`
	Vip         int           `json:"vip"`
	Expire      int           `json:"expire"`
	Global      int           `json:"global"`
	Forever     int           `json:"forever"`
	IsPrivilege bool          `json:"is_privilege"`
	Privilege   []interface{} `json:"privilege"`
	UserName    string        `json:"user_name"`
	Face        string        `json:"face"`
	UserID      int64         `json:"user_id"`
}

type UserInfoResp added in v1.0.10

type UserInfoResp struct {
	BasicResp
	UserInfo UserInfo `json:"data"`
}

Jump to

Keyboard shortcuts

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