base

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: GPL-3.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

View Source
const (
	HttpCodeOK             = 200
	HttpCodePartialContent = 206

	HttpHeaderRange              = "Range"
	HttpHeaderContentLength      = "Content-Length"
	HttpHeaderContentRange       = "Content-Range"
	HttpHeaderContentDisposition = "Content-Disposition"
	HttpHeaderUserAgent          = "User-Agent"

	HttpHeaderRangeFormat = "bytes=%d-%d"
)
View Source
const (
	AgentName = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
)

Variables

View Source
var (
	NotFound  = errors.New("not found")
	BadParams = errors.New("bad params")
)

Functions

func ParseOptsExtra

func ParseOptsExtra[E any](opts *Options) error

func ParseReqExtra

func ParseReqExtra[E any](req *Request) error

Types

type FileInfo

type FileInfo struct {
	Name string `json:"name"`
	Path string `json:"path"`
	Size int64  `json:"size"`

	Req *Request `json:"req"`
}

type Options

type Options struct {
	// Download file name
	Name string `json:"name"`
	// Download file path
	Path string `json:"path"`
	// Select file indexes to download
	SelectFiles []int `json:"selectFiles"`
	// Extra info for specific fetcher
	Extra any `json:"extra"`
}

Options for download

func (*Options) Clone added in v1.4.0

func (o *Options) Clone() *Options

func (*Options) InitSelectFiles added in v1.4.0

func (o *Options) InitSelectFiles(fileSize int)

type Request

type Request struct {
	URL   string `json:"url"`
	Extra any    `json:"extra"`
}

Request download request

type Resource

type Resource struct {
	// if name is not empty, the resource is a folder and the name is the folder name
	Name string `json:"name"`
	Size int64  `json:"size"`
	// is support range download
	Range bool `json:"range"`
	// file list
	Files []*FileInfo `json:"files"`
	Hash  string      `json:"hash"`
}

Resource download resource

func (*Resource) CalcSize added in v1.4.0

func (r *Resource) CalcSize()

func (*Resource) Validate added in v1.4.0

func (r *Resource) Validate() error

type Status

type Status string
const (
	DownloadStatusReady   Status = "ready" // task create but not start
	DownloadStatusRunning Status = "running"
	DownloadStatusPause   Status = "pause"
	DownloadStatusWait    Status = "wait" // task is wait for running
	DownloadStatusError   Status = "error"
	DownloadStatusDone    Status = "done"
)

Jump to

Keyboard shortcuts

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