store

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: GPL-3.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	UserSnowflakeNodeID  = 7
	ImageSnowflakeNodeID = 9
)
View Source
const (
	// ArtistType is the tag type artist.
	ArtistType = "artist"
	// CharacterType is the tag type character.
	CharacterType = "character"
	// CopyrightType is the tag type copyright.
	CopyrightType = "copyright"
	// MetaType is the tag type meta.
	MetaType = "meta"
	// GenericType is the tag type generic.
	GenericType = "generic"
)
View Source
const ImageRootPageVariant = "root"
View Source
const PageSize = 64

Variables

View Source
var (
	// AllowedTagTypes represent tag type strings that are allowed.
	AllowedTagTypes = []string{ArtistType, CharacterType, CopyrightType, MetaType, GenericType}
)
View Source
var (
	// AlreadyExists is returned when store already exists.
	AlreadyExists = errors.New("store path already exists")
)

Functions

func MakePreview added in v1.4.0

func MakePreview(img image.Image) image.Image

MakePreview compresses an image.Image to preview-size.

func MatchName added in v1.3.2

func MatchName(str string) bool

MatchName determines if str is a valid name.

func MatchURL added in v1.3.2

func MatchURL(str string) bool

MatchURL determines if str is a valid URL.

func TagTypeAllowed added in v1.3.3

func TagTypeAllowed(str string) bool

TagTypeAllowed returns whether str is an allowed tag type.

Types

type Image

type Image struct {
	Snowflake             string `json:"snowflake"`
	Hash                  string `json:"hash"`
	Type                  string `json:"type"`
	User                  string `json:"user"`
	Source                string `json:"source"`
	Parent                string `json:"parent"`
	Child                 string `json:"child"`
	Commentary            string `json:"commentary"`
	CommentaryTranslation string `json:"commentary_translation"`
}

Image represents metadata of an image.

type Info

type Info struct {
	Revision       int         `json:"revision"`
	Compat         bool        `json:"compat"`
	Register       bool        `json:"register"`
	InitialUser    string      `json:"initial_user"`
	PermissionDir  os.FileMode `json:"permission_dir"`
	PermissionFile os.FileMode `json:"permission_file"`
}

Info represents system information of a store.

type Store

type Store struct {
	Path           string
	SingleUser     bool
	Private        bool
	Revision       int
	Compat         bool
	Register       bool
	InitialUser    string
	PermissionDir  os.FileMode
	PermissionFile os.FileMode

	sync.RWMutex
	// contains filtered or unexported fields
}

Store represents a file store.

func New

func New(path string, single, private bool) *Store

New initialises a new store instance.

func (*Store) Close

func (s *Store) Close()

Close closes the store.

func (*Store) Image

func (s *Store) Image(hash string) Image

Image returns an image with specific hash.

func (*Store) ImageAdd

func (s *Store) ImageAdd(data []byte, flake string) Image

ImageAdd adds an image to the store.

func (*Store) ImageData

func (s *Store) ImageData(hash string, preview bool) (Image, []byte)

ImageData returns an image and its data with a specific hash.

func (*Store) ImageDestroy

func (s *Store) ImageDestroy(hash string)

ImageDestroy destroys an image.

func (*Store) ImageFilePath

func (s *Store) ImageFilePath(hash string) string

ImageFilePath returns path to an image file with specific hash.

func (*Store) ImageHasTag added in v0.7.4

func (s *Store) ImageHasTag(flake, tag string) bool

ImageHasTag figures out if an image has a tag.

func (*Store) ImageHashSplit

func (s *Store) ImageHashSplit(hash string) string

ImageHashSplit returns split image hash.

func (*Store) ImageHashTagsPath

func (s *Store) ImageHashTagsPath(hash string) string

ImageHashTagsPath returns path to an image's tags with specific hash.

func (*Store) ImageMetadataPath

func (s *Store) ImageMetadataPath(hash string) string

ImageMetadataPath returns path to an image's metadata file with specific hash.

func (*Store) ImageMetadataRead

func (s *Store) ImageMetadataRead(path string) Image

ImageMetadataRead reads an image metadata file.

func (*Store) ImagePath

func (s *Store) ImagePath(hash string) string

