download

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: GPL-3.0 Imports: 34 Imported by: 3

Documentation

Index

Constants

View Source
const (
	EventKeyStart    = "start"
	EventKeyPause    = "pause"
	EventKeyProgress = "progress"
	EventKeyError    = "error"
	EventKeyDelete   = "delete"
	EventKeyDone     = "done"
	EventKeyFinally  = "finally"
)

Variables

View Source
var (
	ErrTaskNotFound        = errors.New("task not found")
	ErrUnSupportedProtocol = errors.New("unsupported protocol")
)
View Source
var (
	ErrExtensionNoManifest = fmt.Errorf("manifest.json not found")
	ErrExtensionNotFound   = fmt.Errorf("extension not found")
)

Functions

func Boot

func Boot() *boot

Types

type ActivationEvent added in v1.4.0

type ActivationEvent string
const (
	EventOnResolve ActivationEvent = "onResolve"
	EventOnStart   ActivationEvent = "onStart"
	EventOnError   ActivationEvent = "onError"
)

type BoltStorage

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

func NewBoltStorage

func NewBoltStorage(dir string) *BoltStorage

func (*BoltStorage) Clear

func (b *BoltStorage) Clear() error

func (*BoltStorage) Close

func (b *BoltStorage) Close() error

func (*BoltStorage) Delete

func (b *BoltStorage) Delete(bucket string, key string) error

func (*BoltStorage) Get

func (b *BoltStorage) Get(bucket string, key string, v any) (bool, error)

func (*BoltStorage) List

func (b *BoltStorage) List(bucket string, v any) error

func (*BoltStorage) Pop

func (b *BoltStorage) Pop(bucket string, key string, v any) error

func (*BoltStorage) Put

func (b *BoltStorage) Put(bucket string, key string, v any) error

func (*BoltStorage) Setup

func (b *BoltStorage) Setup(buckets []string) error

type ContextStorage added in v1.4.1

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

func (*ContextStorage) Clear added in v1.4.1

func (s *ContextStorage) Clear()

func (*ContextStorage) Get added in v1.4.1

func (s *ContextStorage) Get(key string) any

func (*ContextStorage) Keys added in v1.4.1

func (s *ContextStorage) Keys() []string

func (*ContextStorage) Remove added in v1.4.1

func (s *ContextStorage) Remove(key string)

func (*ContextStorage) Set added in v1.4.1

func (s *ContextStorage) Set(key string, value string)

type Downloader

type Downloader struct {
	Logger          *logger.Logger
	ExtensionLogger *logger.Logger
	// contains filtered or unexported fields
}

func NewDownloader

func NewDownloader(cfg *DownloaderConfig) *Downloader

func (*Downloader) Clear

func (d *Downloader) Clear() error

func (*Downloader) Close

func (d *Downloader) Close() error

func (*Downloader) Continue

func (d *Downloader) Continue(id string) (err error)

func (*Downloader) ContinueAll added in v1.3.2

func (d *Downloader) ContinueAll() (err error)

func (*Downloader) Create

func (d *Downloader) Create(rrId string, opts *base.Options) (taskId string, err error)

func (*Downloader) CreateDirect added in v1.3.1

func (d *Downloader) CreateDirect(req *base.Request, opts *base.Options) (taskId string, err error)

func (*Downloader) Delete

func (d *Downloader) Delete(id string, force bool) (err error)

func (*Downloader) DeleteByStatues added in v1.5.4

func (d *Downloader) DeleteByStatues(statues []base.Status, force bool) (err error)

func (*Downloader) DeleteExtension added in v1.4.0

func (d *Downloader) DeleteExtension(identity string) error

func (*Downloader) ExtensionPath added in v1.4.0

func (d *Downloader) ExtensionPath(ext *Extension) string

func (*Downloader) GetConfig

func (d *Downloader) GetConfig() (*DownloaderStoreConfig, error)

func (*Downloader) GetExtension added in v1.4.0

func (d *Downloader) GetExtension(identity string) (*Extension, error)

func (*Downloader) GetExtensions added in v1.4.0

func (d *Downloader) GetExtensions() []*Extension

func (*Downloader) GetTask

func (d *Downloader) GetTask(id string) *Task

func (*Downloader) GetTasks

func (d *Downloader) GetTasks() []*Task

func (*Downloader) GetTasksByStatues added in v1.5.4

func (d *Downloader) GetTasksByStatues(statues []base.Status) []*Task

func (*Downloader) InstallExtensionByFolder added in v1.4.0

func (d *Downloader) InstallExtensionByFolder(path string, devMode bool) (*Extension, error)

func (*Downloader) InstallExtensionByGit added in v1.4.0

func (d *Downloader) InstallExtensionByGit(url string) (*Extension, error)

func (*Downloader) Listener

func (d *Downloader) Listener(fn Listener)

func (*Downloader) Pause

