api

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlbumTitleMinLength = 2                          // Minimum length for image title
	AlbumTitleMaxLength = 32                         // Maximum length for image title
	AlbumTitleRegex     = `^[a-zA-Z0-9\-\/ ]{1,32}$` // Regex for image title, alphanumeric, spaces, max 64 chars

	AlbumDescriptionMinLength = 3                           // Minimum length for image description
	AlbumDescriptionMaxLength = 255                         // Maximum length for image description
	AlbumDescriptionRegex     = `^[\w\s.,!?'"()&-]{0,255}$` // Regex for image description, allows alphanumeric, spaces, punctuation, max 255 chars
)
View Source
const (
	ImageTitleMinLength = 3                      // Minimum length for image title
	ImageTitleMaxLength = 64                     // Maximum length for image title
	ImageTitleRegex     = `^[a-zA-Z0-9 ]{1,64}$` // Regex for image title, alphanumeric, spaces, max 64 chars

	ImageDescriptionMinLength = 3                           // Minimum length for image description
	ImageDescriptionMaxLength = 255                         // Maximum length for image description
	ImageDescriptionRegex     = `^[\w\s.,!?'"()&-]{0,255}$` // Regex for image description, allows alphanumeric, spaces, punctuation, max 255 chars

	ImageMaxSize = 10 * 1024 * 1024 // Maximum size for image file, 10 MB
)

Variables

View Source
var AllowedExtensions = []string{
	"jpg",
	"jpeg",
	"png",
	"gif",
	"webp",
	"tiff",
	"bmp",
	"svg",
}
View Source
var AllowedFileTypes = []string{
	"image/jpeg",
	"image/png",
	"image/gif",
	"image/webp",
	"image/tiff",
	"image/bmp",
	"image/svg+xml",
}

Functions

func IsValidExtension added in v0.1.3

func IsValidExtension(ext string) bool

func IsValidFiletype added in v0.1.7

func IsValidFiletype(fileType string) bool

IsValidFiletype checks if the provided file type is allowed from a list of accepted types.

Types

type AddAlbumCmd

type AddAlbumCmd struct {
	Csrf string `json:"csrf"`

	Title       string `json:"title"`
	Description string `json:"description"`
	IsArchived  bool   `json:"is_archived"`
}

AddAlbumCmd is a a model which represents the command to add a new album record.

func (*AddAlbumCmd) Validate

func (cmd *AddAlbumCmd) Validate() error

Validate validates the AddAlbumCmd -> input validation.

type AddMetaDataCmd

type AddMetaDataCmd struct {
	Csrf string `json:"csrf,omitempty"` // CSRF token for security

	Title       string                   `json:"title"`                 // Title of the image
	Description string                   `json:"description"`           // Description of the image
	FileType    string                   `json:"file_type"`             // MIME type of the image, eg, "image/jpeg", "image/png"
	Size        int64                    `json:"size"`                  // Size of the image file in bytes
	Albums      []Album                  `json:"albums,omitempty"`      // Albums to be associated with the image
	Permissions []permissions.Permission `json:"permissions,omitempty"` // Permissions to be associated with the image
}

AddMetaDataCmd is a command that adds metadata to an image record. model represents the incoming data (title, description, filetype, size) for an image reocord to be created and the object key set up in the object storage service., it will not be used by pixie, but may need to be set by other servies using this pacakge. Note: csrf will not be used by pixie, but may need to be set by other servies using this pacakge.

func (*AddMetaDataCmd) GetExtension

func (cmd *AddMetaDataCmd) GetExtension() (string, error)

GetExtension returns the file extension based on the MIME type.

func (*AddMetaDataCmd) Validate

func (cmd *AddMetaDataCmd) Validate() error

Validate checks the AddMetaDataCmd for valid data. It ensures that the title, description, file type, and size meet the specified criteria.

type Album

type Album struct {
	Csrf        string          `json:"csrf,omitempty"` // CSRF token, if required, or if present
	Id          string          `json:"id,omitempty"`
	Title       string          `json:"title"`
	Description string          `json:"description"`
	Slug        string          `json:"slug,omitempty"`
	CreatedAt   data.CustomTime `json:"created_at,omitempty"`
	UpdatedAt   data.CustomTime `json:"updated_at,omitempty"`
	IsArchived  bool            `json:"is_archived"`
	Images      []ImageData     `json:"images,omitempty"` // image metadata records + their thumbnails signed urls
}

