elevengo

package module
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 23 Imported by: 4

README

ElevenGo

Version Reference License

An API client of 115 Cloud Storage Service.

Example

High-level API
package main

import (
    "github.com/deadblue/elevengo"
    "log"
)

func main()  {
  // Initialize agent
  agent := elevengo.Default()
  // Import credential
  credential := &elevengo.Credential{
    UID: "", CID: "", SEID: "",
  }
  if err := agent.CredentialImport(credential); err != nil {
    log.Fatalf("Import credentail error: %s", err)
  }

  // Get file list
  it, err := agent.FileIterate("dirId")
  for ; err == nil; err = it.Next() {
    file := &elevengo.File{}
    if err = it.Get(file); err == nil {
      log.Printf("File: %d => %#v", it.Index(), file)
    }
  }
  if !elevengo.IsIteratorEnd(err) {
    log.Fatalf("Iterate files error: %s", err)
  }
}
Low-level API
package main

import (
    "context"
    "log"

    "github.com/deadblue/elevengo"
    "github.com/deadblue/elevengo/lowlevel/api"
)

func main()  {
  // Initialize agent
  agent := elevengo.Default()
  // Import credential
  credential := &elevengo.Credential{
    UID: "", CID: "", SEID: "",
  }
  if err := agent.CredentialImport(credential); err != nil {
    log.Fatalf("Import credentail error: %s", err)
  }

  // Get low-level API client
  llc := agent.LowlevelClient()
  // Init FileList API spec
  spec := (&api.FiieListSpec{}).Init("dirId", 0, 32)
  // Call API
  if err = llc.CallApi(spec, context.Background()); err != nil {
    log.Fatalf("Call API error: %s", err)
  }
  // Parse API result
  for index, file := range spec.Result.Files {
    log.Printf("File: %d => %v", index, file)
  }
  
}

License

MIT

Documentation

Overview

Package elevengo is an API client for 115 Cloud Storage Service, it bases on the official APIs that are captures from Web and Desktop App.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrQrcodeCancelled = errors.New("QRcode cancelled")

Functions

func IsIteratorEnd added in v0.2.2

func IsIteratorEnd(err error) bool

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 Default

func Default() *Agent

Default creates an Agent with default settings.

func New

func New(options ...option.AgentOption) *Agent

New creates Agent with customized options.

Example
// Customize agent
agent := New(
	// Custom agent name
	option.AgentNameOption("Evangelion/1.0"),
	// Sleep 100~500 ms between two API calling
	option.AgentCooldownOption{Min: 100, Max: 500},
)

var err error
if err = agent.CredentialImport(&Credential{
	UID: "", CID: "", SEID: "",
}); err != nil {
	log.Fatalf("Invalid credential, error: %s", err)
}
Output:

func (*Agent) CredentialExport added in v0.1.3

func (a *Agent) CredentialExport(cr *Credential)

CredentialExport exports current credentials for future-use.

func (*Agent) CredentialImport added in v0.1.3

func (a *Agent) CredentialImport(cr *Credential) (err error)

CredentialImport imports credentials into agent.

Example
agent := Default()

// Import credential to agent
if err := agent.CredentialImport(&Credential{
	UID:  "UID-From-Cookie",
	CID:  "CID-From-Cookie",
	SEID: "SEID-From-Cookie",
}); err != nil {
	log.Fatalf("Import credentail error: %s", err)
}
Output:

func (*Agent) DirGetId added in v0.1.5

func (a *Agent) DirGetId(path string) (dirId string, err error)

DirGetId retrieves directory ID from full path.

func (*Agent) DirMake added in v0.2.1

func (a *Agent) DirMake(parentId string, name string) (dirId string, err error)

DirMake makes directory under parentId, and returns its ID.

func (*Agent) DirSetOrder added in v0.2.1

func (a *Agent) DirSetOrder(dirId string, order FileOrder, asc bool) (err error)

