remote

package
v1.14.5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package remote provides the remote download and update of artifact data from third-party sources such as API's.

Index

Constants

View Source
const (
	// UserAgent to send with the HTTP request.
	UserAgent = "Defacto2 Uploader form submission, thanks!"

	TimeoutShort = 8 * time.Second
	TimeoutLong  = 15 * time.Second
)

Variables

View Source
var (
	ErrBodyNil  = errors.New("remote: body is nil")
	ErrExist    = errors.New("remote: file already exists")
	ErrNoRecord = errors.New("remote: could not the get record from demozoo api")
	ErrStatus   = errors.New("remote: wrong status code")
	ErrTimeout  = errors.New("remote: the time duration is out of range")
)

Functions

func ReplaceURL added in v1.14.0

func ReplaceURL(sl *slog.Logger, rawURL string) string

ReplaceURL returns a valid URL if the provided rawURL is a known broken link to a scene.org file. Otherwise the rawURL is returned.

For example, the following rawURL:

`http://files.scene.org/view/demos/groups/trsi/ms-dos/trsiscxt.zip`

will return:

`https://files.scene.org/get/demos/groups/trsi/ms-dos/trsiscxt.zip`

Types

type DemozooLink struct {
	UUID        string   `json:"uuid"`          // UUID is the file production UUID.
	Github      string   `json:"github_repo"`   // GitHub is the GitHub repository URI.
	YouTube     string   `json:"youtube_video"` // YouTube is the YouTube watch video URI.
	Releaser1   string   `json:"releaser1"`     // Releaser1 is the first releaser of the file.
	Releaser2   string   `json:"releaser2"`     // Releaser2 is the second releaser of the file.
	Title       string   `json:"title"`         // Title is the file title.
	Filename    string   `json:"filename"`      // Filename is the file name of the download.
	Content     string   `json:"content"`       // Content is the file archive content.
	FileType    string   `json:"file_type"`     // Type is the file type.
	FileHash    string   `json:"file_hash"`     // Hash is the file integrity hash.
	Platform    string   `json:"platform"`      // Platform is the file platform.
	Section     string   `json:"section"`       // Section is the file section.
	Error       string   `json:"error"`         // Error is the error message if the download or record update failed.
	CreditText  []string `json:"credit_text"`   // credit_text, writer
	CreditCode  []string `json:"credit_code"`   // credit_program, programmer/coder
	CreditArt   []string `json:"credit_art"`    // credit_illustration, artist/graphics
	CreditAudio []string `json:"credit_audio"`  // credit_audio, musician/sound
	ID          int      `json:"id"`            // ID is the Demozoo production ID.
	Pouet       int      `json:"pouet_prod"`    // Pouet is the Pouet production ID.
	FileSize    int      `json:"file_size"`     // Size is the file size in bytes.
	IssuedYear  int16    `json:"issued_year"`   // Year is the year the file was issued.
	IssuedMonth int16    `json:"issued_month"`  // Month is the month the file was issued.
	IssuedDay   int16    `json:"issued_day"`    // Day is the day the file was issued.
	// contains filtered or unexported fields
}

DemozooLink is the response from the task of GetDemozooFile.

func Demozoo added in v1.14.0

func Demozoo(prodID int, unid string, download dir.Directory, timeout time.Duration) *DemozooLink

Demozoo initializes a new DemozooLink for use with [Download].

The prodID is the demozoo production id to probe. The uuid is the local artifact record unique id to update. The download directory is where the fetched remote file download will be saved.

The timeout is optional and is for the remote file downloads. It can usually be set to 0 to use the default 15 second value for single links, and 8 seconds per-link for productions with multiple downloads.

func (*DemozooLink) ArchiveDo added in v1.14.0

func (got *DemozooLink) ArchiveDo(
	ctx context.Context, sl *slog.Logger, c *echo.Context, tx *sql.Tx, src string,
) error

ArchiveDo sets the archive content and readme text of the source file.

func (*DemozooLink) Download

func (got *DemozooLink) Download(
	ctx context.Context, sl *slog.Logger, c *echo.Context, tx *sql.Tx, forJSON bool,
) error

