Documentation
¶
Index ¶
- Constants
- Variables
- func Boot() *boot
- func GetMultiPartArchiveBaseName(filename string) string
- type ActivationEvent
- type ArchivePartInfo
- type BoltStorage
- func (b *BoltStorage) Clear() error
- func (b *BoltStorage) Close() error
- func (b *BoltStorage) Delete(bucket string, key string) error
- func (b *BoltStorage) Get(bucket string, key string, v any) (bool, error)
- func (b *BoltStorage) List(bucket string, v any) error
- func (b *BoltStorage) Pop(bucket string, key string, v any) error
- func (b *BoltStorage) Put(bucket string, key string, v any) error
- func (b *BoltStorage) Setup(buckets []string) error
- type ContextStorage
- type Downloader
- func (d *Downloader) Clear() error
- func (d *Downloader) Close() error
- func (d *Downloader) Continue(filter *TaskFilter) (err error)
- func (d *Downloader) ContinueBatch(filter *TaskFilter) (err error)
- func (d *Downloader) Create(rrId string) (taskId string, err error)
- func (d *Downloader) CreateDirect(req *base.Request, opts *base.Options) (taskId string, err error)
- func (d *Downloader) CreateDirectBatch(req *base.CreateTaskBatch) (taskId []string, err error)
- func (d *Downloader) Delete(filter *TaskFilter, force bool) (err error)
- func (d *Downloader) DeleteExtension(identity string) error
- func (d *Downloader) ExtensionPath(ext *Extension) string
- func (d *Downloader) GetConfig() (*base.DownloaderStoreConfig, error)
- func (d *Downloader) GetExtension(identity string) (*Extension, error)
- func (d *Downloader) GetExtensions() []*Extension
- func (d *Downloader) GetTask(id string) *Task
- func (d *Downloader) GetTasks() []*Task
- func (d *Downloader) GetTasksByFilter(filter *TaskFilter) []*Task
- func (d *Downloader) InstallExtensionByFolder(path string, devMode bool) (*Extension, error)
- func (d *Downloader) InstallExtensionByGit(url string) (*Extension, error)
- func (d *Downloader) Listener(fn Listener)
- func (d *Downloader) Pause(filter *TaskFilter) (err error)
- func (d *Downloader) PutConfig(v *base.DownloaderStoreConfig) error
- func (d *Downloader) Resolve(req *base.Request, opts *base.Options) (rr *ResolveResult, err error)
- func (d *Downloader) SendTestWebhook() error
- func (d *Downloader) Setup() error
- func (d *Downloader) Stats(id string) (sr any, err error)
- func (d *Downloader) SwitchExtension(identity string, status bool) error
- func (d *Downloader) TestWebhookUrl(url string) error
- func (d *Downloader) UpdateExtensionSettings(identity string, settings map[string]any) error
- func (d *Downloader) UpgradeCheckExtension(identity string) (newVersion string, err error)
- func (d *Downloader) UpgradeExtension(identity string) error
- type DownloaderConfig
- type Event
- type EventKey
- type Extension
- type ExtensionInfo
- type ExtensionTask
- type ExtractProgressCallback
- type ExtractStatus
- type ExtractionJob
- type ExtractionQueue
- func (q *ExtractionQueue) Enqueue(job *ExtractionJob) *ExtractionJob
- func (q *ExtractionQueue) EnqueueAndWait(job *ExtractionJob)
- func (q *ExtractionQueue) HasPendingJob(id string) bool
- func (q *ExtractionQueue) IsRunning() bool
- func (q *ExtractionQueue) QueueLength() int
- func (q *ExtractionQueue) RemovePendingJob(id string) bool
- func (q *ExtractionQueue) Start()
- func (q *ExtractionQueue) Stop()
- type Instance
- type InstanceEvents
- type InstanceLogger
- type Listener
- type Match
- type MemStorage
- func (n *MemStorage) Clear() error
- func (n *MemStorage) Close() error
- func (n *MemStorage) Delete(bucket string, key string) error
- func (n *MemStorage) Get(bucket string, key string, v any) (bool, error)
- func (n *MemStorage) List(bucket string, v any) error
- func (n *MemStorage) Pop(bucket string, key string, v any) error
- func (n *MemStorage) Put(bucket string, key string, v any) error
- func (n *MemStorage) Setup(buckets []string) error
- type OnDoneContext
- type OnErrorContext
- type OnResolveContext
- type OnStartContext
- type Option
- type Progress
- type Repository
- type ResolveResult
- type Script
- type Setting
- type SettingType
- type Storage
- type Task
- type TaskFilter
- type WebhookData
- type WebhookEvent
- type WebhookPayload
Constants ¶
const ( EventKeyStart = "start" EventKeyPause = "pause" EventKeyProgress = "progress" EventKeyError = "error" EventKeyDelete = "delete" EventKeyDone = "done" EventKeyFinally = "finally" )
Variables ¶
var ( ErrTaskNotFound = errors.New("task not found") ErrUnSupportedProtocol = errors.New("unsupported protocol") )
var ( ErrExtensionNoManifest = fmt.Errorf("manifest.json not found") ErrExtensionNotFound = fmt.Errorf("extension not found") )
Functions ¶
func GetMultiPartArchiveBaseName ¶ added in v1.9.0
GetMultiPartArchiveBaseName returns the base name for a multi-part archive This is used to group related parts together
Types ¶
type ActivationEvent ¶ added in v1.4.0
type ActivationEvent string
const ( EventOnResolve ActivationEvent = "onResolve" EventOnStart ActivationEvent = "onStart" EventOnError ActivationEvent = "onError" EventOnDone ActivationEvent = "onDone" )
type ArchivePartInfo ¶ added in v1.9.0
type ArchivePartInfo struct {
// IsMultiPart indicates if this file is part of a multi-part archive
IsMultiPart bool
// BaseName is the common base name for all parts (without part number extension)
BaseName string
// PartNumber is the part number (1-indexed)
PartNumber int
// FirstPartPath is the path to the first part of the archive
FirstPartPath string
// Pattern indicates which pattern matched (for determining extraction method)
Pattern string
}
ArchivePartInfo contains information about a multi-part archive
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) 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(filter *TaskFilter) (err error)
Continue specific tasks, if continue tasks will exceed maxRunning, it needs pause some running tasks before that
func (*Downloader) ContinueBatch ¶ added in v1.6.0
func (d *Downloader) ContinueBatch(filter *TaskFilter) (err error)
func (*Downloader) CreateDirect ¶ added in v1.3.1
func (*Downloader) CreateDirectBatch ¶ added in v1.5.7
func (d *Downloader) CreateDirectBatch(req *base.CreateTaskBatch) (taskId []string, err error)
func (*Downloader) Delete ¶
func (d *Downloader) Delete(filter *TaskFilter, 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() (*base.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) GetTasksByFilter ¶ added in v1.6.0
func (d *Downloader) GetTasksByFilter(filter *TaskFilter) []*Task
GetTasksByFilter get tasks by filter, if filter is nil, return all tasks return tasks and if match all tasks
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(filter *TaskFilter) (err error)
func (*Downloader) PutConfig ¶
func (d *Downloader) PutConfig(v *base.DownloaderStoreConfig) error
func (*Downloader) Resolve ¶
func (d *Downloader) Resolve(req *base.Request, opts *base.Options) (rr *ResolveResult, err error)
func (*Downloader) SendTestWebhook ¶ added in v1.8.3
func (d *Downloader) SendTestWebhook() error
SendTestWebhook sends a test webhook with a simulated payload Returns error if any webhook URL does not respond with HTTP 200
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) TestWebhookUrl ¶ added in v1.8.3
func (d *Downloader) TestWebhookUrl(url string) error
TestWebhookUrl tests a single webhook URL with a simulated payload Returns error if the URL does not respond with HTTP 200
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
FetchManagers []fetcher.FetcherManager
RefreshInterval int // RefreshInterval time duration to refresh task progress(ms)
Storage Storage
StorageDir string
WhiteDownloadDirs []string
ProductionMode bool
*base.DownloaderStoreConfig
}
func (*DownloaderConfig) Init ¶
func (cfg *DownloaderConfig) Init() *DownloaderConfig
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
}
ExtensionTask is a wrapper of Task, it's used to interact with extension scripts. Avoid extension scripts modifying task directly, use ExtensionTask to encapsulate task, only some fields can be modified, such as request info.
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 ExtractProgressCallback ¶ added in v1.9.0
ExtractProgressCallback is called to report extraction progress
type ExtractStatus ¶ added in v1.9.0
type ExtractStatus string
ExtractStatus represents the current status of archive extraction
const ( // ExtractStatusNone indicates extraction has not started ExtractStatusNone ExtractStatus = "" // ExtractStatusQueued indicates extraction is waiting in the queue ExtractStatusQueued ExtractStatus = "queued" // ExtractStatusWaitingParts indicates waiting for other multi-part archive parts to complete ExtractStatusWaitingParts ExtractStatus = "waitingParts" // ExtractStatusExtracting indicates extraction is in progress ExtractStatusExtracting ExtractStatus = "extracting" // ExtractStatusDone indicates extraction completed successfully ExtractStatusDone ExtractStatus = "done" // ExtractStatusError indicates extraction failed ExtractStatusError ExtractStatus = "error" )
type ExtractionJob ¶ added in v1.9.0
type ExtractionJob struct {
// ID is a unique identifier for this job (usually task ID or multi-part base name)
ID string
// Execute is the function that performs the actual extraction
Execute func()
// contains filtered or unexported fields
}
ExtractionJob represents a single extraction job in the queue
func NewExtractionJob ¶ added in v1.9.0
func NewExtractionJob(id string, execute func()) *ExtractionJob
NewExtractionJob creates a new extraction job
func (*ExtractionJob) Wait ¶ added in v1.9.0
func (j *ExtractionJob) Wait()
Wait blocks until the job has been executed
type ExtractionQueue ¶ added in v1.9.0
type ExtractionQueue struct {
// contains filtered or unexported fields
}
ExtractionQueue manages a queue of extraction jobs to prevent resource exhaustion by ensuring only one extraction (or one multi-part archive extraction) runs at a time
func GetExtractionQueue ¶ added in v1.9.0
func GetExtractionQueue() *ExtractionQueue
GetExtractionQueue returns the global extraction queue instance
func NewExtractionQueue ¶ added in v1.9.0
func NewExtractionQueue() *ExtractionQueue
NewExtractionQueue creates a new extraction queue
func (*ExtractionQueue) Enqueue ¶ added in v1.9.0
func (q *ExtractionQueue) Enqueue(job *ExtractionJob) *ExtractionJob
Enqueue adds a new extraction job to the queue The job will be executed when its turn comes (FIFO order) Returns the job so the caller can wait for completion if needed
func (*ExtractionQueue) EnqueueAndWait ¶ added in v1.9.0
func (q *ExtractionQueue) EnqueueAndWait(job *ExtractionJob)
EnqueueAndWait adds a new extraction job to the queue and waits for it to complete
func (*ExtractionQueue) HasPendingJob ¶ added in v1.9.0
func (q *ExtractionQueue) HasPendingJob(id string) bool
HasPendingJob checks if there's a pending job with the given ID
func (*ExtractionQueue) IsRunning ¶ added in v1.9.0
func (q *ExtractionQueue) IsRunning() bool
IsRunning returns true if the queue worker is running
func (*ExtractionQueue) QueueLength ¶ added in v1.9.0
func (q *ExtractionQueue) QueueLength() int
QueueLength returns the current number of pending jobs in the queue
func (*ExtractionQueue) RemovePendingJob ¶ added in v1.9.0
func (q *ExtractionQueue) RemovePendingJob(id string) bool
RemovePendingJob removes a pending job with the given ID from the queue Returns true if a job was removed, false if not found Note: This cannot remove a job that is currently being executed
func (*ExtractionQueue) Start ¶ added in v1.9.0
func (q *ExtractionQueue) Start()
Start starts the queue worker that processes jobs sequentially
func (*ExtractionQueue) Stop ¶ added in v1.9.0
func (q *ExtractionQueue) Stop()
Stop stops the queue worker gracefully It waits for the current job to complete but discards pending jobs
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) OnDone ¶ added in v1.5.9
func (h InstanceEvents) OnDone(fn 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 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) Setup ¶
func (n *MemStorage) Setup(buckets []string) error
type OnDoneContext ¶ added in v1.5.9
type OnDoneContext struct {
Task *Task `json:"task"`
}
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 OnStartContext ¶ added in v1.4.2
type OnStartContext struct {
Task *ExtensionTask `json:"task"`
}
type Progress ¶
type Progress struct {
// Total download time(ns)
Used int64 `json:"used"`
// Download speed(bytes/s)
Speed int64 `json:"speed"`
// Downloaded size(bytes)
Downloaded int64 `json:"downloaded"`
// Uploaded speed(bytes/s)
UploadSpeed int64 `json:"uploadSpeed"`
// Uploaded size(bytes)
Uploaded int64 `json:"uploaded"`
// ExtractStatus indicates the current status of archive extraction
ExtractStatus ExtractStatus `json:"extractStatus"`
// ExtractProgress is the percentage of extraction completed (0-100)
ExtractProgress int `json:"extractProgress"`
// MultiPartBaseName is set for multi-part archives to group related parts
MultiPartBaseName string `json:"multiPartBaseName,omitempty"`
// MultiPartNumber is the part number for multi-part archives (1-indexed)
MultiPartNumber int `json:"multiPartNumber,omitempty"`
// MultiPartIsFirst indicates if this is the first part of a multi-part archive
MultiPartIsFirst bool `json:"multiPartIsFirst,omitempty"`
}
type Repository ¶ added in v1.4.0
type ResolveResult ¶
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 Task ¶
type Task struct {
ID string `json:"id"`
Protocol string `json:"protocol"`
Meta *fetcher.FetcherMeta `json:"meta"`
Status base.Status `json:"status"`
Uploading bool `json:"uploading"`
Progress *Progress `json:"progress"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
// contains filtered or unexported fields
}
func (*Task) MarshalJSON ¶ added in v1.5.9
type TaskFilter ¶ added in v1.6.0
func (*TaskFilter) IsEmpty ¶ added in v1.6.0
func (f *TaskFilter) IsEmpty() bool
type WebhookData ¶ added in v1.8.3
type WebhookData struct {
Event WebhookEvent `json:"event"`
Time int64 `json:"time"` // Unix timestamp in milliseconds
Payload *WebhookPayload `json:"payload"`
}
WebhookData is the data sent to webhook URLs
type WebhookEvent ¶ added in v1.8.3
type WebhookEvent string
WebhookEvent represents the type of webhook event
const ( WebhookEventDownloadDone WebhookEvent = "DOWNLOAD_DONE" WebhookEventDownloadError WebhookEvent = "DOWNLOAD_ERROR" )
type WebhookPayload ¶ added in v1.8.3
type WebhookPayload struct {
Task *Task `json:"task"`
}
WebhookPayload contains the task data