DirSetOrder sets how files under the directory be ordered.

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

// Create download ticket
var err error
ticket := DownloadTicket{}
if err = agent.DownloadCreateTicket("pickcode", &ticket); 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)
}
Output:

func (*Agent) Fetch added in v0.5.1

func (a *Agent) Fetch(url string) (body io.ReadCloser, err error)

Fetch gets content from url using agent underlying HTTP client.

func (*Agent) FetchRange added in v0.5.1

func (a *Agent) FetchRange(url string, rng Range) (body io.ReadCloser, err error)

FetchRange gets partial content from |url|, which is located by |rng|.

func (*Agent) FileBatchRename added in v0.5.1

func (a *Agent) FileBatchRename(nameMap map[string]string) (err error)

FileBatchRename renames multiple files.

func (*Agent) FileCopy

func (a *Agent) FileCopy(dirId string, fileIds []string) (err error)

FileCopy copies files into target directory whose id is dirId.

func (*Agent) FileDelete

func (a *Agent) FileDelete(fileIds []string) (err error)

FileDelete deletes files.

func (*Agent) FileGet added in v0.2.1

func (a *Agent) FileGet(fileId string, file *File) (err error)

FileGet gets information of a file/directory by its ID.

func (*Agent) FileIterate added in v0.2.2

func (a *Agent) FileIterate(dirId string) (it Iterator[File], err error)

FileIterate list files under directory, whose id is |dirId|.

Example
agent := Default()

it, err := agent.FileIterate("0")
for ; err == nil; err = it.Next() {
	file := &File{}
	_ = it.Get(file)
	log.Printf("File: %d => %#v", it.Index(), file)
}
if !IsIteratorEnd(err) {
	log.Fatalf("Iterate file failed: %s", err.Error())
}
Output:

func (*Agent) FileMove

func (a *Agent) FileMove(dirId string, fileIds []string) (err error)

FileMove moves files into target directory whose id is dirId.

func (*Agent) FileRename

func (a *Agent) FileRename(fileId, newName string) (err error)

FileRename renames file to new name.

func (*Agent) FileSearch

func (a *Agent) FileSearch(dirId, keyword string, opts ...option.FileListOption) (it Iterator[File], err error)

FileSearch recursively searches files under a directory, whose name contains the given keyword.

func (*Agent) FileSetLabels added in v0.2.1

func (a *Agent) FileSetLabels(fileId string, labelIds ...string) (err error)

FileSetLabels sets labels for a file, you can also remove all labels from it by not passing any labelId.

func (*Agent) FileSetStar added in v0.5.1

func (a *Agent) FileSetStar(fileId string, star bool) (err error)

FileSetStar adds/removes star from a file, whose ID is fileId.

func (*Agent) FileWithLabel added in v0.5.1

func (a *Agent) FileWithLabel(labelId string, opts ...option.FileListOption) (it Iterator[File], err error)

FileLabeled lists files which has specific label.

func (*Agent) FileWithStar added in v0.5.1

func (a *Agent) FileWithStar(opts ...option.FileListOption) (it Iterator[File], err error)

FileWithStar lists files with star.

func (*Agent) ImageGetUrl added in v0.2.1

func (a *Agent) ImageGetUrl(pickcode string) (imageUrl string, err error)

ImageGetUrl gets an accessible URL of an image file by its pickcode.

func (*Agent) Import added in v0.2.1

func (a *Agent) Import(dirId string, ticket *ImportTicket) (err error)

Import imports(aka. rapid-upload) a file to your 115 cloud storage. Please check example code for the detailed usage.

Example
var err error

// Initialize two agents for sender and receiver
sender, receiver := Default(), Default()
sender.CredentialImport(&Credential{
	UID: "", CID: "", SEID: "",
})
receiver.CredentialImport(&Credential{
	UID: "", CID: "", SEID: "",
})

