htmx

package
v1.14.4 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: GPL-3.0 Imports: 51 Imported by: 0

Documentation

Overview

Package htmx handles the routes and views for the AJAX responses using the htmx library.

Index

Constants

View Source
const EditorKey = "artifact-editor-key"

Variables

View Source
var (
	ErrIsDir      = errors.New("htmx: the file is a directory")
	ErrPath       = errors.New("htmx: the file path is invalid")
	ErrYMD        = errors.New("htmx: invalid ymd format")
	ErrYouTube    = errors.New("htmx: youtube watch video id needs to be empty or 11 characters")
	ErrFormRead   = errors.New("htmx form: parameters could not be read")
	ErrFormInsert = errors.New("htmx form: submission could not be inserted into the database")
	ErrFormUpdate = errors.New("htmx form: submission could not update a database record")
)

Functions

func Alternatives added in v1.7.12

func Alternatives(s string) []string

Alternatives returns a slice of possible matching alternative names, spellings, acronyms and initialisms for the s string.

func Areacodes added in v1.6.0

func Areacodes(c *echo.Context) error

Areacodes is the handler for the /areacodes route.

func Close added in v1.14.0

func Close(sl *slog.Logger, msg string, file multipart.File)

func CommitNotOn added in v1.14.0

func CommitNotOn(c *echo.Context, tx *sql.Tx, name string,
	fn func(context.Context, boil.ContextExecutor, int64, bool) error,
) error

func CommitOn added in v1.14.0

func CommitOn(c *echo.Context, tx *sql.Tx, name string,
	fn func(context.Context, boil.ContextExecutor, int64, bool) error,
) error

func CommitSanitize added in v1.14.0

func CommitSanitize(c *echo.Context, tx *sql.Tx, name string,
	sanitize func(string) string,
	fn func(context.Context, boil.ContextExecutor, int64, string) error,
) error

func CommitStr added in v1.14.0

func CommitStr(c *echo.Context, tx *sql.Tx, name string,
	fn func(context.Context, boil.ContextExecutor, int64, string) error,
) error

func CommitStrKey added in v1.14.0

func CommitStrKey(c *echo.Context, tx *sql.Tx, name string,
	fn func(context.Context, boil.ContextExecutor, int64, string) error,
) error

func DBConnections added in v0.8.0

func DBConnections(c *echo.Context, db *sql.DB) error

DBConnections is the handler for the database connections page.

func DataListMagazines

func DataListMagazines(sl *slog.Logger, c *echo.Context, db *sql.DB, input string) error

DataListMagazines is a handler for the /datalist/magazines route.

func DataListReleasers

func DataListReleasers(sl *slog.Logger, c *echo.Context, db *sql.DB, input string) error

DataListReleasers is a handler for the /datalist/releasers route.

func DeleteForever added in v0.8.0

func DeleteForever(sl *slog.Logger, c *echo.Context, tx *sql.Tx, recordKey string) error

DeleteForever is a handler for the /delete/forever route. The recordKey is the numeric ID used by the record database table.

func FSAlign added in v1.14.0

func FSAlign(sl *slog.Logger, c *echo.Context, align command.Align, dirs command.Dirs) error

FSAlign handles the htmx request for the thumbnail crop alignment.

func FSCopyDIZ added in v1.14.0

func FSCopyDIZ(c *echo.Context, dirs command.Dirs) error

FSCopyDIZ handles the htmx request to use the file_id.diz artifact as a preview.

func FSCopyHelp added in v1.14.0

func FSCopyHelp(c *echo.Context, dirs command.Dirs) error

FSCopyHelp handles the htmx request to use the helper textfile as a preview.

func FSCopyReadme added in v1.14.0

func FSCopyReadme(sl *slog.Logger, c *echo.Context, dirs command.Dirs) error

func FSCrop added in v1.14.0

func FSCrop(sl *slog.Logger, c *echo.Context, crop command.Crop, dirs command.Dirs,
) error

FSCrop handles the htmx request for the preview image cropping.

func FSPixelate added in v1.14.0

func FSPixelate(sl *slog.Logger, c *echo.Context, directory ...dir.Directory) error

FSPixelate handles the htmx request to pixelate both the preview and thumbnails, if they are not suitable for a general audience. This also has an added benefit of reducing the file sizes of both images and reducing page load.

func FSRemoveDIZ added in v1.14.0

func FSRemoveDIZ(c *echo.Context, extra dir.Directory) error

FSRemoveDIZ handles the request to remove the uuid named file_id.diz text file from the provided extra directory.

func FSRemoveHelp added in v1.14.0