func (d *Downloader) Pause(id string) (err error)

func (*Downloader) PauseAll added in v1.3.2

func (d *Downloader) PauseAll() (err error)

func (*Downloader) PutConfig

func (d *Downloader) PutConfig(v *DownloaderStoreConfig) error

func (*Downloader) Resolve

func (d *Downloader) Resolve(req *base.Request) (rr *ResolveResult, err error)

func (*Downloader) Setup

func (d *Downloader) Setup() error

func (*Downloader) Stats added in v1.5.4

func (d *Downloader) Stats(id string) (sr any, err error)

func (*Downloader) SwitchExtension added in v1.4.0

func (d *Downloader) SwitchExtension(identity string, status bool) error

func (*Downloader) UpdateExtensionSettings added in v1.4.0

func (d *Downloader) UpdateExtensionSettings(identity string, settings map[string]any) error

func (*Downloader) UpgradeCheckExtension added in v1.4.0

func (d *Downloader) UpgradeCheckExtension(identity string) (newVersion string, err error)

UpgradeCheckExtension Check if there is a new version for the extension.

func (*Downloader) UpgradeExtension added in v1.4.0

func (d *Downloader) UpgradeExtension(identity string) error

type DownloaderConfig

type DownloaderConfig struct {
	Controller    *controller.Controller
	FetchBuilders []fetcher.FetcherBuilder

	RefreshInterval int `json:"refreshInterval"` // RefreshInterval time duration to refresh task progress(ms)
	Storage         Storage
	StorageDir      string

	ProductionMode bool

	*DownloaderStoreConfig
}

func (*DownloaderConfig) Init

func (cfg *DownloaderConfig) Init() *DownloaderConfig

type DownloaderProxyConfig added in v1.5.1

type DownloaderProxyConfig struct {
	Enable bool   `json:"enable"`
	Scheme string `json:"scheme"`
	Host   string `json:"host"`
	Usr    string `json:"usr"`
	Pwd    string `json:"pwd"`
}

type DownloaderStoreConfig

type DownloaderStoreConfig struct {
	FirstLoad bool `json:"-"` // FirstLoad is the flag that the config is first time init and not from store

	DownloadDir    string                 `json:"downloadDir"`    // DownloadDir is the default directory to save the downloaded files
	MaxRunning     int                    `json:"maxRunning"`     // MaxRunning is the max running download count
	ProtocolConfig map[string]any         `json:"protocolConfig"` // ProtocolConfig is special config for each protocol
	Extra          map[string]any         `json:"extra"`
	Proxy          *DownloaderProxyConfig `json:"proxy"`
}

DownloaderStoreConfig is the config that can restore the downloader.

func (*DownloaderStoreConfig) Init added in v1.3.1

func (*DownloaderStoreConfig) ProxyUrl added in v1.5.1

func (cfg *DownloaderStoreConfig) ProxyUrl() *url.URL

type Event

type Event struct {
	Key  EventKey
	Task *Task
	Err  error
}

type EventKey

type EventKey string

type Extension added in v1.4.0