// File to send on sender's storage
fileId := "12345678"
// Create import ticket by sender
ticket, pickcode := &ImportTicket{}, ""
if pickcode, err = sender.ImportCreateTicket(fileId, ticket); err != nil {
	log.Fatalf("Get file info failed: %s", err)
}

// Directory to save file on receiver's storage
dirId := "0"
// Call Import first time
if err = receiver.Import(dirId, ticket); err != nil {
	if ie, ok := err.(*ErrImportNeedCheck); ok {
		// Calculate sign value by sender
		signValue, err := sender.ImportCalculateSignValue(pickcode, ie.SignRange)
		if err != nil {
			log.Fatalf("Calculate sign value failed: %s", err)
		}
		// Update ticket and import again
		ticket.SignKey, ticket.SignValue = ie.SignKey, signValue
		if err = receiver.Import(dirId, ticket); err == nil {
			log.Print("Import succeeded!")
		} else {
			log.Fatalf("Import failed: %s", err)
		}
	} else {
		log.Fatalf("Import failed: %s", err)
	}
} else {
	log.Print("Import succeeded!")
}
Output:

func (*Agent) ImportCalculateSignValue added in v0.4.2

func (a *Agent) ImportCalculateSignValue(pickcode string, signRange string) (value string, err error)

ImportCalculateSignValue calculates sign value of a file on cloud storage. Please check example code for the detailed usage.

func (*Agent) ImportCreateTicket added in v0.3.1

func (a *Agent) ImportCreateTicket(fileId string, ticket *ImportTicket) (pickcode string, err error)

ImportCreateTicket is a helper function to create an ImportTicket of a file, that you can share to others to import this file to their cloud storage. You should also send pickcode together with ticket.

func (*Agent) LabelCreate added in v0.2.1

func (a *Agent) LabelCreate(name string, color LabelColor) (labelId string, err error)

LabelCreate creates a label with name and color, returns its ID.

func (*Agent) LabelDelete added in v0.2.1

func (a *Agent) LabelDelete(labelId string) (err error)

LabelDelete deletes a label whose ID is labelId.

func (*Agent) LabelFind added in v0.2.1

func (a *Agent) LabelFind(name string, label *Label) (err error)

LabelFind finds label whose name is name, and returns it.

func (*Agent) LabelIterate added in v0.2.1

func (a *Agent) LabelIterate() (it Iterator[Label], err error)

func (*Agent) LabelSetOrder added in v0.5.1

func (a *Agent) LabelSetOrder(labelId string, order FileOrder, asc bool) (err error)

func (*Agent) LabelUpdate added in v0.2.1

func (a *Agent) LabelUpdate(label *Label) (err error)

LabelUpdate updates label's name or color.

func (*Agent) LowlevelClient added in v0.6.1

func (a *Agent) LowlevelClient() client.Client

LowlevelClient returns low-level client that can be used to directly call ApiSpec.

func (*Agent) LowlevelParams added in v0.6.3

func (a *Agent) LowlevelParams() types.CommonParams

LowlevelParams returns common parameters for low-level API calling.

func (*Agent) OfflineAddUrl added in v0.4.6

func (a *Agent) OfflineAddUrl(urls []string, opts ...option.OfflineAddOption) (hashes []string, err error)

OfflineAddUrl adds offline tasks by download URLs. It returns an info hash list related to the given urls, the info hash will be empty if the related URL is invalid.

You can use options to change the download directory:

agent := Default()
agent.CredentialImport(&Credential{UID: "", CID: "", SEID: ""})
hashes, err := agent.OfflineAddUrl([]string{
	"https://foo.bar/file.zip",
	"magent:?xt=urn:btih:111222",
	"ed2k://|file|name|size|md4|",
}, option.OfflineSaveDownloadedFileTo("dirId"))

func (*Agent) OfflineClear

func (a *Agent) OfflineClear(flag OfflineClearFlag) (err error)