func FSRemoveHelp(c *echo.Context, extra dir.Directory) error

FSRemoveHelp handles the request to remove the uuid named helper (.hlp) text file from the provided extra directory.

func FSRemoveImages added in v1.14.0

func FSRemoveImages(c *echo.Context, directories ...dir.Directory) error

FSRemoveImages handles the request to remove the uuid named image files from the directories provided.

func FSRemoveReadme added in v1.14.0

func FSRemoveReadme(c *echo.Context, extra dir.Directory) error

FSRemoveReadme handles the request to remove the uuid named readme text file from the provided extra directory.

func FSThumb added in v1.14.0

func FSThumb(sl *slog.Logger, c *echo.Context, thumb command.Generate, dirs command.Dirs) error

FSThumb handles the htmx request for the thumbnail quality.

func FSUseBinText added in v1.14.0

func FSUseBinText(sl *slog.Logger, c *echo.Context, dirs command.Dirs) error

FSUseBinText handles the htmx request to use the text file artifact as a preview.

func FSUseImage added in v1.14.0

func FSUseImage(sl *slog.Logger, c *echo.Context, dirs command.Dirs) error

FSUseImage handles the htmx request to use an image file artifact as a preview.

func FSUseReadme added in v1.14.0

func FSUseReadme(sl *slog.Logger, c *echo.Context, amigaFont bool, dirs command.Dirs,
) error

FSUseReadme handles the htmx request to use the text file artifact as a preview.

func GlobTo

func GlobTo(name string) string

GlobTo returns the path to the named template file. If name is empty, the path to the view/htmx directory is returned.

func HTMLLinkTo added in v1.14.0

func HTMLLinkTo(c *echo.Context, err error) error

HTMLLinkTo handles the post submission for a form submission to provide the HTML formatted links for the "Links" section of the artifact editor.

func Key added in v1.14.0

func Key(c *echo.Context) (int64, error)

func KeyParam added in v1.14.0

func KeyParam(c *echo.Context) (int64, error)

KeyParam returns the "id" value from the URL parameters or returns 0 and an error if it is invalid.

func PageReload added in v1.14.0

func PageReload(c *echo.Context) *echo.Context

PageReload is a helper function to set the HTTP HTMX header for the browser to refresh the page.

func Paths added in v1.14.0

func Paths(c *echo.Context) (unid, filename string, err error)

Paths returns two values provided by the URL parameters:

The UUID unique identifier for the file assets storage.
The original filename of the artifact, however this maybe modified to be friendly with URL queries.

An error is returned if the unid or filename values are invalid.

func Pings added in v0.8.0

func Pings(c *echo.Context, proto string, port int) error

Pings is a handler for the /pings route.

The proto string should either be "http" or "https".

func SaveTemp added in v1.14.0

func SaveTemp(sl *slog.Logger, c *echo.Context, key string, fileHeader *multipart.FileHeader) (string, error)

SaveTemp is a generic file writer that saves the chosen file upload to a temporary file. Note the multipart file header needs to be closed outside of this func.

func SearchByID added in v0.8.0

func SearchByID(sl *slog.Logger, c *echo.Context, db *sql.DB) error

SearchByID is a handler for the /editor/search/id route.

func SearchReleaser

func SearchReleaser(sl *slog.Logger, c *echo.Context, db *sql.DB, ft *fulltext.Tidbits) error

SearchReleaser is a handler for the /search/releaser route.

func SearchResult added in v1.8.14

func SearchResult(index any) template.HTML

func StatusOK added in v1.14.0

func StatusOK(c *echo.Context, name string) error

func Suggestion

func Suggestion(name, initialism string, count any) string

Suggestion returns a human readable string of the byte count with a named description.

func TemplateFuncMap

func TemplateFuncMap() template.FuncMap

TemplateFuncMap are a collection of mapped functions that can be used in a template.

func Templates

func Templates(fsys fs.FS) map[string]*template.Template

Templates returns a map of the htmx templates.

func Tx16Colors added in v1.14.0

func Tx16Colors(c *echo.Context, tx *sql.Tx) error

Tx16Colors handles the post submission for the file artifact 16 Colors link.

func TxComment added in v1.14.0

func TxComment(c *echo.Context, tx *sql.Tx) error

TxComment handles the post submission for the file artifact comment.

func TxCommentUndo added in v1.14.0

func TxCommentUndo(c *echo.Context, tx *sql.Tx) error

TxCommentUndo handles the post submission for the file artifact comment reset.

func TxCreditAudio added in v1.14.0

