asset

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindImages      = "images"
	KindBackgrounds = "backgrounds"
	KindCharacters  = "characters"

	VariantImg        = "img"
	VariantTimg       = "timg"
	VariantAlpha      = "alpha"
	VariantRealEsrgan = "real-esrgan"
	VariantRealCugan  = "real-cugan"
)

Variables

View Source
var (
	ErrInvalidKind    = fmt.Errorf("invalid kind")
	ErrInvalidVariant = fmt.Errorf("invalid variant")
)
View Source
var (
	ErrExists = errors.New("asset: the asset or variant already exists.")
)

Functions

func CheckKind added in v0.10.0

func CheckKind(kind string) error

func CheckVariant added in v0.10.0

func CheckVariant(variant string) error

func NewRepo added in v0.8.0

func NewRepo(db *bun.DB, conf *config.Config) (*repo, error)

func RegisterController

func RegisterController(v0 *server.V0, c *Controller)

func SortAsset added in v0.10.0

func SortAsset(query *bun.SelectQuery) *bun.SelectQuery

func SortAssetVariant added in v0.12.0

func SortAssetVariant(query *bun.SelectQuery) *bun.SelectQuery

func SortVariant added in v0.10.0

func SortVariant(query *bun.SelectQuery) *bun.SelectQuery

Types

type Asset

type Asset struct {
	Kind     string     `json:"kind"`
	Name     string     `json:"name"`
	Variants *[]Variant `json:"variants"`
}

func (Asset) String added in v0.10.0

func (a Asset) String() string

String returns a string representation of the asset.

The string representation of assets is "{kind}/{name}". e.g., "images/20_i00", "backgrounds/21_g1_interrogat_room".

type Controller

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

func NewController

func NewController(service *Service) *Controller

func (*Controller) GetAsset added in v0.8.0

func (c *Controller) GetAsset(ctx *fiber.Ctx) error

func (*Controller) GetAssets added in v0.8.0

func (c *Controller) GetAssets(ctx *fiber.Ctx) error

func (*Controller) GetKindNames added in v0.10.0

func (c *Controller) GetKindNames(ctx *fiber.Ctx) error

func (*Controller) GetVariant added in v0.10.0

func (c *Controller) GetVariant(ctx *fiber.Ctx) error

func (*Controller) GetVariantFile added in v0.10.0

func (c *Controller) GetVariantFile(ctx *fiber.Ctx) error

func (*Controller) GetVariantNames added in v0.10.0

func (c *Controller) GetVariantNames(ctx *fiber.Ctx) error

func (*Controller) GetVariants added in v0.8.0

func (c *Controller) GetVariants(ctx *fiber.Ctx) error

func (*Controller) PostVariant added in v0.10.0

func (c *Controller) PostVariant(ctx *fiber.Ctx) error

type Service

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

func NewService

func NewService(conf *config.Config, assetRepo *repo) *Service

func (*Service) GetAsset added in v0.8.0

func (s *Service) GetAsset(ctx context.Context, kind, name string) (*Asset, error)

func (*Service) GetAssets

func (s *Service) GetAssets(ctx context.Context, kind string) ([]Asset, error)

func (*Service) GetKindNames added in v0.10.0

func (s *Service) GetKindNames(ctx context.Context) ([]string, error)

func (*Service) GetVariant added in v0.10.0

func (s *Service) GetVariant(ctx context.Context, kind string, name string, variant string) (*Variant, error)

func (*Service) GetVariantFile added in v0.10.0

func (s *Service) GetVariantFile(ctx context.Context, kind, name, variant string) (*string, error)

func (*Service) GetVariantNames added in v0.10.0

func (s *Service) GetVariantNames(ctx context.Context) ([]string, error)

func (*Service) GetVariants added in v0.8.0

func (s *Service) GetVariants(ctx context.Context, kind string, name string) ([]Variant, error)

func (*Service) InitNames added in v0.10.0

func (s *Service) InitNames(ctx context.Context) error

func (*Service) PopulateFrom added in v0.10.0

func (s *Service) PopulateFrom(ctx context.Context, dirPath string) error

func (*Service) PostVariant added in v0.10.0

func (s *Service) PostVariant(ctx context.Context, kind, name string, variant Variant, file io.Reader) error

type Variant

type Variant struct {
	Variant  string `json:"variant"`
	Filename string `json:"filename"`
	Asset    *Asset `json:"-"`
}

func (Variant) FilePath added in v0.10.0

func (v Variant) FilePath(dirPath string) string

FilePath returns the absolute path to the variant file.

This is a shortcut for filepath.Join(dir, v.Path()).

func (Variant) Path added in v0.10.0

func (v Variant) Path() string

Path returns the relative path to the variant file.

The path of assets is "{variant}/{asset.kind}/{filename}". When the program want to find an asset file in a certain directory, it will check the path relative to the directory.

func (Variant) String added in v0.10.0

func (v Variant) String() string

String returns a string representation of the variant.

The string representation of assets is "{asset}/{variant}". e.g., "images/20_i00/img", "backgrounds/21_g1_interrogat_room/timg".

Jump to

Keyboard shortcuts

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