server

package
v0.13.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SessionCookieName is the name of the session cookie
	SessionCookieName = "vget_session"
	// SessionDuration is the duration for session tokens (24 hours)
	SessionDuration = 24 * time.Hour
	// APITokenDuration is the duration for API tokens (1 year)
	APITokenDuration = 365 * 24 * time.Hour
)

Variables

This section is empty.

Functions

func GetDistFS

func GetDistFS() fs.FS

GetDistFS returns the embedded dist filesystem Returns nil if dist directory doesn't exist (dev mode)

Types

type BulkDownloadRequest added in v0.11.6

type BulkDownloadRequest struct {
	URLs []string `json:"urls" binding:"required"`
}

BulkDownloadRequest is the request body for POST /bulk-download

type ConfigRequest

type ConfigRequest struct {
	OutputDir string `json:"output_dir,omitempty"`
}

ConfigRequest is the request body for PUT /config

type ConfigSetRequest added in v0.8.3

type ConfigSetRequest struct {
	Key   string `json:"key" binding:"required"`
	Value string `json:"value"`
}

ConfigSetRequest is the request body for POST /config

type DownloadFunc

type DownloadFunc func(ctx context.Context, url, outputPath string, progressFn func(downloaded, total int64)) error

DownloadFunc is the function signature for downloading a URL It receives the job context, URL, output path, and a progress callback

type DownloadRequest

type DownloadRequest struct {
	URL        string `json:"url" binding:"required"`
	Filename   string `json:"filename,omitempty"`
	ReturnFile bool   `json:"return_file,omitempty"`
}

DownloadRequest is the request body for POST /download

type GenerateTokenRequest added in v0.12.13

type GenerateTokenRequest struct {
	Payload map[string]any `json:"payload,omitempty"`
}

GenerateTokenRequest is the request body for POST /api/auth/token

type HistoryDB added in v0.12.16

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

HistoryDB manages SQLite database for download history

func NewHistoryDB added in v0.12.16

func NewHistoryDB() (*HistoryDB, error)

NewHistoryDB creates and initializes the history database

func (*HistoryDB) ClearHistory added in v0.12.16

func (h *HistoryDB) ClearHistory() (int64, error)

ClearHistory deletes all history records

func (*HistoryDB) Close added in v0.12.16

func (h *HistoryDB) Close() error

Close closes the database connection

func (*HistoryDB) DeleteRecord added in v0.12.16

func (h *HistoryDB) DeleteRecord(id string) error

DeleteRecord deletes a single history record

func (*HistoryDB) GetHistory added in v0.12.16

func (h *HistoryDB) GetHistory(limit, offset int) ([]HistoryRecord, int, error)

GetHistory returns download history with pagination

func (*HistoryDB) GetStats added in v0.12.16

func (h *HistoryDB) GetStats() (completed int, failed int, totalBytes int64, err error)

GetStats returns download statistics

func (*HistoryDB) RecordJob added in v0.12.16

func (h *HistoryDB) RecordJob(job *Job) error

RecordJob saves a completed or failed job to history

type HistoryRecord added in v0.12.16

type HistoryRecord struct {
	ID          string `json:"id"`
	URL         string `json:"url"`
	Filename    string `json:"filename"`
	Status      string `json:"status"` // "completed" or "failed"
	SizeBytes   int64  `json:"size_bytes"`
	StartedAt   int64  `json:"started_at"`   // Unix timestamp
	CompletedAt int64  `json:"completed_at"` // Unix timestamp
	Duration    int64  `json:"duration_seconds"`
	Error       string `json:"error,omitempty"`
}

HistoryRecord represents a completed download in history

type JWTClaims added in v0.12.13

type JWTClaims struct {
	TokenType string         `json:"type"` // "session" or "api"
	Custom    map[string]any `json:"custom,omitempty"`
	jwt.RegisteredClaims
}

JWTClaims represents the claims in a JWT token

type Job