func TxCreditAudio(c *echo.Context, tx *sql.Tx) error

TxCreditAudio handles the post submission for the file artifact creator musician.

func TxCreditIll added in v1.14.0

func TxCreditIll(c *echo.Context, tx *sql.Tx) error

TxCreditIll handles the post submission for the file artifact creator illustrator.

func TxCreditProg added in v1.14.0

func TxCreditProg(c *echo.Context, tx *sql.Tx) error

TxCreditProg handles the post submission for the file artifact creator programmer.

func TxCreditText added in v1.14.0

func TxCreditText(c *echo.Context, tx *sql.Tx) error

TxCreditText handles the post submission for the file artifact creator text.

func TxCreditUndo added in v1.14.0

func TxCreditUndo(c *echo.Context, tx *sql.Tx) error

TxCreditUndo handles the post submission for the file artifact creators reset.

func TxDemozoo added in v1.14.0

func TxDemozoo(c *echo.Context, tx *sql.Tx) error

TxDemozoo handles the post submission for the file artifact Demozoo production link.

func TxEmulateBroken added in v1.14.0

func TxEmulateBroken(c *echo.Context, tx *sql.Tx) error

TxEmulateBroken handles the patch submission for the broken emulation for a file artifact.

func TxEmulateCPU added in v1.14.0

func TxEmulateCPU(c *echo.Context, tx *sql.Tx) error

TxEmulateCPU handles the patch submission for the CPU emulation for a file artifact.

func TxEmulateEMS added in v1.14.0

func TxEmulateEMS(c *echo.Context, tx *sql.Tx) error

func TxEmulateMachine added in v1.14.0

func TxEmulateMachine(c *echo.Context, tx *sql.Tx) error

TxEmulateMachine handles the patch submission for the machine and graphic emulation for a file artifact.

func TxEmulateRunProg added in v1.14.0

func TxEmulateRunProg(c *echo.Context, tx *sql.Tx) error

TxEmulateRunProg handles the patch submission for the run program emulation.

func TxEmulateSFX added in v1.14.0

func TxEmulateSFX(c *echo.Context, tx *sql.Tx) error

TxEmulateSFX handles the patch submission for the audio emulation for a file artifact.

func TxEmulateUMB added in v1.14.0

func TxEmulateUMB(c *echo.Context, tx *sql.Tx) error

func TxEmulateXMS added in v1.14.0

func TxEmulateXMS(c *echo.Context, tx *sql.Tx) error

func TxFilename added in v1.14.0

func TxFilename(c *echo.Context, tx *sql.Tx) error

TxFilename handles the post submission for the file artifact filename.

func TxFilenameUndo added in v1.14.0

func TxFilenameUndo(c *echo.Context, tx *sql.Tx) error

TxFilenameUndo handles the post submission for the file artifact filename reset.

func TxGitHub added in v1.14.0

func TxGitHub(c *echo.Context, tx *sql.Tx) error

TxGitHub handles the post submission for the file artifact GitHub repository link.

func TxLastMod added in v1.14.0

func TxLastMod(c *echo.Context, tx *sql.Tx) error

TxLastMod is the post submission to set the date of release to be the last modification date of the file download or file archive.

func TxLinksUndo added in v1.14.0

func TxLinksUndo(c *echo.Context, tx *sql.Tx) error

TxLinksUndo handles the post submission for the file artifact links reset.

func TxPouet added in v1.14.0

func TxPouet(c *echo.Context, tx *sql.Tx) error

TxPouet handles the post submission for the file artifact Pouet production link.

func TxPublic added in v1.14.0

func TxPublic(c *echo.Context, tx *sql.Tx, state bool) error

TxPublic handles the post submission for the file artifact record toggle. The return value is either "online" or "offline" depending on the state.

func TxPublicByKey added in v1.14.0

func TxPublicByKey(c *echo.Context, tx *sql.Tx, key string, state bool) error

TxPublicByKey handles the post submission for the file artifact record toggle. The key string is converted into an integer and used as the artifact id. The return value is either "online" or "offline" depending on the state.

func TxReadmeOff added in v1.14.0

func TxReadmeOff(c *echo.Context, tx *sql.Tx) error

TxReadmeOff handles the htmx request to disable the in page display of both the text files readme and file_id.diz for the file artifact.

func TxRelations added in v1.14.0

func TxRelations(c *echo.Context, tx *sql.Tx) error

TxRelations handles the post submission for the file artifact releaser relationships.

func TxReleasers added in v1.14.0

func TxReleasers(c *echo.Context, tx *sql.Tx) error