Album is a model which represents an album in the API response.

func (*Album) Validate

func (a *Album) Validate() error

Validate validates the Album -> input validation.

type AlbumImageRecord added in v0.1.7

type AlbumImageRecord struct {
	AlbumId          string          `db:"album_uuid"`
	AlbumTitle       string          `db:"album_title"`       // encrypted
	AlbumDescription string          `db:"album_description"` // encrypted
	AlbumSlug        string          `db:"album_slug"`        // encrypted
	AlbumCreatedAt   data.CustomTime `db:"album_created_at"`
	AlbumUpdatedAt   data.CustomTime `db:"album_updated_at"`
	AlbumIsArchived  bool            `db:"album_is_archived"`
	ImageId          string          `db:"image_uuid"`         // Unique identifier for the image record
	ImageTitle       string          `db:"image_title"`        // encrypted: title of the image
	ImageDescription string          `db:"image_description"`  // encrypted: description of the image
	FileName         string          `db:"file_name"`          // name of the file with it's extension, eg, "slug.jpg"
	FileType         string          `db:"file_type"`          // MIME type of the image, eg, "jpeg"
	ObjectKey        string          `db:"object_key"`         // The key used to store the image in object storage, eg, "2025/slug.jpg"
	ImageSlug        string          `db:"image_slug"`         // encrypted: a unique slug for the image, used in URLs
	Width            int             `db:"width"`              // Width of the image in pixels
	Height           int             `db:"height"`             // Height of the image in pixels
	Size             int64           `db:"size"`               // Size of the image file in bytes
	ImageDate        string          `db:"image_date"`         // encrypted: date when the image was taken or created, ie, from exif metadata
	ImageCreatedAt   string          `db:"image_created_at"`   // Timestamp when the image was created
	ImageUpdatedAt   string          `db:"image_updated_at"`   // Timestamp when the image was last updated
	ImageIsArchived  bool            `db:"image_is_archived"`  // Indicates if the image is archived
	ImageIsPublished bool            `db:"image_is_published"` // Indicates if the image is published and visible to users
}

AlbumImageRecord is a model which represents a row of data from a JOIN query between the album, album_image, and image tables.

type AlbumImageXref added in v0.1.7

type AlbumImageXref struct {
	Id        int             `db:"id"`
	AlbumId   string          `db:"album_uuid"`
	ImageId   string          `db:"image_uuid"`
	CreatedAt data.CustomTime `db:"created_at"`
}

AlbumImageXref is a model which represents a record in the album_image cross-reference table.

type AlbumRecord added in v0.1.7

type AlbumRecord struct {
	Id          string          `db:"uuid" json:"id,omitempty"`
	Title       string          `db:"title" json:"title"`             // encrypted
	Description string          `db:"description" json:"description"` // encrypted
	Slug        string          `db:"slug" json:"slug,omitempty"`     // encrypted
	SlugIndex   string          `db:"slug_index" json:"slug_index,omitempty"`
	CreatedAt   data.CustomTime `db:"created_at" json:"created_at,omitempty"`
	UpdatedAt   data.CustomTime `db:"updated_at" json:"updated_at,omitempty"`
	IsArchived  bool            `db:"is_archived" json:"is_archived"`
}

AlbumRecord is a model which represents an album record in the database.

func (*AlbumRecord) Validate added in v0.1.7

func (a *AlbumRecord) Validate() error

Validate validates the AlbumRecord -> input validation.

type AlbumUpdateCmd

type AlbumUpdateCmd struct {
	Csrf        string `json:"csrf,omitempty"` // this may not always be required
	Title       string `json:"title"`
	Description string `json:"description"`
	IsArchived  bool   `json:"is_archived"`
}

AlbumUpdateCmd is a model which represents the command to update an existing album record.

func (*AlbumUpdateCmd) Validate

func (cmd *AlbumUpdateCmd) Validate() error

type ImageData

