api

package
v0.0.0-...-8bf7f5a Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package api provides an API for accessing/mangaging a Moonpool database.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrThumbnailNotFound = errors.New("thumbnail not found")
)

Functions

func GenerateMockData

func GenerateMockData(a *API, amount int, mockTags, mockTimestamps bool) ([]int64, error)

GenerateMockData creates an x amount of new entries with a random tag and .png extension as its metadata. GenerateMockData may return an error, along with partial ArchiveIDs if only some imports are successful.

Types

type API

type API struct {
	Config Config
	// contains filtered or unexported fields
}

func New

func New(c Config, l *slog.Logger) (*API, error)

func Open

func Open(c Config, l *slog.Logger) (*API, error)

func (*API) AssignTags

func (a *API) AssignTags(ctx context.Context, archive_id int64, tags []string) error

AssignTags assigns a slice of tags to a given archive_id. A new tag will be implicitly created if one does not exist already. No errors will be given if a tag is already set. Tag aliases will automatically be resolved to their base tag.

func (*API) BeginTX

func (a *API) BeginTX(ctx context.Context) (*WithTX, error)

func (*API) Close

func (a *API) Close(ctx context.Context) error

Close manually runs a SQL checkpoint and closes the API connection. Calling Close() will implicitly close the sql.DB connection as well

func (*API) DeleteTagAlias

func (a *API) DeleteTagAlias(ctx context.Context, tag_alias string) error

DeleteTagAlias completely deletes an alias tag from moonpool. Base tag is not affected whatsoever.

func (*API) DoesEntryExist

func (a *API) DoesEntryExist(ctx context.Context, archive_id int64) bool

func (*API) GenerateBlurHash

func (a *API) GenerateBlurHash(ctx context.Context, archive_id int64) error

func (*API) GeneratePerceptualHash

func (a *API) GeneratePerceptualHash(ctx context.Context, archive_id int64, hashType string, r io.Reader) error

hashType is unused

func (*API) GenerateThumbnail

func (a *API) GenerateThumbnail(ctx context.Context, archive_id int64) error

func (*API) GetBlurHashString

func (a *API) GetBlurHashString(ctx context.Context, archive_id int64) (string, error)

func (*API) GetEntry

func (a *API) GetEntry(ctx context.Context, archive_id int64) (entry.Entries, error)

func (*API) GetFile

func (a *API) GetFile(ctx context.Context, archive_id int64) (io.ReadCloser, error)

func (*API) GetHashes

func (a *API) GetHashes(ctx context.Context, archive_id int64) (entry.Hashes, error)

func (*API) GetMostRecentArchiveID

func (a *API) GetMostRecentArchiveID(ctx context.Context) (int64, error)

GetMostRecentArchiveID gets the the most recently imported archive_id.

func (*API) GetPage

func (a *API) GetPage(ctx context.Context, sort string, amount, pagenation int64, desc bool) ([]archive.Archive, error)

GetPage returns a list of archives within a given range. Valid sort options are "imported", "created", and "modified".

func (*API) GetPath

func (a *API) GetPath(ctx context.Context, archive_id int64) (entry.Path, error)

GetPath takes an archive_id and returns its relative folder path that points to a file

func (*API) GetPerceptualHash

func (a *API) GetPerceptualHash(ctx context.Context, archive_id int64, hashType string) (uint64, error)

hashType is unused

func (*API) GetTagCount

func (a *API) GetTagCount(ctx context.Context, tag string) (int64, error)

func (*API) GetTags

func (a *API) GetTags(ctx context.Context, archive_id int64) ([]string, error)

func (*API) GetTagsByList

func (a *API) GetTagsByList(ctx context.Context, archive_ids []int64) ([]entry.TagCount, error)

GetTagCountByList groups the total amount of tags that are assigned to a list of archive_id's. entry.TagCount is implicitly sorted from largest to smallest and returns 50 tags in total.

func (*API) GetTagsByRange

func (a *API) GetTagsByRange(ctx context.Context, start, end, offset int64) ([]entry.TagCount, error)

GetTagCountByList groups the total amount of tags that are within a range of archive_id's. offset is the starting point in which to begin grouping each archive_id. entry.TagCount is implicitly sorted from largest to smallest