Download fetches the download link from Demozoo and saves it to the download directory. It then runs Update to modify the database record with various metadata from the file and Demozoo record API data.

func (*DemozooLink) Stat

func (got *DemozooLink) Stat(ctx context.Context, sl *slog.Logger, c *echo.Context, tx *sql.Tx) error

Stat sets the file size, hash, type, and archive content of the file. The UUID is used to locate the file in the download directory.

func (*DemozooLink) Update

func (got *DemozooLink) Update(ctx context.Context, c *echo.Context, tx *sql.Tx) error

Update modifies the database record using data provided by the DemozooLink struct. A JSON response is returned with the success status of the update.

type PouetLink struct {
	UUID        string `json:"uuid"`         // UUID is the file production UUID.
	Releaser1   string `json:"releaser1"`    // Releaser1 is the first releaser of the file.
	Releaser2   string `json:"releaser2"`    // Releaser2 is the second releaser of the file.
	Title       string `json:"title"`        // Title is the file title.
	Filename    string `json:"filename"`     // Filename is the file name of the download.
	Content     string `json:"content"`      // Content is the file archive content.
	FileType    string `json:"file_type"`    // Type is the file type.
	FileHash    string `json:"file_hash"`    // Hash is the file integrity hash.
	Platform    string `json:"platform"`     // Platform is the file platform.
	Section     string `json:"section"`      // Section is the file section.
	Error       string `json:"error"`        // Error is the error message if the download or record update failed.
	PouetID     int    `json:"id"`           // PouetID is the Pouet prod which ID.
	DemozooID   int    `json:"demozoo_prod"` // DemozooID is the production ID.
	FileSize    int    `json:"file_size"`    // Size is the file size in bytes.
	IssuedYear  int16  `json:"issued_year"`  // Year is the year the file was issued.
	IssuedMonth int16  `json:"issued_month"` // Month is the month the file was issued.
	IssuedDay   int16  `json:"issued_day"`   // Day is the day the file was issued.
	// contains filtered or unexported fields
}

PouetLink is the response from the task of GetDemozooFile.

func Pouet added in v1.14.0

func Pouet(prodID int, unid string, download dir.Directory, timeout time.Duration) *PouetLink

Pouet initializes a new PouetLink for use with [Download].

The prodID is the pouet production id to probe. The uuid is the local artifact record unique id to update. The download directory is where the fetched remote file download will be saved.

The timeout is optional and is for the remote file download, but can usually be set to 0 to use the default 15 second value.

func (*PouetLink) Download

func (got *PouetLink) Download(ctx context.Context, sl *slog.Logger, tx *sql.Tx) error

Download fetches the download link from Pouet and saves it to the download directory. It then runs Update to modify the database record with various metadata from the file and Pouet record API data.

func (*PouetLink) Stat

func (got *PouetLink) Stat(ctx context.Context, sl *slog.Logger, tx *sql.Tx) error

Stat sets the file size, hash, type, and archive content of the file. The UUID is used to locate the file in the download directory.

func (*PouetLink) Update

func (got *PouetLink) Update(ctx context.Context, tx *sql.Tx) error

Update modifies the database record using data provided by the DemozooLink struct. A JSON response is returned with the success status of the update.

type Response added in v1.14.0

type Response struct {
	ContentLength string // ContentLength is the size of the file in bytes.
	ContentType   string // ContentType is the MIME type of the file.
	LastModified  string // LastModified is the last modified date of the file.
	Path          string // Path is the path to the downloaded file.
}

Response contains the details of a fetched downloaded file.

func GetFile added in v0.14.0

func GetFile(ctx context.Context, sl *slog.Logger, timeout time.Duration, rawURL string) (Response, error)

GetFile downloads a file from a remote URL and saves it to the default temp directory. The timeout is used both for the context and the http client and should be either TimeoutShort or TimeoutLong. There is a maximum timeout limit of 60 seconds.

The returned Response.Path is the path to the downloaded file and it should be removed after use.

Jump to

Keyboard shortcuts

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