Documentation
¶
Overview ¶
Package server provides the HTTP server for the web UI and REST API.
Index ¶
- type Config
- type DownloadRequest
- type ErrorResponse
- type Job
- type JobFileProgress
- type JobManager
- func (m *JobManager) CancelJob(id string) bool
- func (m *JobManager) CreateJob(req DownloadRequest) (*Job, bool, error)
- func (m *JobManager) DeleteJob(id string) bool
- func (m *JobManager) GetJob(id string) (*Job, bool)
- func (m *JobManager) ListJobs() []*Job
- func (m *JobManager) Subscribe() chan *Job
- func (m *JobManager) Unsubscribe(ch chan *Job)
- type JobProgress
- type JobStatus
- type PlanFile
- type PlanResponse
- type Server
- type SettingsResponse
- type SuccessResponse
- type WSClient
- type WSHub
- type WSMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Addr string
Port int
Token string // HuggingFace token
ModelsDir string // Output directory for models (not configurable via API)
DatasetsDir string // Output directory for datasets (not configurable via API)
Concurrency int
MaxActive int
MultipartThreshold string // Minimum size for multipart download
Verify string // Verification mode: none, size, sha256
Retries int // Number of retry attempts
AllowedOrigins []string // CORS origins
Endpoint string // Custom HuggingFace endpoint (e.g., for mirrors)
}
Config holds server configuration.
type DownloadRequest ¶
type DownloadRequest struct {
Repo string `json:"repo"`
Revision string `json:"revision,omitempty"`
Dataset bool `json:"dataset,omitempty"`
Filters []string `json:"filters,omitempty"`
Excludes []string `json:"excludes,omitempty"`
AppendFilterSubdir bool `json:"appendFilterSubdir,omitempty"`
DryRun bool `json:"dryRun,omitempty"`
}
DownloadRequest is the request body for starting a download. Note: Output path is NOT configurable via API for security reasons. The server uses its configured OutputDir (Models/ for models, Datasets/ for datasets).
type ErrorResponse ¶
ErrorResponse represents an API error.
type Job ¶
type Job struct {
ID string `json:"id"`
Repo string `json:"repo"`
Revision string `json:"revision"`
IsDataset bool `json:"isDataset,omitempty"`
Filters []string `json:"filters,omitempty"`
Excludes []string `json:"excludes,omitempty"`
OutputDir string `json:"outputDir"`
Status JobStatus `json:"status"`
Progress JobProgress `json:"progress"`
Error string `json:"error,omitempty"`
CreatedAt time.Time `json:"createdAt"`
StartedAt *time.Time `json:"startedAt,omitempty"`
EndedAt *time.Time `json:"endedAt,omitempty"`
Files []JobFileProgress `json:"files,omitempty"`
// contains filtered or unexported fields
}
Job represents a download job.
type JobFileProgress ¶
type JobFileProgress struct {
Path string `json:"path"`
TotalBytes int64 `json:"totalBytes"`
Downloaded int64 `json:"downloaded"`
Status string `json:"status"` // pending, active, complete, skipped, error
}
JobFileProgress holds per-file progress.
type JobManager ¶
type JobManager struct {
// contains filtered or unexported fields
}
JobManager manages download jobs.
func NewJobManager ¶
func NewJobManager(cfg Config, wsHub *WSHub) *JobManager
NewJobManager creates a new job manager.
func (*JobManager) CancelJob ¶
func (m *JobManager) CancelJob(id string) bool
CancelJob cancels a running or queued job.
func (*JobManager) CreateJob ¶
func (m *JobManager) CreateJob(req DownloadRequest) (*Job, bool, error)
CreateJob creates a new download job. Returns existing job if same repo+revision+dataset is already in progress.
func (*JobManager) DeleteJob ¶
func (m *JobManager) DeleteJob(id string) bool
DeleteJob removes a job from the list.
func (*JobManager) GetJob ¶
func (m *JobManager) GetJob(id string) (*Job, bool)
GetJob retrieves a job by ID.
func (*JobManager) Subscribe ¶
func (m *JobManager) Subscribe() chan *Job
Subscribe adds a listener for job updates.
func (*JobManager) Unsubscribe ¶
func (m *JobManager) Unsubscribe(ch chan *Job)
Unsubscribe removes a listener.
type JobProgress ¶
type JobProgress struct {
TotalFiles int `json:"totalFiles"`
CompletedFiles int `json:"completedFiles"`
TotalBytes int64 `json:"totalBytes"`
DownloadedBytes int64 `json:"downloadedBytes"`
BytesPerSecond int64 `json:"bytesPerSecond"`
}
JobProgress holds aggregate progress info.
type PlanResponse ¶
type PlanResponse struct {
Repo string `json:"repo"`
Revision string `json:"revision"`
Files []PlanFile `json:"files"`
TotalSize int64 `json:"totalSize"`
TotalFiles int `json:"totalFiles"`
}
PlanResponse is the response for a dry-run/plan request.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the HTTP server for hfdownloader.
type SettingsResponse ¶
type SettingsResponse struct {
Token string `json:"token,omitempty"`
ModelsDir string `json:"modelsDir"`
DatasetsDir string `json:"datasetsDir"`
Concurrency int `json:"connections"`
MaxActive int `json:"maxActive"`
MultipartThreshold string `json:"multipartThreshold"`
Verify string `json:"verify"`
Retries int `json:"retries"`
Endpoint string `json:"endpoint,omitempty"`
}
SettingsResponse represents current settings.
type SuccessResponse ¶
type SuccessResponse struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
}
SuccessResponse represents a simple success message.
type WSClient ¶
type WSClient struct {
// contains filtered or unexported fields
}
WSClient represents a connected WebSocket client.
type WSHub ¶
type WSHub struct {
// contains filtered or unexported fields
}
WSHub manages WebSocket clients and broadcasts.
func (*WSHub) BroadcastEvent ¶
BroadcastEvent sends a progress event to all clients.
func (*WSHub) BroadcastJob ¶
BroadcastJob sends a job update to all clients.
func (*WSHub) ClientCount ¶
ClientCount returns the number of connected clients.