func (*API) GetThumbnail

func (a *API) GetThumbnail(ctx context.Context, archive_id int64, size, format string) ([]byte, error)

GetThumbnail returns the thumbnail data from a given entry. Valid sizes are "small", "medium", and "large". Valid formats are "jpeg"

func (*API) GetTimestamps

func (a *API) GetTimestamps(ctx context.Context, archive_id int64) (entry.Timestamp, error)

GetTimestamps returns the UTC timestamps of an entry. If only partial timestamp information exists, GetTimestamps will return a partial timestamp and an error. You should ALWAYS check whether a Timestamp is empty or not, regardless of any errors.

func (*API) Import

func (a *API) Import(ctx context.Context, i Importer) (int64, error)

Import takes an Importer interface and returns an archive_id and nil error on success, or both an archive_id AND non-nil error on partial success. Partial success currently only occurs when all other import routines (archive creation, file storing, timestamps, etc) are successful, except for tag importing. Import will return an ArchiveID of -1 if a non-partial success isn't possible.

You should ALWAYS check if "ArchiveID <=0 && error != nil"

func (*API) NewSavepoint

func (a *API) NewSavepoint(ctx context.Context, name string) error

func (*API) NewTagAlias

func (a *API) NewTagAlias(ctx context.Context, tag, tag_alias string) error

func (*API) QueryTags

func (a *API) QueryTags(ctx context.Context, sort, order string, q QueryTags) ([]int64, error)

Valid sort options are "imported", "created", and "modified". Valid order options are "descending", "ascending".

func (*API) ReleaseSavepoint

func (a *API) ReleaseSavepoint(ctx context.Context, name string) error

func (*API) RemoveArchive

func (a *API) RemoveArchive(ctx context.Context, archive_id int64) error

RemoveArchive completely deletes an entry from the moonpool database.

func (*API) RemoveTags

func (a *API) RemoveTags(ctx context.Context, archive_id int64, tags []string) error

RemoveTags unassigns a list of tags from an entry. If a tag is no longer in reference to any entry, it is completely removed from the database.

func (*API) RenderBlurHash

func (a *API) RenderBlurHash(ctx context.Context, archive_id int64) (image.Image, error)

func (*API) ReplaceTags

func (a *API) ReplaceTags(ctx context.Context, archive_id int64, tags []string) error

ReplaceTags unassigns any and all tags associated with a given archive_id, and replaces it with a given slice of tags.

func (*API) ResolveTagAlias

func (a *API) ResolveTagAlias(ctx context.Context, tag_alias []string) ([]entry.TagAlias, error)

ResolveTagAlias returns the base tag of a given tag alias.

func (*API) RollbackSavepoint

func (a *API) RollbackSavepoint(ctx context.Context, name string) error

func (*API) SearchTag

func (a *API) SearchTag(ctx context.Context, tag string) ([]int64, error)

SearchTag takes a tag and returns a slice of archive IDs.

func (*API) SetHashes

func (a *API) SetHashes(ctx context.Context, archive_id int64, h entry.Hashes) error

func (*API) SetTimestamps

func (a *API) SetTimestamps(ctx context.Context, archive_id int64, t entry.Timestamp) error

SetTimestamps sets assigns or updates an existing timestamp to an entry. Timestamps are implicitly converted into a UTC timezone. If a timestamp field is empty, SetTimestamps will ignore that field and only update the field of an entry with a valid time.

func (*API) Vaccum

func (a *API) Vaccum(ctx context.Context) (int64, error)

type Config

type Config struct {
	ArchiveLocation, ThumbnailLocation, MediaLocation string
}

type Importer

type Importer interface {
	Timestamp() entry.Timestamp
	Hash() entry.Hashes
	Path() string
	Extension() string
	Store(baseDirectory string) error
}

type QueryTags

type QueryTags struct {
	TagsInclude, TagsExclude []string
}

func BuildQuery

func BuildQuery(s string) QueryTags

BuildQuery takes a string and returns a QueryTag to be used in API.QueryTags. Each tag can be separated by a comma (,) and have a prefixed special character to assign specific tag modifiers to it.

tag modifiers: dash (-) = exclude tag from search

type WithTX

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

Jump to

Keyboard shortcuts

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