OfflineClear clears tasks which is in specific status.

func (*Agent) OfflineDelete

func (a *Agent) OfflineDelete(hashes []string, opts ...option.OfflineDeleteOption) (err error)

OfflineDelete deletes tasks.

func (*Agent) OfflineIterate added in v0.2.1

func (a *Agent) OfflineIterate() (it Iterator[OfflineTask], err error)

OfflineIterate returns an iterator for travelling offline tasks, it will return an error if there are no tasks.

Example
agent := Default()

for it, err := agent.OfflineIterate(); err == nil; err = it.Next() {
	task := &OfflineTask{}
	err = it.Get(task)
	if err != nil {
		log.Printf("Offline task: %#v", task)
	}
}
Output:

func (*Agent) QrcodePoll added in v0.5.1

func (a *Agent) QrcodePoll(session *QrcodeSession) (done bool, err error)

QrcodePoll polls the session state, and automatically sin

func (*Agent) QrcodeStart

func (a *Agent) QrcodeStart(session *QrcodeSession, options ...option.QrcodeOption) (err error)

QrcodeStart starts a QRcode sign-in session. The session is for web by default, you can change sign-in app by passing a "option.QrcodeLoginOption".

Example:

agent := elevengo.Default()
session := elevengo.QrcodeSession()
agent.QrcodeStart(session, option.QrcodeLoginLinux)
Example
agent := Default()

session := &QrcodeSession{}
err := agent.QrcodeStart(session)
if err != nil {
	log.Fatalf("Start QRcode session error: %s", err)
}
// TODO: Show QRcode and ask user to scan it via 115 app.
for done := false; !done && err != nil; {
	done, err = agent.QrcodePoll(session)
}
if err != nil {
	log.Fatalf("QRcode login failed, error: %s", err)
}
Output:

func (*Agent) StorageStat

func (a *Agent) StorageStat(info *StorageInfo) (err error)

StorageStat gets storage size information.

func (*Agent) UploadCreateOssTicket added in v0.3.2

func (a *Agent) UploadCreateOssTicket(
	dirId, name string, r io.ReadSeeker, ticket *UploadOssTicket,
) (err error)

UploadCreateOssTicket creates ticket to upload file through aliyun-oss-sdk. Use this method if you want to upload a file larger than 5G bytes.

To create ticket, r will be fully read to calculate SHA-1 and MD5 hash value. If you want to re-use r, try to seek it to beginning.

Example:

    import (
        "github.com/aliyun/aliyun-oss-go-sdk/oss"
        "github.com/deadblue/elevengo"
    )

	func main() {
		filePath := "/file/to/upload"

		var err error

		file, err := os.Open(filePath)
		if err != nil {
			log.Fatalf("Open file failed: %s", err)
		}
		defer file.Close()

		// Create 115 agent
		agent := elevengo.Default()
		if err = agent.CredentialImport(&elevengo.Credential{
			UID: "", CID: "", SEID: "",
		}); err != nil {
			log.Fatalf("Login failed: %s", err)
		}
		// Prepare OSS upload ticket
		ticket := &UploadOssTicket{}
		if err = agent.UploadCreateOssTicket(
			"dirId",
			filepath.Base(file.Name()),
			file,
			ticket,
		); err != nil {
			log.Fatalf("Create OSS ticket failed: %s", err)
		}
		if ticket.Exist {
			log.Printf("File has been fast-uploaded!")
			return
		}

		// Create OSS client
		oc, err := oss.New(
			ticket.Client.Endpoint,
			ticket.Client.AccessKeyId,
			ticket.Client.AccessKeySecret,
			oss.SecurityToken(ticket.Client.SecurityToken)
		)
		if err != nil {
			log.Fatalf("Create OSS client failed: %s", err)
		}
		bucket, err := oc.Bucket(ticket.Bucket)
		if err != nil {
			log.Fatalf("Get OSS bucket failed: %s", err)
		}
		// Upload file in multipart.
		err = bucket.UploadFile(
			ticket.Object,
			filePath,
			100 * 1024 * 1024,	// 100 Megabytes per part
			oss.Callback(ticket.Callback),
			oss.CallbackVar(ticket.CallbackVar),
		)
		// Until now (2023-01-29), there is a bug in aliyun-oss-go-sdk:
		// When set Callback option, the response from CompleteMultipartUpload API
		// is returned by callback host, which is not the standard XML. But SDK
		// always tries to parse it as CompleteMultipartUploadResult, and returns
		// `io.EOF` error, just ignore it!
		if err != nil && err != io.EOF {
			log.Fatalf("Upload file failed: %s", err)
		} else {
			log.Print("Upload done!")
		}
	}