type Extension struct {
	// Identity is global unique for an extension, it's a combination of author and name
	Identity    string `json:"identity"`
	Name        string `json:"name"`
	Author      string `json:"author"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Icon        string `json:"icon"`
	// Version semantic version string, like: 1.0.0
	Version string `json:"version"`
	// Homepage homepage url
	Homepage string `json:"homepage"`
	// Repository git repository info
	Repository *Repository `json:"repository"`
	Scripts    []*Script   `json:"scripts"`
	Settings   []*Setting  `json:"settings"`
	// Disabled if true, this extension will be ignored
	Disabled bool `json:"disabled"`

	DevMode bool `json:"devMode"`
	// DevPath is the local path of extension source code
	DevPath string `json:"devPath"`

	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

type ExtensionInfo added in v1.4.2

type ExtensionInfo struct {
	Identity string `json:"identity"`
	Name     string `json:"name"`
	Author   string `json:"author"`
	Title    string `json:"title"`
	Version  string `json:"version"`
}

func NewExtensionInfo added in v1.4.2

func NewExtensionInfo(ext *Extension) *ExtensionInfo

type ExtensionTask added in v1.5.2

type ExtensionTask struct {
	*Task
	// contains filtered or unexported fields
}

func NewExtensionTask added in v1.5.2

func NewExtensionTask(download *Downloader, task *Task) *ExtensionTask

func (*ExtensionTask) Continue added in v1.5.2

func (t *ExtensionTask) Continue() error

func (*ExtensionTask) Pause added in v1.5.2

func (t *ExtensionTask) Pause() error

type Instance added in v1.4.0

type Instance struct {
	Events   InstanceEvents  `json:"events"`
	Info     *ExtensionInfo  `json:"info"`
	Logger   *InstanceLogger `json:"logger"`
	Settings map[string]any  `json:"settings"`
	Storage  *ContextStorage `json:"storage"`
}

Instance inject to js context when extension script is activated

type InstanceEvents added in v1.4.0

type InstanceEvents map[ActivationEvent]goja.Callable

func (InstanceEvents) OnError added in v1.5.2

func (h InstanceEvents) OnError(fn goja.Callable)

func (InstanceEvents) OnResolve added in v1.4.0

func (h InstanceEvents) OnResolve(fn goja.Callable)

func (InstanceEvents) OnStart added in v1.4.2

func (h InstanceEvents) OnStart(fn goja.Callable)

type InstanceLogger added in v1.4.0

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

func (*InstanceLogger) Debug added in v1.4.0

func (l *InstanceLogger) Debug(msg ...goja.Value)

func (*InstanceLogger) Error added in v1.4.0

func (l *InstanceLogger) Error(msg ...goja.Value)

func (*InstanceLogger) Info added in v1.4.0

func (l *InstanceLogger) Info(msg ...goja.Value)

func (*InstanceLogger) Warn added in v1.4.0

func (l *InstanceLogger) Warn(msg ...goja.Value)

type Listener

type Listener func(event *Event)

type Match added in v1.4.2

type Match struct {
	// Urls match expression, refer to https://developer.chrome.com/docs/extensions/mv3/match_patterns/
	Urls []string `json:"urls"`
	// Labels match request labels
	Labels []string `json:"labels"`
}

type MemStorage

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

func NewMemStorage

func NewMemStorage() *MemStorage

func (*MemStorage) Clear

func (n *MemStorage) Clear() error

func (*MemStorage) Close

func (n *MemStorage) Close() error

func (*MemStorage) Delete

func (n *MemStorage) Delete(bucket string, key string) error

func (*MemStorage) Get

func (n *MemStorage) Get(bucket string, key string, v any) (bool, error)

func (*MemStorage) List

func (n *MemStorage) List(bucket string, v any) error

func (*MemStorage) Pop

func (n *MemStorage) Pop(bucket string, key string, v any) error

func (*MemStorage) Put

func (n *MemStorage) Put(bucket string, key string, v any) error

func (*MemStorage) Setup

func (n *MemStorage) Setup(buckets []string) error

type OnErrorContext added in v1.5.2

type OnErrorContext struct {
	Task  *ExtensionTask `json:"task"`
	Error error          `json:"error"`
}

type OnResolveContext added in v1.4.2

type OnResolveContext struct {
	Req *base.Request  `json:"req"`
	Res *base.Resource `json:"res"`
}

type OnStartContext added in v1.4.2

type OnStartContext struct {
	Task *ExtensionTask `json:"task"`
}

type Option added in v1.4.0

type Option struct {
	Label string `json:"label"`
	Value any    `json:"value"`
}

type Progress

type Progress struct {
	// 下载耗时(纳秒)
	Used int64 `json:"used"`
	// 每秒下载字节数
	Speed int64 `json:"speed"`
	// 已下载的字节数
	Downloaded int64 `json:"downloaded"`
}

type Repository added in v1.4.0

type Repository struct {
	Url       string `json:"url"`
	Directory string `json:"directory"`
}

type ResolveResult

type ResolveResult struct {
	ID  string         `json:"id"`
	Res *base.Resource `json:"res"`
}

type Script added in v1.4.0

type Script struct {
	// Event active event name
	Event string `json:"event"`
	// Match rules
	Match *Match `json:"match"`
	// Entry js script file path
	Entry string `json:"entry"`
}

type Setting added in v1.4.0

type Setting struct {
	Name        string `json:"name"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Required    bool   `json:"required"`
	// setting type
	Type SettingType `json:"type"`
	// setting value
	Value any `json:"value"`
	//Multiple bool      `json:"multiple"`
	Options []*Option `json:"options"`
}

type SettingType added in v1.4.0

type SettingType string
const (
	SettingTypeString  SettingType = "string"
	SettingTypeNumber  SettingType = "number"
	SettingTypeBoolean SettingType = "boolean"
)

type Storage

type Storage interface {
	Setup(buckets []string) error
	Put(bucket string, key string, v any) error
	Get(bucket string, key string, v any) (bool, error)
	List(bucket string, v any) error
	Pop(bucket string, key string, v any) error
	Delete(bucket string, key string) error

	Close() error
	Clear() error
}

type Task

type Task struct {
	ID        string               `json:"id"`
	Meta      *fetcher.FetcherMeta `json:"meta"`
	Status    base.Status          `json:"status"`
	Protocol  string               `json:"protocol"`
	Progress  *Progress            `json:"progress"`
	CreatedAt time.Time            `json:"createdAt"`
	UpdatedAt time.Time            `json:"updatedAt"`
	// contains filtered or unexported fields
}

func NewTask

func NewTask() *Task

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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