TxReleasers handles the post submission for the file artifact releasers. It will only update the releaser1 and the releaser2 values if they have changed. The return value is either "Updated" or "Update" depending on if the values have changed.

func TxReleasersUndo added in v1.14.0

func TxReleasersUndo(c *echo.Context, tx *sql.Tx) error

TxReleasersUndo handles the post submission for the file artifact releasers reset. It will always reset and save the releaser1 and the releaser2 values. The return value is always "Resetted" unless an error occurs.

func TxTags added in v1.14.0

func TxTags(sl *slog.Logger, c *echo.Context, tx *sql.Tx) error

TxTags handles the post submission for the file artifact classifications, such as the platform, operating system, section or category tags. The return value is either the humanized and counted classification or an error.

func TxTitle added in v1.14.0

func TxTitle(c *echo.Context, tx *sql.Tx) error

TxTitle handles the post submission for the file artifact title.

func TxTitleUndo added in v1.14.0

func TxTitleUndo(c *echo.Context, tx *sql.Tx) error

TxTitleUndo handles the post submission for the file artifact title reset.

func TxVirusTotal added in v1.14.0

func TxVirusTotal(c *echo.Context, tx *sql.Tx) error

TxVirusTotal handles the post submission for the file artifact VirusTotal report link.

func TxWebsites added in v1.14.0

func TxWebsites(c *echo.Context, tx *sql.Tx) error

TxWebsites handles the post submission for the file artifact website links.

func TxYMD added in v1.14.0

func TxYMD(c *echo.Context, tx *sql.Tx) error

TxYMD is the post submission for the date of release.

func TxYMDUndo added in v1.14.0

func TxYMDUndo(c *echo.Context, tx *sql.Tx) error

TxYMDUndo is the post submission to undo the date of release.

func TxYouTube added in v1.14.0

func TxYouTube(c *echo.Context, tx *sql.Tx) error

TxYouTube handles the post submission for the file artifact YouTube watch video link.

func UPAdvanced added in v1.14.0

func UPAdvanced(sl *slog.Logger, c *echo.Context, tx *sql.Tx, download dir.Directory) error

UPAdvanced is a handler for the /uploader/advanced route.

func UPCount added in v1.14.0

func UPCount(sl *slog.Logger, c *echo.Context, db *sql.DB, name string) error

UPCount handles the post submission for the Uploader classification, such as the platform, operating system, section or category tags. The return value is either the humanized and counted classification or an error.

func UPImage added in v1.14.0

func UPImage(sl *slog.Logger, c *echo.Context, tx *sql.Tx, download dir.Directory) error

UPImage is a handler for the /uploader/image route.

func UPIntro added in v1.14.0

func UPIntro(sl *slog.Logger, c *echo.Context, tx *sql.Tx, download dir.Directory) error

UPIntro is a handler for the /uploader/intro route.

func UPMagazine added in v1.14.0

func UPMagazine(sl *slog.Logger, c *echo.Context, tx *sql.Tx, download dir.Directory) error

UPMagazine is a handler for the /uploader/magazine route.

func UPSHA384 added in v1.14.0

func UPSHA384(sl *slog.Logger, c *echo.Context, db *sql.DB) error

UPSHA384 is a handler for the /uploader/sha384 route. It checks the SHA-384 hash against the database to see if the file already exists, and returns the URI if it does. Otherwise, if it does not exist, it returns an empty string.

func UPText added in v1.14.0

func UPText(sl *slog.Logger, c *echo.Context, tx *sql.Tx, download dir.Directory) error

UPText is a handler for the /uploader/text route.

func UPTrainer added in v1.14.0

func UPTrainer(sl *slog.Logger, c *echo.Context, tx *sql.Tx, download dir.Directory) error

UPTrainer is a handler for the /uploader/trainer route.

func UUID added in v1.7.0

func UUID(c *echo.Context) (string, error)

UUID returns the uuid from the URL parameters and returns an error if it is invalid.

func Validate added in v1.7.0

func Validate(path string) error

Validate checks that the path is not absolute and does not allow for any path traversal. It returns an error if the path is invalid.

func ValidateDemozoo added in v1.14.0

func ValidateDemozoo(c *echo.Context, prodID int, useCache bool) (demozoo.Production, error)

ValidateDemozoo looks up the Demozoo production ID and confirms that the production is suitable for Defacto2. If a production is not suitable, an message is returned.

A valid production requires at least one download link and must be a suitable type such as an intro, demo or cracktro for MS-DOS, Windows etc.

func ValidatePouet added in v1.14.0

