download

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionNotFound = errors.New("download session not found")
	ErrSessionExpired  = errors.New("download session expired")
)

Functions

This section is empty.

Types

type Manager

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

Handles download sessions and their temp-file lifecycle

func NewManager

func NewManager(tempDir string, sessionTTL time.Duration, log *logger.Logger) *Manager

New download manager and starts the cleanup loop

func (*Manager) CleanupSession

func (m *Manager) CleanupSession(id string)

Cleanup session and its temp file

func (*Manager) GetSession

func (m *Manager) GetSession(id string) (*Session, error)

Get session by ID

func (*Manager) InitSession

func (m *Manager) InitSession(filePath, filename string, totalSize int64, deleteAfter bool) *Session

Registers a file that is ready to be downloaded. Deletes file on cleanup if deleteAfter is true

func (*Manager) InitSessionFor

func (m *Manager) InitSessionFor(filePath, filename string, totalSize int64, deleteAfter bool, serverID, creatorUserID string) *Session

InitSessionFor creates a download session bound to an owning server and creating user, so the stream handler can authorize per-server instead of globally.

func (*Manager) Stop

func (m *Manager) Stop()

Stop manager and clean up sessions

func (*Manager) TempDir

func (m *Manager) TempDir() string

type Session

type Session struct {
	ID          string
	FilePath    string // file to serve
	Filename    string // suggested download filename
	TotalSize   int64
	DeleteAfter bool // if true, file is deleted on session cleanup
	ExpiresAt   time.Time

	// ServerID is the server this file belongs to and CreatorUserID the user
	// who requested it. The stream handler serves bytes straight off disk
	// using only the session id, so without these it can only enforce a
	// global permission - meaning any user holding files:read anywhere could
	// fetch another user's download if they learned the id.
	ServerID      string
	CreatorUserID string
}

A prepared download

Jump to

Keyboard shortcuts

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