func (*Agent) UploadCreateTicket added in v0.1.4

func (a *Agent) UploadCreateTicket(
	dirId, name string, r io.ReadSeeker, ticket *UploadTicket,
) (err error)

UploadCreateTicket creates a ticket which contains all required parameters to upload file/data to cloud, the ticket should be used in 1 hour.

To create ticket, r will be fully read to calculate SHA-1 and MD5 hash value. If you want to re-use r, try to seek it to beginning.

To upload a file larger than 5G bytes, use `UploadCreateOssTicket`.

Example
agent := Default()

filename := "/path/to/file"
file, err := os.Open(filename)
if err != nil {
	log.Fatalf("Open file failed: %s", err.Error())
}

ticket := &UploadTicket{}
if err = agent.UploadCreateTicket("dirId", path.Base(filename), file, ticket); err != nil {
	log.Fatalf("Create upload ticket failed: %s", err.Error())
}
if ticket.Exist {
	log.Printf("File already exists!")
	return
}

// Make temp file to receive upload result
tmpFile, err := os.CreateTemp("", "curl-upload-*")
if err != nil {
	log.Fatalf("Create temp file failed: %s", err)
}
defer func() {
	_ = tmpFile.Close()
	_ = os.Remove(tmpFile.Name())
}()

// Use "curl" to upload file
cmd := exec.Command("curl", ticket.Url,
	"-o", tmpFile.Name(), "-#",
	"-T", filename)
for name, value := range ticket.Header {
	cmd.Args = append(cmd.Args, "-H", fmt.Sprintf("%s: %s", name, value))
}
if err = cmd.Run(); err != nil {
	log.Fatalf("Upload failed: %s", err)
}

// Parse upload result
uploadFile := &File{}
if err = agent.UploadParseResult(tmpFile, uploadFile); err != nil {
	log.Fatalf("Parse upload result failed: %s", err)
} else {
	log.Printf("Uploaded file: %#v", file)
}
Output:

func (*Agent) UploadParseResult added in v0.1.4

func (a *Agent) UploadParseResult(r io.Reader, file *File) (err error)

UploadParseResult parses the raw upload response, and fills it to file.

func (*Agent) UploadSample added in v0.5.1

func (a *Agent) UploadSample(dirId, name string, size int64, r io.Reader) (fileId string, err error)

UploadSample directly uploads small file/data (smaller than 200MB) to cloud.

func (*Agent) UserGet added in v0.2.1

func (a *Agent) UserGet(info *UserInfo) (err error)

UserGet get information of current signed-in user.

func (*Agent) Version

func (a *Agent) Version() string

func (*Agent) VideoCreateTicket added in v0.5.1

func (a *Agent) VideoCreateTicket(pickcode string, ticket *VideoTicket) (err error)

VideoCreateTicket creates a PlayTicket to play the cloud video.

Example
agent := Default()

// Create video play ticket
ticket := &VideoTicket{}
err := agent.VideoCreateTicket("pickcode", ticket)
if err != nil {
	log.Fatalf("Get video info failed: %s", err)
}

