driver

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 9 Imported by: 8

Documentation

Index

Constants

View Source
const (
	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"
)
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 (
	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")

	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")
)
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 GetErr

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

Types

type BasicResponse

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

func (*BasicResponse) Err

func (resp *BasicResponse) 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 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
}

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 StringInt64 `json:"te"`
}

type FileListResponse

type FileListResponse struct {
	BasicResponse

	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, pageSize, offset int64) (*FileListResponse, error)

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 int    `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 {
	BasicResponse
	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
}

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

func (c *Pan115Client) EnableTrace() *Pan115Client

func (*Pan115Client) GetRequest

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

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) (*[]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

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

Jump to

Keyboard shortcuts

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