type Job struct {
	ID         string    `json:"id"`
	URL        string    `json:"url"`
	Filename   string    `json:"filename,omitempty"`
	Status     JobStatus `json:"status"`
	Progress   float64   `json:"progress"`
	Downloaded int64     `json:"downloaded"` // bytes downloaded
	Total      int64     `json:"total"`      // total bytes (-1 if unknown)
	Error      string    `json:"error,omitempty"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
	// contains filtered or unexported fields
}

Job represents a download job

type JobQueue

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

JobQueue manages download jobs with a worker pool

func NewJobQueue

func NewJobQueue(maxConcurrent int, outputDir string, downloadFn DownloadFunc) *JobQueue

NewJobQueue creates a new job queue with the specified concurrency

func (*JobQueue) AddFailedJob added in v0.11.6

func (jq *JobQueue) AddFailedJob(rawURL, errorMsg string) *Job

AddFailedJob creates a job that immediately fails with the given error

func (*JobQueue) AddJob

func (jq *JobQueue) AddJob(rawURL, filename string) (*Job, error)

AddJob creates and queues a new download job

func (*JobQueue) CancelJob

func (jq *JobQueue) CancelJob(id string) bool

CancelJob cancels a job by ID

func (*JobQueue) ClearHistory added in v0.8.7

func (jq *JobQueue) ClearHistory() int

ClearHistory removes all completed, failed, and cancelled jobs

func (*JobQueue) GetAllJobs

func (jq *JobQueue) GetAllJobs() []*Job

GetAllJobs returns all jobs

func (*JobQueue) GetJob

func (jq *JobQueue) GetJob(id string) *Job

GetJob returns a job by ID

func (*JobQueue) RemoveJob added in v0.8.7

func (jq *JobQueue) RemoveJob(id string) bool

RemoveJob removes a single completed, failed, or cancelled job by ID

func (*JobQueue) SetHistoryDB added in v0.12.16

func (jq *JobQueue) SetHistoryDB(db *HistoryDB)

SetHistoryDB sets the history database for persisting completed downloads

func (*JobQueue) Start

func (jq *JobQueue) Start()

Start begins the worker pool and cleanup routine

func (*JobQueue) Stop

func (jq *JobQueue) Stop()

Stop gracefully shuts down the job queue

type JobStatus

type JobStatus string

JobStatus represents the current state of a download job

const (
	JobStatusQueued      JobStatus = "queued"
	JobStatusDownloading JobStatus = "downloading"
	JobStatusCompleted   JobStatus = "completed"
	JobStatusFailed      JobStatus = "failed"
	JobStatusCancelled   JobStatus = "cancelled"
)

type PodcastChannel added in v0.10.2

type PodcastChannel struct {
	ID           string `json:"id"`
	Title        string `json:"title"`
	Author       string `json:"author"`
	Description  string `json:"description"`
	EpisodeCount int    `json:"episode_count"`
	FeedURL      string `json:"feed_url,omitempty"` // iTunes only
	Source       string `json:"source"`             // "xiaoyuzhou" or "itunes"
}

type PodcastEpisode added in v0.10.2

type PodcastEpisode struct {
	ID          string `json:"id"`
	Title       string `json:"title"`
	PodcastName string `json:"podcast_name"`
	Duration    int    `json:"duration"` // seconds
	PubDate     string `json:"pub_date,omitempty"`
	DownloadURL string `json:"download_url"`
	Source      string `json:"source"` // "xiaoyuzhou" or "itunes"
}

type PodcastEpisodesRequest added in v0.10.2

type PodcastEpisodesRequest struct {
	PodcastID string `json:"podcast_id" binding:"required"`
	Source    string `json:"source" binding:"required"` // "xiaoyuzhou" or "itunes"
}

type PodcastSearchRequest added in v0.10.2

type PodcastSearchRequest struct {
	Query string `json:"query" binding:"required"`
	Lang  string `json:"lang"` // language code, defaults to config language
}

type PodcastSearchResult added in v0.10.2

type PodcastSearchResult struct {
	Source   string           `json:"source"`   // "xiaoyuzhou" or "itunes"
	Podcasts []PodcastChannel `json:"podcasts"` // podcast channels
	Episodes []PodcastEpisode `json:"episodes"` // individual episodes
}

type Response

type Response struct {
	Code    int    `json:"code"`
	Data    any    `json:"data"`
	Message string `json:"message"`
}

Response is the standard API response structure

type Server

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

Server is the HTTP server for vget

func NewServer

func NewServer(port int, outputDir, apiKey string, maxConcurrent int) *Server

NewServer creates a new HTTP server

func (*Server) Start

func (s *Server) Start() error

Start starts the HTTP server

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully shuts down the server

type TorrentAddRequest added in v0.10.0

type TorrentAddRequest struct {
	URL      string `json:"url" binding:"required"` // Magnet link or .torrent URL
	SavePath string `json:"save_path,omitempty"`
	Paused   bool   `json:"paused,omitempty"`
}

TorrentAddRequest is the request body for POST /torrent

type TorrentConfigRequest added in v0.10.0

type TorrentConfigRequest struct {
	Enabled         bool   `json:"enabled"`
	Client          string `json:"client"`
	Host            string `json:"host"`
	Username        string `json:"username"`
	Password        string `json:"password"`
	UseHTTPS        bool   `json:"use_https"`
	DefaultSavePath string `json:"default_save_path"`
}

TorrentConfigRequest is the request body for POST /config/torrent

type TrackRequest added in v0.8.6

type TrackRequest struct {
	TrackingNumber string `json:"tracking_number" binding:"required"`
	Courier        string `json:"courier" binding:"required"`
}

TrackRequest is the request body for POST /kuaidi100

type WebDAVConfigRequest added in v0.8.3

type WebDAVConfigRequest struct {
	Name     string `json:"name" binding:"required"`
	URL      string `json:"url" binding:"required"`
	Username string `json:"username"`
	Password string `json:"password"`
}

WebDAVConfigRequest is the request body for WebDAV server operations

type WebDAVDownloadRequest added in v0.10.0

type WebDAVDownloadRequest struct {
	Remote string   `json:"remote" binding:"required"`
	Files  []string `json:"files" binding:"required"`
}

WebDAVDownloadRequest is the request body for POST /api/webdav/download

type WebDAVFileInfo added in v0.10.0

type WebDAVFileInfo struct {
	Name  string `json:"name"`
	Path  string `json:"path"`
	Size  int64  `json:"size"`
	IsDir bool   `json:"isDir"`
}

WebDAVFileInfo is the response for a single file/directory

type WebDAVRemoteInfo added in v0.10.0

type WebDAVRemoteInfo struct {
	Name    string `json:"name"`
	URL     string `json:"url"`
	HasAuth bool   `json:"hasAuth"`
}

WebDAVRemoteInfo is the response for a single remote

Jump to

Keyboard shortcuts

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