headers := make([]string, 0, len(ticket.Headers))
for name, value := range ticket.Headers {
	headers = append(headers, fmt.Sprintf("'%s: %s'", name, value))
}

// Play HLS through mpv
cmd := exec.Command("mpv")
cmd.Args = append(cmd.Args,
	fmt.Sprintf("--http-header-fields=%s", strings.Join(headers, ",")),
	ticket.Url,
)
cmd.Run()
Output:

type Credential added in v0.1.3

type Credential struct {
	UID  string
	CID  string
	SEID string
}

Credential contains required information which 115 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 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 ErrImportNeedCheck added in v0.4.2

type ErrImportNeedCheck struct {
	// The sign key your should set to ImportTicket
	SignKey string
	// The sign range in format of "<start>-<end>" in bytes.
	// You can directly use it in ImportCreateTicket.
	SignRange string
}

func (*ErrImportNeedCheck) Error added in v0.4.2

func (e *ErrImportNeedCheck) Error() string

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

	// Last modified time
	ModifiedTime time.Time

	// Play duration in seconds, for audio/video files.
	MediaDuration float64
	// Is file a video.
	IsVideo bool
	// Definition of the video file.
	VideoDefinition VideoDefinition
}

File describe a file or directory on cloud storage.

type FileOrder added in v0.5.1

type FileOrder int
const (
	FileOrderByName FileOrder = iota
	FileOrderBySize
	FileOrderByType
	FileOrderByCreateTime
	FileOrderByUpdateTime
	FileOrderByOpenTime
)

type ImportTicket added in v0.2.1

type ImportTicket struct {
	// File base name
	FileName string
	// File size in bytes
	FileSize int64
	// File SHA-1 hash, in upper-case HEX format
	FileSha1 string
	// Sign key from 115 server.
	SignKey string
	// SHA-1 hash value of a segment of the file, in upper-case HEX format
	SignValue string
}

ImportTicket container reqiured fields to import(aka. quickly upload) a file to your 115 cloud storage.

type Iterator added in v0.2.1

type Iterator[T any] interface {

	// Next move cursor to next.
	Next() error

	// Index returns the index of current item, starts from 0.
	Index() int

	// Get gets current item.
	Get(*T) error

	// Count return the count of items.
	Count() int
}

Iterator iterate items.

type Label added in v0.2.1

type Label struct {
	Id    string
	Name  string
	Color LabelColor
}

type LabelColor added in v0.2.1

type LabelColor int
const (
	LabelColorBlank LabelColor = iota
	LabelColorRed
	LabelColorOrange
	LabelColorYellow
	LabelColorGreen
	LabelColorBlue
	LabelColorPurple
	LabelColorGray
)

type OfflineClearFlag

type OfflineClearFlag int
const (
	OfflineClearDone OfflineClearFlag = iota
	OfflineClearAll
	OfflineClearFailed
	OfflineClearRunning
	OfflineClearDoneAndDelete
	OfflineClearAllAndDelete
)

type OfflineTask

type OfflineTask struct {
	InfoHash string
	Name     string
	Size     int64
	Status   int
	Percent  float64
	Url      string
	FileId   string
}

OfflineTask describe an offline downloading task.

func (*OfflineTask) IsDone added in v0.2.1

func (t *OfflineTask) IsDone() bool

func (*OfflineTask) IsFailed added in v0.2.1

func (t *OfflineTask) IsFailed() bool

func (*OfflineTask) IsRunning added in v0.2.1

func (t *OfflineTask) IsRunning() bool

type QrcodeSession

type QrcodeSession struct {
	// QRCode image content.
	Image []byte
	// contains filtered or unexported fields
}

QrcodeSession holds the information during a QRCode login process.

func (*QrcodeSession) Marshal added in v0.5.2

func (s *QrcodeSession) Marshal() string

Marshal marshals QrcodeSession into a string, which can be tranfered out of process.

