driver

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: MIT Imports: 18 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// login
	ApiLoginCheck = "https://passportapi.115.com/app/1.0/web/1.0/check/sso"

	// 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"

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

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

	ApiUploadOssToken = "https://uplb.115.com/3.0/gettoken.php"
)
View Source
const (
	UADefalut    = "Mozilla/5.0"
	UA115Browser = "Mozilla/5.0 115Browser/23.9.3.2"
	UA115Disk    = "Mozilla/5.0 115disk/30.1.0"
	UAIosApp     = "Mozilla/5.0; Darwin/10.0; UDown/30.1.0"
)
View Source
const (
	CookieDomain115   = ".115.com"
	CookieDomainAnxia = ".anxia.com"

	CookieUrl = "https://115.com"

	CookieNameUid  = "UID"
	CookieNameCid  = "CID"
	CookieNameSeid = "SEID"
)
View Source
const (
	OssRegionId = "oss-cn-shenzhen"
	OssEndpoint = "oss-cn-shenzhen.aliyuncs.com"
)
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")

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

	ErrWrongParams = errors.New("wrong parameters")

	ErrRepeatLogin = errors.New("repeat login")

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

	ErrPickCodeisEmpty = errors.New("empty pickcode")

	ErrUploadSH1Invalid = errors.New("userid/filesize/target/pickcode 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

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
	CID  string
	SEID string
}

func (*Credential) FromCookie

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

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
}

type DownloadReap added in v1.0.5

type DownloadReap struct {
	BasicResp
	EncodedData string `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) 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 int    `json:"client"`
	OssId  string `json:"oss_id"`
	Url    string `json:"url"`
}

type FileInfo

type FileInfo struct {
	AreaID     IntString `json:"aid"`
	CategoryID string    `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 GetFileOption added in v1.0.6

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

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 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 LoginResp

type LoginResp struct {
	Code     int  `json:"code"`
	CheckSsd bool `json:"check_ssd"`
	Data     struct {
		Expire int    `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   string `json:"cid"`
	CategoryName string `json:"cname"`

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

type Option

type Option func(c *Pan115Client)

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
}

func Defalut

func Defalut() *Pan115Client

Default 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

func (*Pan115Client) Delete

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

func (*Pan115Client) Download added in v1.0.5

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

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 string) string

func (*Pan115Client) GetDigestResult added in v1.0.6

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

func (*Pan115Client) GetOssToken added in v1.0.6

func (c *Pan115Client) GetOssToken() (*UploadOssTokenResponse, error)

func (*Pan115Client) GetRequest

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

func (*Pan115Client) GetUploadInfo added in v1.0.6

func (c *Pan115Client) GetUploadInfo() error

func (*Pan115Client) GetUploadTicket added in v1.0.6

func (c *Pan115Client) GetUploadTicket(params *UploadOssParams, mimeType string, fileSize int64) (*UploadTicket, error)

func (*Pan115Client) ImportCookies

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

func (*Pan115Client) ImportCredential

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

func (*Pan115Client) List

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

func (*Pan115Client) LoginCheck

func (c *Pan115Client) LoginCheck() error

func (*Pan115Client) Mkdir

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

func (*Pan115Client) Move

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

func (*Pan115Client) NewRequest

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

func (*Pan115Client) Rename

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

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) UploadAvailable added in v1.0.6

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

func (*Pan115Client) UploadByOss added in v1.0.6

func (c *Pan115Client) UploadByOss(params *UploadOssParams, r io.Reader, dirID string) error

func (*Pan115Client) UploadFastOrByOss added in v1.0.6

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

func (*Pan115Client) UploadSH1 added in v1.0.6

func (c *Pan115Client) UploadSH1(fileSize int64, fileName, dirID, preID, fileID string) (*UploadInitResp, error)

type ResultWithErr

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

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 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"`
}

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)

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 UploadOssParams added in v1.0.6

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 UploadOssTokenResponse added in v1.0.6

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

func (*UploadOssTokenResponse) Err added in v1.0.6

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

type UploadTicket added in v1.0.6

type UploadTicket struct {
	// Request method
	Verb string
	// Remote URL which will receive the file content.
	Url string
	// Request header
	Header map[string]string
}

Jump to

Keyboard shortcuts

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