func ValidatePouet(c *echo.Context, prodID int, useCache bool) (pouet.Response, error)

ValidatePouet fetches the first usable download link from the Pouet API. The production ID is validated and the production is checked to see if it is suitable for Defacto2. If the production is not suitable, an empty production is returned with a htmx message.

Types

type Copy added in v1.10.8

type Copy int
const (
	FileID Copy = iota
	Text
	Helper
)

func (Copy) Ext added in v1.10.8

func (cp Copy) Ext() string

func (Copy) MkCopy added in v1.14.0

func (cp Copy) MkCopy(c *echo.Context, dirs command.Dirs) error

func (Copy) String added in v1.10.8

func (cp Copy) String() string

type Ext added in v1.14.0

type Ext int
const (
	Diz Ext = iota
	Hlp
	Txt
)

func (Ext) String added in v1.14.0

func (e Ext) String() string

type Insert added in v1.14.0

type Insert struct {
	FileHeader *multipart.FileHeader
	Readme     string
	Key        string
	Content    []string
	Checksum   [48]byte
	Magic      magicnumber.Signature
}

func (Insert) Upload added in v1.14.0

func (in Insert) Upload(sl *slog.Logger, c *echo.Context, tx *sql.Tx) (int64, uuid.UUID, error)

type Prod added in v1.14.0

type Prod int
const (
	Demozoo Prod = iota
	Pouet
)

func (Prod) ButtonOK added in v1.14.0

func (prod Prod) ButtonOK(c *echo.Context, prodID int, info ...string) error

func (Prod) ID added in v1.14.0

func (prod Prod) ID(c *echo.Context) (int, error)

ID validates the production ID and ensures that it is a valid numeric value.

func (Prod) Lookup added in v1.14.0

func (prod Prod) Lookup(c *echo.Context, db *sql.DB, useCache bool) error

func (Prod) String added in v1.14.0

func (prod Prod) String() string

func (Prod) Submit added in v1.14.0

func (prod Prod) Submit(
	sl *slog.Logger, c *echo.Context, db *sql.DB, tx *sql.Tx, download dir.Directory,
) error

Submit handles the PUT production routes for Demozoo and Pouet. This will attempt to insert a new file record into the database using the production ID. If the ID is already in use, an error message is returned.

Note both a sql.Tx and sql.DB are required as there are two separate commit stages.

func (Prod) ValidFn added in v1.14.0

func (prod Prod) ValidFn(c *echo.Context, prodID int, useCache bool,
	fn func(string) (string, error),
) (bool, error)

type Record added in v1.14.0

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

func (*Record) FormData added in v1.14.0

func (rec *Record) FormData(c *echo.Context) string

FormData reads the form values from the context and validates the unique identifier and record key. The returned value should be blank, otherwise there is an error.

type Submit added in v1.14.0

type Submit struct {
	Download  dir.Directory
	Extra     dir.Directory
	Preview   dir.Directory
	Thumbnail dir.Directory
}

func (Submit) Image added in v1.14.0

func (u Submit) Image(sl *slog.Logger, c *echo.Context) error

func (Submit) Replacement added in v1.14.0

func (u Submit) Replacement(sl *slog.Logger, c *echo.Context, tx *sql.Tx) error

Replacement is the file transfer handler that uploads, validates a new file upload and updates the existing artifact record with the new file information.

func (Submit) StatusOK added in v1.14.0

func (u Submit) StatusOK(c *echo.Context, filename string) error

type Transfer added in v1.14.0

type Transfer struct {
	Key      string
	Download dir.Directory
}

Transfer is a generic file transfer handler that uploads and validates a chosen file upload. The provided key is the name of the form input field.

func (Transfer) CopyTemp added in v1.14.0

func (t Transfer) CopyTemp(sl *slog.Logger, fname uuid.UUID, tempDest string)

CopyTemp copies the uploaded file to the downloads directory store. The fname UUID needs be provided as a unique identifier filename. The tempDest is the saved, temporary file that was uploaded.

func (Transfer) StatusOK added in v1.14.0

func (t Transfer) StatusOK(c *echo.Context, fname string, id int64) error

func (Transfer) Submit added in v1.14.0

func (t Transfer) Submit(sl *slog.Logger, c *echo.Context, tx *sql.Tx) error

type YMD added in v1.14.0

type YMD int

YMD are the date of release form input options.

const (
	DateForm YMD = iota // DateForm uses the form inputs
	DateUndo            // DateUndo uses the revert toggle
	DateLast            // DateLast uses the date lastmodification toggle
)

Jump to

Keyboard shortcuts

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