ImagePath returns path to an image with specific hash.

func (*Store) ImagePreviewFilePath

func (s *Store) ImagePreviewFilePath(hash string) string

ImagePreviewFilePath returns path to an image preview file with specific hash.

func (*Store) ImageSearch added in v0.7.4

func (s *Store) ImageSearch(tags []string) []string

ImageSearch searches for images with specific tags.

func (*Store) ImageSnowflake

func (s *Store) ImageSnowflake(flake string) Image

ImageSnowflake returns image that has specific snowflake.

func (*Store) ImageSnowflakeHash

func (s *Store) ImageSnowflakeHash(flake string) string

ImageSnowflakeHash returns image hash from snowflake.

func (*Store) ImageSnowflakePath

func (s *Store) ImageSnowflakePath(flake string) string

ImageSnowflakePath returns path to an image with specific snowflake.

func (*Store) ImageSnowflakes

func (s *Store) ImageSnowflakes() []string

ImageSnowflakes returns a slice of image snowflakes.

func (*Store) ImageTagAdd

func (s *Store) ImageTagAdd(flake, tag string)

ImageTagAdd adds a tag to an image with specific snowflake.

func (*Store) ImageTagRemove

func (s *Store) ImageTagRemove(flake, tag string)

ImageTagRemove removes a tag from an image with specific snowflake.

func (*Store) ImageTags

func (s *Store) ImageTags(flake string) []string

ImageTags returns tags of an image with specific hash.

func (*Store) ImageTagsPath

func (s *Store) ImageTagsPath(flake string) string

ImageTagsPath returns path to an image's tags with specific hash.

func (*Store) ImageUpdate added in v0.8.8

func (s *Store) ImageUpdate(hash, source, parent, commentary, commentaryTranslation string)

ImageUpdate updates image metadata.

func (*Store) Images

func (s *Store) Images() []string

Images returns a slice of image hashes.

func (*Store) ImagesDir

func (s *Store) ImagesDir() string

ImagesDir returns path to images.

func (*Store) ImagesSnowflakeDir

func (s *Store) ImagesSnowflakeDir() string

ImagesSnowflakeDir returns path to image snowflakes.

func (*Store) LockPath

func (s *Store) LockPath() string

LockPath returns path to lock file.

func (*Store) MatchName

func (s *Store) MatchName(str string) bool

MatchName determines if str is a valid name. As of v1, this just calls MatchName.

func (*Store) MatchURL added in v1.2.7

func (s *Store) MatchURL(str string) bool

MatchURL determines if str is a valid URL. As of v1, this just calls MatchURL.

func (*Store) Page

func (s *Store) Page(variant string, entry int) []string

Page returns all entries in a page.

func (*Store) PageBaseDir

func (s *Store) PageBaseDir() string

PageBaseDir returns path to page base directory.

func (*Store) PageImages

func (s *Store) PageImages(variant string, entry int) []Image

PageImages returns all images in a page.

func (*Store) PageInsert

func (s *Store) PageInsert(variant, flake string)

PageInsert inserts an image into the index.

func (*Store) PageRegisterRemove

func (s *Store) PageRegisterRemove(variant, flake string)

PageRegisterRemove registers an image remove.

func (*Store) PageTotal

func (s *Store) PageTotal(variant string) int

PageTotal returns total amount of pages.

func (*Store) PageVariantPath

func (s *Store) PageVariantPath(variant string) string

PageVariantPath returns path to pages of a variant.

func (*Store) SecretAssociate

func (s *Store) SecretAssociate(secret, flake string)

SecretAssociate associates a secret with a user.

func (*Store) SecretDisassociate

func (s *Store) SecretDisassociate(secret string)

SecretDisassociate disassociates a secret.

func (*Store) SecretLookup

func (s *Store) SecretLookup(secret string) User

SecretLookup looks up a user from a secret.

func (*Store) SecretNew

func (s *Store) SecretNew() string

SecretNew generates a new user secret.

func (*Store) SecretPath

func (s *Store) SecretPath(secret string) string

SecretPath returns path to tokens.

func (*Store) SecretsDir

func (s *Store) SecretsDir() string

