handlers

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

internal/api/handlers/component.go

Index

Constants

View Source
const DefaultRegistrationRole = "viewer"

DefaultRegistrationRole is the role given to self-registered accounts.

Variables

View Source
var MediaPolicy = storage.UploadPolicy{MaxSize: 50 << 20}

MediaPolicy limits uploads; set at startup from the media configuration.

View Source
var SchemaNotifier interface {
	Notify(ctx context.Context) error
}

SchemaNotifier tells other API replicas that the schema changed. It is set at startup (see cmd/start.go); nil means single-replica mode.

Functions

func CreateAgent

func CreateAgent(c *gin.Context)

CreateAgent handles creating a new agent.

func CreateCollection

func CreateCollection(c *gin.Context)

CreateCollection handles creating a new collection.

func CreateComponent

func CreateComponent(c *gin.Context)

CreateComponentHandler creates a new component definition.

func CreateOrUpdateSingleton

func CreateOrUpdateSingleton(c *gin.Context)

CreateOrUpdateSingleton handles the creation or updating of a single type.

func CreateOrUpdateSingletonItem

func CreateOrUpdateSingletonItem(c *gin.Context)

CreateOrUpdateSingletonItem creates or replaces a singleton's content. Requires the update permission.

func CreateUser

func CreateUser(c *gin.Context)

CreateUser lets an admin create an account with any existing role.

func DeleteAgent

func DeleteAgent(c *gin.Context)

DeleteAgent handles deleting an agent by its name.

func DeleteCollection

func DeleteCollection(c *gin.Context)

DeleteCollectionByIDHandler handles deleting a collection by its ID.

func DeleteComponent

func DeleteComponent(c *gin.Context)

DeleteComponentHandler deletes a component by name.

func DeleteItem

func DeleteItem(ct models.Collection) gin.HandlerFunc

func DeleteMedia added in v0.4.0

func DeleteMedia(c *gin.Context)

DeleteMedia removes a file and its content. Requires the delete permission.

func DeleteSingleton

func DeleteSingleton(c *gin.Context)

DeleteSingleton handles deleting a single type by its name (optional).

func DeleteUser

func DeleteUser(c *gin.Context)

DeleteUser handles deleting a user.

func DynamicCollectionHandler

func DynamicCollectionHandler(c *gin.Context)

DynamicCollectionHandler handles CRUD operations for dynamic collections.

func GetAgent

func GetAgent(c *gin.Context)

func GetAgents

func GetAgents(c *gin.Context)

GetAgents retrieves a list of agents with optional filtering and pagination.

func GetAllUsers

func GetAllUsers(c *gin.Context)

GetAllUsers handles fetching all users.

func GetCollection

func GetCollection(c *gin.Context)

func GetCollections

func GetCollections(c *gin.Context)

GetCollections retrieves a list of collections with optional filtering, sorting, and pagination.

func GetComponent

func GetComponent(c *gin.Context)

GetComponentHandler retrieves a component by name.

func GetComponents

func GetComponents(c *gin.Context)

GetComponents lists all component definitions.

func GetItemByID

func GetItemByID(ct models.Collection, id uint, rc readContext) gin.HandlerFunc

GetItemByID retrieves a single item by ID.

func GetItems

func GetItems(collection models.Collection, rc readContext) gin.HandlerFunc

GetItems lists a collection's items with pagination, filtering and sorting.

Query parameters:

page, pageSize                 pagination (pageSize max 100)
filters[<field>][<op>]=<value> op: $eq $ne $lt $lte $gt $gte $contains
filters[<field>]=<value>       shorthand for $eq
sort=<field>[:asc|:desc],...   multiple keys allowed
status=published|draft|all     draft-and-publish collections (default published)

<field> is a collection attribute or one of id, createdAt, updatedAt, publishedAt (snake_case also accepted).

func GetMedia added in v0.4.0

func GetMedia(c *gin.Context)

GetMedia returns one media file. Requires the create permission, like ListMedia.

func GetSingleItem

func GetSingleItem(c *gin.Context)

GetSingleItem returns a singleton's content in the flat item shape, with relations populated down to "level" (default 1).

func GetSingleton

func GetSingleton(c *gin.Context)

GetSingleton retrieves a single type by its name.

func GetSingletons

func GetSingletons(c *gin.Context)

GetSingletons lists all singleton definitions.

func GetUser

func GetUser(c *gin.Context)

GetUser handles fetching a single user by ID.

func GraphQLHandler

func GraphQLHandler(c *gin.Context)

GraphQLHandler executes a GraphQL request. The caller's role is passed to resolvers through the context so that queries and mutations enforce the same permissions as the REST API.

func HandleWebhook

func HandleWebhook(c *gin.Context)

HandleWebhook is the Gin handler for incoming agent webhook requests.

func InitAsynqClient

func InitAsynqClient(client *asynq.Client)

InitAsynqClient initializes the trigger package with a shared Asynq client. This function should be called once when your server starts.

func ListMedia added in v0.4.0

func ListMedia(c *gin.Context)

ListMedia lists the media library: page, pageSize, mime (type prefix such as "image/") and search (file name). Browsing the library needs the create permission: it includes files only drafts use, so readers only reach files through the content that references them.

func Login

func Login(c *gin.Context)

func PublishItem added in v0.4.0

func PublishItem(publish bool) gin.HandlerFunc

PublishItem publishes (publish=true) or unpublishes an item of a draft-and-publish collection: POST /api/collections/:collection/:id/publish and /unpublish. Requires the update permission.

func Register

func Register(c *gin.Context)

Register creates a new account through the public endpoint.

The caller can never choose its own role: the very first account created on an empty instance becomes "admin" (bootstrap), every later account gets the least-privileged DefaultRegistrationRole. Admins promote users through PUT /admin/users/:id.

func ServeLocalMedia added in v0.4.0

func ServeLocalMedia(store *media.Local) gin.HandlerFunc

ServeLocalMedia serves files of the local driver under /uploads/<key>. Only files recorded in the media library are served, with their detected type, and with headers that stop browsers from running anything in them.

func UpdateAgent

func UpdateAgent(c *gin.Context)

UpdateAgent handles updating an existing agent.

func UpdateCollection

func UpdateCollection(c *gin.Context)

UpdateCollection handles updating an existing collection.

func UpdateComponent

func UpdateComponent(c *gin.Context)

UpdateComponentHandler updates an existing component definition.

func UpdateItem

func UpdateItem(collection models.Collection) gin.HandlerFunc

UpdateItem replaces an item's data. The body's optional "status" publishes or unpublishes it in draft-and-publish collections.

func UpdateMedia added in v0.4.0

func UpdateMedia(c *gin.Context)

UpdateMedia changes a file's name, alt text or caption: {"data": {"alt": "…"}}. Requires the update permission.

func UpdateUser

func UpdateUser(c *gin.Context)

UpdateUser lets an admin change a user's username, email, password or role. Unknown fields are rejected so that arbitrary columns cannot be written.

func UploadMedia added in v0.4.0

func UploadMedia(c *gin.Context)

UploadMedia stores the files of a multipart/form-data request (fields "files" or "file"; optional "alt" and "caption"). Requires the create permission. All files are stored, or none.

Types

type LoginAttemptGuard

type LoginAttemptGuard struct {
	Counter     ratelimit.Counter
	MaxFailures int
	Window      time.Duration
}

LoginAttemptGuard limits failed logins per (username, client IP) within a window. Keying on both stops password guessing against an account without letting anyone lock a user out from another address.

var LoginGuard *LoginAttemptGuard

LoginGuard is set at startup; nil disables the check.

Jump to

Keyboard shortcuts

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