contentdb

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: LGPL-2.1 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFileNotFound = fmt.Errorf("PackageArchive.ReadFile(): not found")

ErrFileNotFound .

View Source
var (
	Host = "https://content.minetest.net"
)

Functions

This section is empty.

Types

type ArchiveType

type ArchiveType int

ArchiveType is the type of the archive.

const (
	Invalid     ArchiveType = 0
	Mod         ArchiveType = 1
	Modpack     ArchiveType = 2
	TexturePack ArchiveType = 3
	Game        ArchiveType = 4
)

Possible archive type values.

func (ArchiveType) String

func (a ArchiveType) String() string

type Client

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

Client implements a basic HTTP client that can be used to talk to the remote API endpoitns.

func NewClient

func NewClient(ctx context.Context) *Client

NewClient initializes a Client with the required values to properly operate.

func (*Client) Download

func (c *Client) Download(author, name string) (*PackageArchive, error)

Download fetches the package archive from the ContentDB for the current revision.

func (*Client) DownloadRelease added in v0.2.0

func (c *Client) DownloadRelease(author, name, release string) (*PackageArchive, error)

DownloadRelease fetches the provided package from the ContentDB in the specified revision.

func (*Client) GetPackage

func (c *Client) GetPackage(author, name string) (pkg *Package, err error)

GetPackage return details of the specified package.

func (*Client) GetRelease added in v0.2.0

func (c *Client) GetRelease(author, name, release string) (r *PackageRelease, err error)

func (*Client) ListPackages

func (c *Client) ListPackages(q *Query) (pkgs []Package, err error)

ListPackages returns a list of packages with the given query. If query is nil, or has all fields empty, all pacakges are returned.

func (*Client) ListReleases added in v0.2.0

func (c *Client) ListReleases(author, name string) (r []*PackageRelease, err error)

type Package

type Package struct {
	// Basic package info
	Author           string `json:"author,omitempty"`
	Name             string `json:"name,omitempty"`
	Title            string `json:"title,omitempty"`
	ShortDescription string `json:"short_description,omitempty"`
	Release          int32  `json:"release,omitempty"`
	Thumbnail        string `json:"string,omitempty"`
	Type             string `json:"type,omitempty"`

	// Package details
	LongDescription string   `json:"long_description,omitempty"`
	CreatedAt       string   `json:"created_at,omitempty"`
	License         string   `json:"license,omitempty"`
	MediaLicense    string   `json:"media_license,omitempty"`
	ContentWarnings []string `json:"content_warnings,omitempty"`
	Maintainers     []string `json:"maintainers,omitempty"`
	Provides        []string `json:"provides,omitempty"`
	ScreenShots     []string `json:"screenshots,omitempty"`
	Tags            []string `json:"tags,omitempty"`
	State           string   `json:"state,omitempty"`

	// Statistics
	Score     float32 `json:"score,omitempty"`
	Downloads int32   `json:"downloads,omitempty"`
	Forums    int32   `json:"forums,omitempty"`

	// Links
	IssueTracker string `json:"issue_tracker,omitempty"`
	Repo         string `json:"repo,omitempty"`
	URL          string `json:"url,omitempty"`
}

Package is a downloadable content from ContentDB.

type PackageArchive

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

PackageArchive provides utility functions to analyse the contents of downloaded archives from ContentDB.

func NewPackageArchive

func NewPackageArchive(b []byte) (*PackageArchive, error)

NewPackageArchive initializes a PackageArchive struct with the given byte slice b. It's expected that b points to a valid in-memory Zip archive.

func (*PackageArchive) Bytes

func (p *PackageArchive) Bytes() []byte

Bytes returns the underlying byte slice this archive was initialized with.

func (*PackageArchive) Contents

func (p *PackageArchive) Contents() []string

Contents returns a list of the package contents, ignoring directories.

func (*PackageArchive) FindFile

func (p *PackageArchive) FindFile(name string, max int) (count int, dir string)

FindFile returns the count of files with the given name and at what directory it was found. If max is grather than zero, search will stop after max files are found.

func (*PackageArchive) ReadFile

func (p *PackageArchive) ReadFile(pattern string) ([]byte, error)

ReadFile returns a byte slice with the extracted file contents.

func (*PackageArchive) Type

func (p *PackageArchive) Type() ArchiveType

Type detects the archive type. The algorithm uses the expected contents, and has some backwards compatibility.

type PackageRelease added in v0.2.0

type PackageRelease struct {
	ID          int    `json:"id,omitempty"`
	Title       string `json:"title,omitempty"`
	ReleaseDate string `json:"release_date,omitempty"`
	URL         string `json:"url,omitempty"`
	Commit      string `json:"commit,omitempty"`
	Downlads    int    `json:"downloads,omitempty"`
}

PackageRelease is a single downloadable version of a package.

type Query

type Query struct {
	Type            string
	Query           string
	Author          string
	Tag             []string
	Random          string
	Limit           string
	Hide            string
	Sort            string
	Order           string
	ProtocolVersion string
	EngineVersion   string
	Format          string
}

Query can be used to filter out the content returned by ListPackages.

func NewQuery

func NewQuery(q string) *Query

NewQuery is a package query constructor that filter by the given query

func QueryMods

func QueryMods() *Query

QueryMods is a package query constructor that returns only Mods

func (*Query) AsValues

func (q *Query) AsValues() (qs url.Values)

AsValues converts the current query into an url.Values

func (*Query) OrderBy

func (q *Query) OrderBy(criteria string) *Query

OrderBy sorts the query by the given criteria. This value is passed to the remote endpoint. Allowed values are name, title, score, reviews, downloads, created_at, approved_at, last_release

func (*Query) WithAuthor

func (q *Query) WithAuthor(author string) *Query

WithAuthor filter packages by author.

func (*Query) WithTags

func (q *Query) WithTags(tag ...string) *Query

WithTags filter packages by the given tags.

func (*Query) WithType

func (q *Query) WithType(t string) *Query

WithType filter packages by type. Type must be 'mod', 'game' or 'txp'.

Jump to

Keyboard shortcuts

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