func (*QrcodeSession) Unmarshal added in v0.5.2

func (s *QrcodeSession) Unmarshal(text string) (err error)

Unmarshal fills QrcodeSession from a string which is generated by |Marshal|.

type Range added in v0.3.2

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

Range is used in Agent.GetRange().

func RangeFirst added in v0.3.2

func RangeFirst(length int64) Range

RangeFirst makes a Range parameter to request the first `length` bytes.

func RangeLast added in v0.3.2

func RangeLast(length int64) Range

RangeLast makes a Range parameter to request the last `length` bytes.

func RangeMiddle added in v0.3.2

func RangeMiddle(offset, length int64) Range

RangeMiddle makes a Range parameter to request content starts from `offset`, and has `length` bytes (at most).

You can pass a negative number in `length`, to request content starts from `offset` to the end.

type StorageInfo

type StorageInfo struct {
	// Total size in bytes.
	Size int64
	// Human-readable total size.
	FormatSize string

	// Used size in bytes.
	Used int64
	// Human-readable used size.
	FormatUsed string

	// Available size in bytes.
	Avail int64
	// Human-readable remain size.
	FormatAvail string
}

StorageInfo describes storage space usage.

type UploadOssTicket added in v0.3.2

type UploadOssTicket struct {
	// Expiration time
	Expiration time.Time
	// Is file already exists
	Exist bool
	// Client parameters
	Client struct {
		Endpoint        string
		AccessKeyId     string
		AccessKeySecret string
		SecurityToken   string
	}
	// Bucket name
	Bucket string
	// Object key
	Object string
	// Callback option
	Callback string
	// CallbackVar option
	CallbackVar string
}

UploadOssTicket contains all required paramters to upload a file through aliyun-oss-sdk(https://github.com/aliyun/aliyun-oss-go-sdk).

type UploadTicket

type UploadTicket struct {
	// Expiration time
	Expiration time.Time
	// Is file exists
	Exist bool
	// Request method
	Verb string
	// Remote URL which will receive the file content.
	Url string
	// Request header
	Header map[string]string
}

UploadTicket contains all required information to upload a file.

type UserInfo added in v0.1.2

type UserInfo struct {
	// User ID
	Id int
	// User name
	Name string
	// Is user VIP
	IsVip bool
}

UserInfo contains the basic information of a signed-in user.

type VideoDefinition added in v0.5.2

type VideoDefinition int

VideoDefinition values from 115.

const (
	// Standard Definition, aka. 480P.
	VideoDefinitionSD VideoDefinition = 1
	// High Definition, aka. 720P.
	VideoDefinitionHD VideoDefinition = 2
	// Full-HD, aka. 1080P.
	VideoDefinitionFHD VideoDefinition = 3
	// Another 1080P, what the fuck?
	VideoDefinition1080P VideoDefinition = 4
	// 4K Definition, aka. Ultra-HD.
	VideoDefinition4K VideoDefinition = 5
	// The fallback definition, usually for non-standard resolution.
	VideoDefinitionOrigin VideoDefinition = 100
)

type VideoTicket added in v0.5.1

type VideoTicket struct {
	// Play URL, it is normally a m3u8 URL.
	Url string
	// Request headers which SHOULD be sent with play URL.
	Headers map[string]string
	// File name.
	FileName string
	// File size.
	FileSize int64
	// Video duration in seconds.
	Duration float64
	// Video width.
	Width int
	// Video height.
	Height int
}

VideoTicket contains all required arguments to play a cloud video.

Directories

Path Synopsis
internal
oss
Package lowlevel exposes the low-level API client and specs that are used by Agent.
Package lowlevel exposes the low-level API client and specs that are used by Agent.
api
Package plugin declares some interfaces that allow developer customizing elevengo agent.
Package plugin declares some interfaces that allow developer customizing elevengo agent.

Jump to

Keyboard shortcuts

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