type ImageData struct {
	Id          string `db:"uuid" json:"id,omitempty"`               // Unique identifier for the image record
	Title       string `db:"title" json:"title"`                     // Title of the image
	Description string `db:"description" json:"description"`         // Description of the image
	FileName    string `db:"file_name" json:"file_name,omitempty"`   // name of the file with it's extension, eg, "slug.jpg"   // MIME type of the image, eg, "image/jpeg", "image/png"
	FileType    string `db:"file_type" json:"file_type,omitempty"`   // MIME type of the image, eg, "image/jpeg", "image/png"
	ObjectKey   string `db:"object_key" json:"object_key,omitempty"` // The key used to store the image in object storage, eg, "2025/slug.jpg"
	Slug        string `db:"slug" json:"slug,omitempty"`             // unique slug for the image, used in URLs
	Width       int    `db:"width" json:"width,omitempty"`           // Width of the image in pixels
	Height      int    `db:"height" json:"height,omitempty"`         // Height of the image in pixels
	Size        int64  `db:"size" json:"size,omitempty"`             // Size of the image file in bytes
	ImageDate   string `db:"image_date" json:"image_date,omitempty"` // Date when the image was taken or created, ie, from exif metadata
	CreatedAt   string `db:"created_at" json:"created_at,omitempty"` // Timestamp when the image was created
	UpdatedAt   string `db:"updated_at" json:"updated_at,omitempty"` // Timestamp when the image was last updated
	IsArchived  bool   `db:"is_archived" json:"is_archived"`         // Indicates if the image is archived
	IsPublished bool   `db:"is_published" json:"is_published"`       // Indicates if the image is published and visible to users

	// pre-signed GET URLs for the browser to access the image in object storage at various resolutions.
	// This field is dynamically generated and not stored in the database.
	// Note, this could be thumbnail tiles or larger images, or both, depending on the request context.
	ImageTargets []ImageTarget `json:"image_targets,omitempty"` // The signed URL for the image, used to access the image in object storage
	BlurUrl      string        `json:"blur_url,omitempty"`      // The signed URL for the blurred placeholder image, used for lazy loading in the browser

	// these fields may or may not be present, depending on the context, access, query, etc.
	Albums      []Album                  `json:"albums,omitempty"`      // Albums to which the image belongs
	Permissions []permissions.Permission `json:"permissions,omitempty"` // Permissions associated with the image
}

ImageData is a composite model that includes both the necessary fields from database record but also the signed url from the object storage service and other metadata. It is used to return image data to the client in a single response.

type ImageRecord added in v0.1.7

type ImageRecord struct {
	Id          string          `db:"uuid" json:"id"`                   // Unique identifier for the image record
	Title       string          `db:"title" json:"title"`               // ENCRYPTED: title of the image
	Description string          `db:"description" json:"description"`   // ENCRYPTED: description of the image
	FileName    string          `db:"file_name" json:"file_name"`       // name of the file with it's extension, eg, "slug.jpg"
	FileType    string          `db:"file_type" json:"file_type"`       // MIME type of the image, eg, "jpeg"
	ObjectKey   string          `db:"object_key" json:"object_key"`     // The key used to store the image in object storage, eg, "2025/slug.jpg"
	Slug        string          `db:"slug" json:"slug"`                 // ENCRYPTED: a unique slug for the image, used in URLs
	SlugIndex   string          `db:"slug_index" json:"slug_index"`     // blind index for slug, indexed for fast lookups
	Width       int             `db:"width" json:"width"`               // Width of the image in pixels
	Height      int             `db:"height" json:"height"`             // Height of the image in pixels
	Size        int64           `db:"size" json:"size"`                 // Size of the image file in bytes
	ImageDate   string          `db:"image_date" json:"image_date"`     // ENCRYPTED: date when the image was taken or created, ie, from exif metadata
	CreatedAt   data.CustomTime `db:"created_at" json:"created_at"`     // Timestamp when the image was created
	UpdatedAt   data.CustomTime `db:"updated_at" json:"updated_at"`     // Timestamp when the image was last updated
	IsArchived  bool            `db:"is_archived" json:"is_archived"`   // Indicates if the image is archived
	IsPublished bool            `db:"is_published" json:"is_published"` // Indicates if the image is published and visible to users
}

ImageRecord is a model that represents the image record in the database. It contains the fields that are stored in the database, such as the image slug, metadata, and any other relevant information. It does not include the signed URL, as that is generated dynamically when requested.

func (*ImageRecord) Validate added in v0.1.7

func (r *ImageRecord) Validate() error

Validate checks the ImageRecord for valid data before storing it in the database. NOTE: regexes are for plaintext validation, not for encrypted fields.

type ImageTarget added in v0.1.4