SecretsDir returns path to tokens.

func (*Store) Tag

func (s *Store) Tag(tag string) []string

Tag returns a slice of image snowflakes in a specific tag.

func (*Store) TagCreate

func (s *Store) TagCreate(tag string) bool

TagCreate creates a tag and returns ok value.

func (*Store) TagDestroy

func (s *Store) TagDestroy(tag string)

TagDestroy removes all references from a tag and removes it.

func (*Store) TagInfo

func (s *Store) TagInfo(tag string) Tag

TagInfo returns information of a tag.

func (*Store) TagMetadataPath

func (s *Store) TagMetadataPath(tag string) string

TagMetadataPath returns path to a specific tag's metadata file.

func (*Store) TagPath

func (s *Store) TagPath(tag string) string

TagPath returns path to a specific tag.

func (*Store) TagType

func (s *Store) TagType(tag, t string)

TagType sets type of tag.

func (*Store) Tags

func (s *Store) Tags() []string

Tags returns a slice of tag names.

func (*Store) TagsDir

func (s *Store) TagsDir() string

TagsDir returns path to tags.

func (*Store) User

func (s *Store) User(flake string) User

User returns user information with specific snowflake.

func (*Store) UserAdd

func (s *Store) UserAdd(username, password string, privileged bool) User

UserAdd creates a user.

func (*Store) UserDestroy

func (s *Store) UserDestroy(flake string)

UserDestroy destroys a user with specific snowflake.

func (*Store) UserImages

func (s *Store) UserImages(flake string) []string

UserImages returns slice of a user's images.

func (*Store) UserImagesPath

func (s *Store) UserImagesPath(flake string) string

UserImagesPath returns path to a user's images with specific snowflake.

func (*Store) UserMetadata

func (s *Store) UserMetadata(info User)

UserMetadata sets user metadata.

func (*Store) UserMetadataPath

func (s *Store) UserMetadataPath(flake string) string

UserMetadataPath returns path to a user's metadata file with specific snowflake.

func (*Store) UserPasswordPath

func (s *Store) UserPasswordPath(flake string) string

UserPasswordPath returns path to a user's password.

func (*Store) UserPasswordUpdate

func (s *Store) UserPasswordUpdate(flake, password string) bool

UserPasswordUpdate updates password of specified user.

func (*Store) UserPasswordValidate

func (s *Store) UserPasswordValidate(flake, password string) bool

UserPasswordValidate validates password of specified user.

func (*Store) UserPath

func (s *Store) UserPath(flake string) string

UserPath returns path to a user with specific snowflake.

func (*Store) UserPrivileged

func (s *Store) UserPrivileged(flake string, privileged bool)

UserPrivileged sets privileged status of user with specific snowflake.

func (*Store) UserSecretRegen

func (s *Store) UserSecretRegen(flake string) string

UserSecretRegen regenerates secret of user with specific snowflake.

func (*Store) UserUsername

func (s *Store) UserUsername(username string) User

UserUsername returns user via username.

func (*Store) UserUsernamePasswordValidate

func (s *Store) UserUsernamePasswordValidate(username, password string) bool

UserUsernamePasswordValidate validates password of specified user from username.

func (*Store) UserUsernameUpdate

func (s *Store) UserUsernameUpdate(flake, username string) bool

UserUsernameUpdate updates username of user with specific snowflake.

func (*Store) UsernamePath

func (s *Store) UsernamePath(name string) string

UsernamePath returns path to username.

func (*Store) UsernamesDir

func (s *Store) UsernamesDir() string

UsernamesDir returns path to usernames.

func (*Store) Users

func (s *Store) Users() []string

Users returns a slice of user snowflakes.

func (*Store) UsersDir

func (s *Store) UsersDir() string

UsersDir returns path to users.

type Tag

type Tag struct {
	Type         string    `json:"type"`
	CreationTime time.Time `json:"creation_time"`
}

Tag represents metadata of a tag.

type User

type User struct {
	Secret     string `json:"secret"`
	Privileged bool   `json:"privileged"`
	Snowflake  string `json:"snowflake"`
	Username   string `json:"username"`
}

User represents metadata of a user.

Jump to

Keyboard shortcuts

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