Documentation
¶
Overview ¶
Package elevengo is an API wrapper of 115 Cloud Storage Service, it bases on 115 web APIs which captured from their web pages.
Index ¶
- func IsFileExist(err error) bool
- func IsFileNotExist(err error) bool
- func IsOfflineCaptcha(err error) bool
- func IsOfflineExist(err error) bool
- func IsQrcodeExpire(err error) bool
- type Agent
- func (a *Agent) CaptchaKeyImage(session *CaptchaSession, index int) ([]byte, error)
- func (a *Agent) CaptchaStart() (session *CaptchaSession, err error)
- func (a *Agent) CaptchaSubmit(session *CaptchaSession, code string) (err error)
- func (a *Agent) CredentialExport() (cr Credential, err error)
- func (a *Agent) CredentialImport(cr *Credential) (err error)
- func (a *Agent) DirCreate(parentId, name string) (directoryId string, err error)
- func (a *Agent) DirGetId(path string) (directoryId string, err error)
- func (a *Agent) Download(pickcode string, w io.Writer) (size int64, err error)
- func (a *Agent) DownloadCreateTicket(pickcode string) (ticket DownloadTicket, err error)
- func (a *Agent) FileCopy(parentId string, fileIds ...string) (err error)
- func (a *Agent) FileDelete(parentId string, fileIds ...string) (err error)
- func (a *Agent) FileList(parentId string, cursor Cursor) (files []*File, err error)
- func (a *Agent) FileMove(parentId string, fileIds ...string) (err error)
- func (a *Agent) FileRename(fileId, name string) (err error)
- func (a *Agent) FileSearch(rootId, keyword string, cursor Cursor) (files []*File, err error)
- func (a *Agent) FileStat(fileId string) (info FileInfo, err error)
- func (a *Agent) ImageUrl(pickcode string) (link string, err error)
- func (a *Agent) OfflineAdd(url ...string) (err error)
- func (a *Agent) OfflineClear(flag *OfflineClearFlag) (err error)
- func (a *Agent) OfflineDelete(deleteFile bool, hash ...string) (err error)
- func (a *Agent) OfflineList(cursor Cursor) (tasks []*OfflineTask, err error)
- func (a *Agent) QrcodeLogin(session *QrcodeSession) error
- func (a *Agent) QrcodeStart() (session *QrcodeSession, err error)
- func (a *Agent) QrcodeStatus(session *QrcodeSession) (status QrcodeStatus, err error)
- func (a *Agent) StorageStat() (info StorageInfo, err error)
- func (a *Agent) Upload(parentId string, info UploadInfo, r io.Reader) (file *File, err error)
- func (a *Agent) UploadCreateTicket(parentId string, info UploadInfo) (ticket UploadTicket, err error)
- func (a *Agent) UploadParseResult(content []byte) (file *File, err error)
- func (a *Agent) User() (info UserInfo)
- func (a *Agent) Version() string
- func (a *Agent) VideoHlsContent(pickcode string) (content []byte, err error)
- type CaptchaSession
- type Credential
- type Cursor
- type DirectoryInfo
- type DownloadTicket
- type File
- type FileInfo
- type OfflineClearFlag
- type OfflineTask
- type OfflineTaskStatus
- type Options
- type QrcodeSession
- type QrcodeStatus
- type StorageInfo
- type UploadInfo
- type UploadTicket
- type UserInfo
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsFileExist ¶
func IsFileNotExist ¶
func IsOfflineCaptcha ¶
func IsOfflineExist ¶
func IsQrcodeExpire ¶
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent holds signed-in user's credentials, and provides methods to access upstream server's features, such as file management, offline download, etc.
func (*Agent) CaptchaKeyImage ¶
func (a *Agent) CaptchaKeyImage(session *CaptchaSession, index int) ([]byte, error)
Get one CAPTCHA key image data.
You can call this method multiple times, it will return the same character in different font on every calling.
It is useful when you try to train your CAPTCHA solver.
func (*Agent) CaptchaStart ¶
func (a *Agent) CaptchaStart() (session *CaptchaSession, err error)
Start a CAPTCHA session.
Example ¶
agent := Default()
// TODO: Import your credentials here
// Start captcha session.
session, err := agent.CaptchaStart()
if err != nil {
log.Fatalf("Start captcha session error: %s", err)
}
// TODO:
// * Show `session.CodeImage` and `session.KeysImage` to user.
// * Ask user to give the captcha code.
err = agent.CaptchaSubmit(session, "code")
if err != nil {
log.Fatalf("Submit captcha code error: %s", err)
}
func (*Agent) CaptchaSubmit ¶
func (a *Agent) CaptchaSubmit(session *CaptchaSession, code string) (err error)
Submit the CAPTCHA code.
func (*Agent) CredentialExport ¶ added in v0.1.3
func (a *Agent) CredentialExport() (cr Credential, err error)
Export credentials from agent, caller can store it for future use.
func (*Agent) CredentialImport ¶ added in v0.1.3
func (a *Agent) CredentialImport(cr *Credential) (err error)
Import credentials into agent.
Example ¶
agent := Default()
// Import credential to agent
err := agent.CredentialImport(&Credential{
UID: "UID-from-cookie",
CID: "CID-from-cookie",
SEID: "SEID-from-cookie",
})
if err != nil {
log.Fatalf("Import credentail error: %s", err)
} else {
user := agent.User()
log.Printf("Username: %s", user.Name)
}
func (*Agent) Download ¶ added in v0.1.4
Download downloads a file from cloud, writes its content into w. If w implements io.Closer, it will be closed automatically.
This method DOSE NOT support multi-thread/resuming, if caller requires those, use thirdparty tools/libraries instead.
To monitor the downloading progress, caller can wrap w by "github.com/deadblue/gostream/observe".
func (*Agent) DownloadCreateTicket ¶ added in v0.1.4
func (a *Agent) DownloadCreateTicket(pickcode string) (ticket DownloadTicket, err error)
DownloadCreateTicket creates ticket which contains all required information to download a file. Caller can use third-party tools/libraries to download file, such as wget/curl/aria2.
Example ¶
agent := Default()
// TODO: Import your credentials here
// Create download ticket
ticket, err := agent.DownloadCreateTicket("pickcode")
if err != nil {
log.Fatalf("Get download ticket error: %s", err)
}
// Process download ticket through curl
cmd := exec.Command("/usr/bin/curl", ticket.Url)
for name, value := range ticket.Headers {
cmd.Args = append(cmd.Args, "-H", fmt.Sprintf("%s: %s", name, value))
}
cmd.Args = append(cmd.Args, "-o", ticket.FileName)
if err = cmd.Run(); err != nil {
log.Fatal(err)
} else {
log.Printf("File downloaded to %s", ticket.FileName)
}
func (*Agent) FileDelete ¶
Delete files from a directory.
func (*Agent) FileList ¶
Get file list from specific directory.
The upstream API restricts the data count in response, so for a directory which contains a lot of files. you need pass a cursor to receive the cursor information, and use it to fetch remain files.
The cursor should be created by FileCursor(), and DO NOT pass it as nil even you try to get file list from a empty directory.
Example ¶
agent := Default()
// TODO: Import your credentials here
// Get files under root directory
for cursor := FileCursor(); cursor.HasMore(); cursor.Next() {
files, err := agent.FileList("0", cursor)
if err != nil {
log.Fatalf("Get file list error: %s", err)
} else {
for _, file := range files {
log.Printf("Remote file: %#v", file)
}
}
}
func (*Agent) FileSearch ¶
Recursively search files which's name contains the keyword and under the directory.
func (*Agent) FileStat ¶
Get file information related to the file ID. Since the upstream response is cheap, this method cat not return more information.
func (*Agent) OfflineAdd ¶
Add one or more offline tasks by URL.
func (*Agent) OfflineClear ¶
func (a *Agent) OfflineClear(flag *OfflineClearFlag) (err error)
Clear specific type of offline tasks.
The "flag" parameter indicates which type of tasks will be clear, you can pass nil to clear the done tasks but keep the downloaded files.
func (*Agent) OfflineDelete ¶
Delete some offline tasks. if "deleteFile" is true, the downloaded files will be deleted.
func (*Agent) OfflineList ¶
func (a *Agent) OfflineList(cursor Cursor) (tasks []*OfflineTask, err error)
Get some of offline tasks.
The upstream API returns at most 30 tasks for one request, caller need pass a cursor to receive the cursor information, and use it to get remain tasks.
The cursor should be created by OfflineCursor(), DO NOT pass it as nil.
Example ¶
agent := Default()
// TODO: Import your credentials here
// Get offline tasks
for cursor := OfflineCursor(); cursor.HasMore(); cursor.Next() {
tasks, err := agent.OfflineList(cursor)
if err != nil {
log.Fatalf("Get offline task list error: %s", err)
} else {
for _, task := range tasks {
log.Printf("Offline task: %#v", task)
}
}
}
func (*Agent) QrcodeLogin ¶
func (a *Agent) QrcodeLogin(session *QrcodeSession) error
Login through QRcode. You SHOULD call this method ONLY when `QrcodeStatus.IsAllowed()` is true.
func (*Agent) QrcodeStart ¶
func (a *Agent) QrcodeStart() (session *QrcodeSession, err error)
Start a QRcode login session.
Example ¶
agent := Default()
session, err := agent.QrcodeStart()
if err != nil {
log.Fatalf("Start QRcode session error: %s", err)
}
// TODO:
// Convert `session.Content` to QRcode, show it to user,
// and prompt user to scan it through mobile app.
for {
// Get QRcode status
status, err := agent.QrcodeStatus(session)
if err != nil {
if IsQrcodeExpire(err) {
log.Printf("QRCode expired, please re-generate one.")
break
} else {
log.Fatalf("Get QRcode status error: %s", err)
}
} else {
// Check QRcode status
if status.IsWaiting() {
log.Println("Please scan the QRcode in mobile app.")
} else if status.IsScanned() {
log.Println("QRcode has beed scanned, please allow this login in mobile app.")
} else if status.IsAllowed() {
err = agent.QrcodeLogin(session)
if err == nil {
log.Println("QRcode login successed!")
} else {
log.Printf("Submit QRcode login error: %s", err)
}
break
} else if status.IsCanceled() {
fmt.Println("User canceled this login!")
break
}
}
}
func (*Agent) QrcodeStatus ¶
func (a *Agent) QrcodeStatus(session *QrcodeSession) (status QrcodeStatus, err error)
Get QRcode status.
The upstream API uses a long-pull request for 30 seconds, so this API will also block at most 30 seconds, be careful to use it in main goroutine.
The QRcode has 4 status:
- Waiting
- Scanned
- Allowed
- Canceled
The QRcode will expire in 5 mimutes, when it expired, an error will be return, caller can use IsQrcodeExipre() to check that.
func (*Agent) StorageStat ¶
func (a *Agent) StorageStat() (info StorageInfo, err error)
Get storage size information.
func (*Agent) Upload ¶ added in v0.1.4
Upload uploads data as a file to cloud, and returns the file metadata on success. If r implements io.Closer, it will be closed automatically.
func (*Agent) UploadCreateTicket ¶ added in v0.1.4
func (a *Agent) UploadCreateTicket(parentId string, info UploadInfo) (ticket UploadTicket, err error)
UploadCreateTicket creates a ticket which contains all required information to upload a file. Caller can use third-party tools/libraries to upload file.
Example ¶
agent := Default()
// TODO: Import your credentials here
filename := "/path/to/file"
// Get file info
info, err := os.Stat(filename)
if err != nil {
log.Fatalf("Get file info error: %s", err)
}
// Create upload ticket
ticket, err := agent.UploadCreateTicket("0", info)
if err != nil {
log.Fatalf("Create upload ticket error: %s", err)
}
// Createa temp file to receive upload response
tmpFile, err := ioutil.TempFile(os.TempDir(), "115-upload-")
if err != nil {
log.Fatal(err)
}
defer func() {
_ = os.Remove(tmpFile.Name())
}()
// Process upload ticket through curl
cmd := exec.Command("/usr/bin/curl", ticket.Endpoint, "-o", tmpFile.Name())
for name, value := range ticket.Values {
cmd.Args = append(cmd.Args, "-F", fmt.Sprintf("%s=%s", name, value))
}
// Show upload progress
cmd.Args = append(cmd.Args, "-#")
// NOTICE: File field should be the LAST one.
cmd.Args = append(cmd.Args, "-F", fmt.Sprintf("%s=@%s", ticket.FileField, filename))
// Run the command
if err = cmd.Run(); err != nil {
log.Fatalf("Execute curl command error: %s", err)
}
// Parse upload response
response, _ := ioutil.ReadAll(tmpFile)
file, err := agent.UploadParseResult(response)
if err != nil {
log.Fatalf("Parse upload result error: %s", err)
} else {
log.Printf("Uploaded file: %#v", file)
}
func (*Agent) UploadParseResult ¶ added in v0.1.4
UploadParseResult parses the raw upload response body to file metadata. It is useful when caller process upload ticket through thirdpary tools/libraries.
func (*Agent) VideoHlsContent ¶
Get HLS content of a video.
For video file, the upstream server support HLS streaming. Caller can use this method to get the HLS content, then play it through thirdparty tools, such as "mpv".
Example ¶
agent := Default()
// TODO: Import your credentials here
// Get video HLS content
hls, err := agent.VideoHlsContent("pickcode")
if err != nil {
log.Fatalf("Get video HLS error: %s", err)
}
// Play HLS through mpv
cmd := exec.Command("/usr/local/bin/mpv", "-")
cmd.Stdin = bytes.NewReader(hls)
if err = cmd.Run(); err != nil {
log.Fatalf("Execute mpv error: %s", err)
}
type CaptchaSession ¶
type CaptchaSession struct {
// CAPTCHA image data.
CodeImage []byte
// CAPTCHA keys image data.
KeysImage []byte
// contains filtered or unexported fields
}
CaptchaSession holds CAPTCHA images and session information during a CAPTCHA process.
There are 4 Chinese characters on "CodeImage" and 10 Chinese characters on "KeysImage" (5 columns by 2 rows). User should find the 4 characters on "CodeImage" from "KeysImage", the indexes of these characters is the CAPTCHA code.
The index bases on 0, starts from left top corner, increases from left to right, then from top to bottom.
For example:
Assume the code image is
+---------------+ | J | F | C | H | +---------------+
and the keys image is
+-------------------+ | A | B | C | D | E | +-------------------+ | F | G | H | I | J | +-------------------+
Then the CAPTCHA code is "9527", you can call Agent.CaptchaSubmit() to submit it.
type Credential ¶ added in v0.1.3
Credential contains required information that the upstream server uses to authenticate a signed-in user.
In detail, three cookies are required: "UID", "CID", "SEID", caller can find them from browser cookie storage.
type Cursor ¶
type Cursor interface {
// Return true if the cursor has not been used or there is some data remain.
HasMore() bool
// Move cursor to the start of the remaining data.
Next()
// Return total amount of the data.
Total() int
}
Due to the upstream API restriction, some list methods can not get the whole data in one request. Cursor is design for these methods, to get data page-by-page.
func FileCursor ¶
func FileCursor() Cursor
Create a cursor for "Agent.FileList()" and "Agent.FileSearch()".
type DirectoryInfo ¶ added in v0.1.2
DirectoryInfo only used in FileInfo.
type DownloadTicket ¶
type DownloadTicket struct {
// Download URL.
Url string
// Request headers which SHOULD be sent with download URL.
Headers map[string]string
// File name.
FileName string
// File size in bytes.
FileSize int64
}
DownloadTicket contains all required information to download a file.
type File ¶
type File struct {
// True means a file.
IsFile bool
// True means a directory.
IsDirectory bool
// Unique ID for the file.
FileId string
// Parent directory ID.
ParentId string
// File name.
Name string
// File size in bytes, 0 for directory.
Size int64
// Pick code, you can use this to create a download ticket.
PickCode string
// Sha1 hash value of the file, empty for directory.
Sha1 string
// Create time of the file.
CreateTime time.Time
// Update time of the file.
UpdateTime time.Time
}
File describe a remote file or directory.
type FileInfo ¶
type FileInfo struct {
// True means a file.
IsFile bool
// True means a directory.
IsDirectory bool
// File name.
Name string
// Pick code for downloading.
PickCode string
// Sha1 hash value of the file, empty for directory.
Sha1 string
// Create time of the file.
CreateTime time.Time
// Update time of the file.
UpdateTime time.Time
// Parent directory list.
Parents []*DirectoryInfo
}
FileInfo is returned by FileStat(), contains basic information of a file.
type OfflineClearFlag ¶
type OfflineClearFlag struct {
// contains filtered or unexported fields
}
Parameter for "Agent.OfflineClear()" method. Default value is to clear all done tasks without deleteing downloaded files.
func (*OfflineClearFlag) All ¶
func (f *OfflineClearFlag) All(delete bool) *OfflineClearFlag
Clear all tasks, delete the downloaded files if "delete" is true.
func (*OfflineClearFlag) Done ¶
func (f *OfflineClearFlag) Done(delete bool) *OfflineClearFlag
Clear done tasks, delete the downloaded files if "delete" is true.
func (*OfflineClearFlag) Failed ¶
func (f *OfflineClearFlag) Failed() *OfflineClearFlag
Clear failed tasks.
func (*OfflineClearFlag) Running ¶
func (f *OfflineClearFlag) Running() *OfflineClearFlag
Clean running tasks.
type OfflineTask ¶
type OfflineTask struct {
// Unique hash of the task.
InfoHash string
// Task name.
Name string
// Task URL.
Url string
// Task status.
Status OfflineTaskStatus
// Download percent of the task, 0 to 100.
Percent float64
// File ID of the downloaded file on remote server.
FileId string
}
OfflineTask describe a remote download task.
type OfflineTaskStatus ¶
type OfflineTaskStatus int
Describe status of an offline task.
func (OfflineTaskStatus) IsDone ¶
func (s OfflineTaskStatus) IsDone() bool
Return true if the task has been done.
func (OfflineTaskStatus) IsFailed ¶
func (s OfflineTaskStatus) IsFailed() bool
Return true if the task has been failed.
func (OfflineTaskStatus) IsRunning ¶
func (s OfflineTaskStatus) IsRunning() bool
Return true if the task is still running.
type Options ¶ added in v0.1.3
type Options struct {
// Name of the agent, will be used in "User-Agent" request header.
// Caller can customize it, while it does not affect any features.
Name string
// Logger for printing debug message.
// Set to nil to disable the debug message.
// Caller can implement one or simply use plugin.StdLogger.
Logger plugin.Logger
}
Options for customize Agent.
type QrcodeSession ¶
type QrcodeSession struct {
// The raw data of QR code, caller should use thridparty tools/libraries
// to convert it into QR code matrix or image.
Content string
// contains filtered or unexported fields
}
QrcodeSession holds the information during a QRcode login process.
type QrcodeStatus ¶
type QrcodeStatus int
QrcodeStatus is returned by `Agent.QrcodeStatus()`. You can call `QrcodeStatus.IsXXX()` method to check the status, or directly check its value.
func (QrcodeStatus) IsAllowed ¶
func (qs QrcodeStatus) IsAllowed() bool
Return true if user allowed this login process, you can call "Agent.QrcodeLogin()" after then.
func (QrcodeStatus) IsCanceled ¶
func (qs QrcodeStatus) IsCanceled() bool
Return true if user canceled this login process.
func (QrcodeStatus) IsScanned ¶
func (qs QrcodeStatus) IsScanned() bool
Return true if user has scanned the QRcode, but still not allow or cancel this login.
func (QrcodeStatus) IsWaiting ¶
func (qs QrcodeStatus) IsWaiting() bool
Return true if user still does not scan the QRcode.
type StorageInfo ¶
type StorageInfo struct {
// Total size in bytes.
Size int64
// Used size in bytes.
Used int64
// Avail size in bytes.
Avail int64
}
Storage information.
type UploadInfo ¶
type UploadInfo interface {
// Name of the upload file.
Name() string
// Size in bytes of the upload file.
Size() int64
}
UploadInfo contains all required information to create an upload ticket.
To upload a regular file, caller can use os.FileInfo as UploadInfo, see "Agent.UploadCreateTicket" doc for detail.
To upload a memory data as file, caller should implement it himself.
type UploadTicket ¶
type UploadTicket struct {
// Remote URL which will receive the file content.
Endpoint string
// Field name for the upload file.
FileField string
// Other parameters that should be sent with the file.
Values map[string]string
}
UploadTicket contains all required information to upload a file.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
types
This package contains all internal types that you needn't care about.
|
This package contains all internal types that you needn't care about. |
|
Package plugin declares some interfaces that allows developer customizing elevengo agent.
|
Package plugin declares some interfaces that allows developer customizing elevengo agent. |