remote

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: GPL-3.0 Imports: 22 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 (
	// Timeout is the HTTP client default timeout.
	Timeout = 5 * time.Second
	// User-Agent to send with the HTTP request.
	UserAgent = "Defacto2 Uploader form submission, thanks!"
)

Variables

View Source
var (
	ErrDB    = errors.New("database connection is nil")
	ErrExist = errors.New("file already exists")
)

Functions

func FixSceneOrg added in v0.14.0

func FixSceneOrg(rawURL string) string

FixSceneOrg returns a working URL if the provided rawURL is a known, broken link to a scene.org file. Otherwise it returns the original URL.

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 {
	ID          int      `json:"id"`            // ID is the Demozoo production ID.
	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.
	Pouet       int      `json:"pouet_prod"`    // Pouet is the Pouet production ID.
	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.
	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.
	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
	Filename    string   `json:"filename"`      // Filename is the file name of the download.
	FileSize    int      `json:"file_size"`     // Size is the file size in bytes.
	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.
}

DemozooLink is the response from the task of GetDemozooFile.

func (*DemozooLink) ArchiveContent

func (got *DemozooLink) ArchiveContent(c echo.Context, db *sql.DB, src string) error

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

func (*DemozooLink) Download

func (got *DemozooLink) Download(c echo.Context, db *sql.DB, downloadDir string) 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(c echo.Context, db *sql.DB, downloadDir string) 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(c echo.Context, db *sql.DB) 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 DownloadResponse added in v0.14.0

type DownloadResponse 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.
}

DownloadResponse contains the details of a downloaded file.

func GetFile added in v0.14.0

func GetFile(rawURL string, timeout time.Duration) (DownloadResponse, error)

GetFile downloads a file from a remote URL and saves it to the default temp directory. If timeout is 0, it uses the default timeout of 5 seconds, otherwise it uses the provided timeout. It returns the path to the downloaded file and it should be removed after use.

type PouetLink struct {
	ID          int    `json:"id"`           // ID is the Demozoo production ID.
	UUID        string `json:"uuid"`         // UUID is the file production UUID.
	Demozoo     int    `json:"demozoo_prod"` // Demozoo production ID.
	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.
	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.
	Filename    string `json:"filename"`     // Filename is the file name of the download.
	FileSize    int    `json:"file_size"`    // Size is the file size in bytes.
	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.
}

PouetLink is the response from the task of GetDemozooFile.

func (*PouetLink) ArchiveContent

func (got *PouetLink) ArchiveContent(c echo.Context, db *sql.DB, src string) error

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

func (*PouetLink) Download

func (got *PouetLink) Download(c echo.Context, db *sql.DB, downloadDir string) error

func (*PouetLink) Stat

func (got *PouetLink) Stat(c echo.Context, db *sql.DB, downloadDir string) 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(c echo.Context, db *sql.DB) 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.

Jump to

Keyboard shortcuts

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