type ImageTarget struct {
	Width     int    `json:"width,omitempty"`      // Width of the image in pixels
	SignedUrl string `json:"signed_url,omitempty"` // The signed URL for the image, used to access the image in object storage
}

ImageTarget represents the model representing the width and signed url for accessing an image in object storage. Its primary purpose is for building srcset for images in the browser.

type Patron added in v0.1.7

type Patron struct {
	Id          string                 `json:"uuid,omitempty"`
	Username    string                 `json:"username"`
	Slug        string                 `json:"slug,omitempty"`
	CreatedAt   data.CustomTime        `json:"created_at,omitempty"`
	UpdatedAt   data.CustomTime        `json:"updated_at,omitempty"`
	IsArchived  bool                   `json:"is_archived"`
	IsActive    bool                   `json:"is_active"`
	Permissions []exo.PermissionRecord `json:"permissions,omitempty"`
}

PatronRecord is a model which represents a patron record in the database.

type PatronRegisterCmd added in v0.1.7

type PatronRegisterCmd struct {
	Username string `json:"username"`
}

PatronRegisterCmd is a command for registering a new patron.

func (*PatronRegisterCmd) Validate added in v0.1.7

func (c *PatronRegisterCmd) Validate() error

Validate validates the PatronRegisterCmd -> input validation.

type Placeholder added in v0.1.3

type Placeholder struct {
	Id          string `db:"uuid" json:"id,omitempty"`               // Unique identifier for the image record
	Title       string `db:"title" json:"title"`                     // Title of the image
	Description string `db:"description" json:"description"`         // Description of the image
	FileName    string `db:"file_name" json:"file_name,omitempty"`   // name of the file with it's extension, eg, "slug.jpg"   // MIME type of the image, eg, "image/jpeg", "image/png"
	FileType    string `db:"file_type" json:"file_type,omitempty"`   // MIME type of the image, eg, "image/jpeg", "image/png"
	ObjectKey   string `db:"object_key" json:"object_key,omitempty"` // The key used to store the image in object storage, eg, "2025/slug.jpg"
	Slug        string `db:"slug" json:"slug,omitempty"`             // unique slug for the image, used in URLs
	Size        int64  `db:"size" json:"size,omitempty"`             // Size of the image file in bytes
	CreatedAt   string `db:"created_at" json:"created_at,omitempty"` // Timestamp when the image was created
	UpdatedAt   string `db:"updated_at" json:"updated_at,omitempty"` // Timestamp when the image was last updated
	IsArchived  bool   `db:"is_archived" json:"is_archived"`         // Indicates if the image is archived
	IsPublished bool   `db:"is_published" json:"is_published"`       // Indicates if the image is published and visible to users
	SignedUrl   string `json:"signed_url,omitempty"`                 // The signed PUT URL for uploading the image to object storage
}

Placeholder is a model that represents a placeholder record that is created when an image upload is initiated. It contains the metadata and the signed put url for uploading the image to object storage.

type UpdateMetadataCmd

type UpdateMetadataCmd struct {
	Csrf           string `json:"csrf,omitempty"`             // CSRF token for security -> needed by downstream services
	Slug           string `json:"slug,omitempty"`             // Slug of the image to update, must be a valid UUID
	Title          string `json:"title,omitempty"`            // Title of the image
	Description    string `json:"description,omitempty"`      // Description of the image
	ImageDateMonth int    `json:"image_date_month,omitempty"` // Month of the image date, 1-12
	ImageDateDay   int    `json:"image_date_day,omitempty"`   // Day of the image date, 1-31
	ImageDateYear  int    `json:"image_date_year,omitempty"`  // Year of the image date, 4 digits
	IsPublished    bool   `json:"is_published,omitempty"`     // Indicates if the image is published and visible to users
	IsArchived     bool   `json:"is_archived,omitempty"`      // Indicates if the image is archived

	// addition fields will be added, albums, permissions, image size, etc.
	AlbumSlugs      []string `json:"album_slugs,omitempty"`      // Slugs of the albums to associate with the image
	PermissionSlugs []string `json:"permission_slugs,omitempty"` // Slugs of the permissions to associate with the image
}

UpdateMetadataCmd is a model that represents the command to update metadata of an image record.

func (*UpdateMetadataCmd) Validate

func (cmd *UpdateMetadataCmd) Validate() error

Validate checks the UpdateMetadataCmd for valid data.

Jump to

Keyboard shortcuts

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