Documentation
¶
Overview ¶
internal/api/handlers/component.go
Index ¶
- Constants
- Variables
- func CreateAgent(c *gin.Context)
- func CreateCollection(c *gin.Context)
- func CreateComponent(c *gin.Context)
- func CreateOrUpdateSingleton(c *gin.Context)
- func CreateOrUpdateSingletonItem(c *gin.Context)
- func CreateUser(c *gin.Context)
- func DeleteAgent(c *gin.Context)
- func DeleteCollection(c *gin.Context)
- func DeleteComponent(c *gin.Context)
- func DeleteItem(ct models.Collection) gin.HandlerFunc
- func DeleteMedia(c *gin.Context)
- func DeleteSingleton(c *gin.Context)
- func DeleteUser(c *gin.Context)
- func DynamicCollectionHandler(c *gin.Context)
- func GetAgent(c *gin.Context)
- func GetAgents(c *gin.Context)
- func GetAllUsers(c *gin.Context)
- func GetCollection(c *gin.Context)
- func GetCollections(c *gin.Context)
- func GetComponent(c *gin.Context)
- func GetComponents(c *gin.Context)
- func GetItemByID(ct models.Collection, id uint, rc readContext) gin.HandlerFunc
- func GetItems(collection models.Collection, rc readContext) gin.HandlerFunc
- func GetMedia(c *gin.Context)
- func GetSingleItem(c *gin.Context)
- func GetSingleton(c *gin.Context)
- func GetSingletons(c *gin.Context)
- func GetUser(c *gin.Context)
- func GraphQLHandler(c *gin.Context)
- func HandleWebhook(c *gin.Context)
- func InitAsynqClient(client *asynq.Client)
- func ListMedia(c *gin.Context)
- func Login(c *gin.Context)
- func PublishItem(publish bool) gin.HandlerFunc
- func Register(c *gin.Context)
- func ServeLocalMedia(store *media.Local) gin.HandlerFunc
- func UpdateAgent(c *gin.Context)
- func UpdateCollection(c *gin.Context)
- func UpdateComponent(c *gin.Context)
- func UpdateItem(collection models.Collection) gin.HandlerFunc
- func UpdateMedia(c *gin.Context)
- func UpdateUser(c *gin.Context)
- func UploadMedia(c *gin.Context)
- type LoginAttemptGuard
Constants ¶
const DefaultRegistrationRole = "viewer"
DefaultRegistrationRole is the role given to self-registered accounts.
Variables ¶
var MediaPolicy = storage.UploadPolicy{MaxSize: 50 << 20}
MediaPolicy limits uploads; set at startup from the media configuration.
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 CreateCollection ¶
CreateCollection handles creating a new collection.
func CreateComponent ¶
CreateComponentHandler creates a new component definition.
func CreateOrUpdateSingleton ¶
CreateOrUpdateSingleton handles the creation or updating of a single type.
func CreateOrUpdateSingletonItem ¶
CreateOrUpdateSingletonItem creates or replaces a singleton's content. Requires the update permission.
func CreateUser ¶
CreateUser lets an admin create an account with any existing role.
func DeleteAgent ¶
DeleteAgent handles deleting an agent by its name.
func DeleteCollection ¶
DeleteCollectionByIDHandler handles deleting a collection by its ID.
func DeleteComponent ¶
DeleteComponentHandler deletes a component by name.
func DeleteItem ¶
func DeleteItem(ct models.Collection) gin.HandlerFunc
func DeleteMedia ¶ added in v0.4.0
DeleteMedia removes a file and its content. Requires the delete permission.
func DeleteSingleton ¶
DeleteSingleton handles deleting a single type by its name (optional).
func DynamicCollectionHandler ¶
DynamicCollectionHandler handles CRUD operations for dynamic collections.
func GetCollection ¶
func GetCollections ¶
GetCollections retrieves a list of collections with optional filtering, sorting, and pagination.
func GetComponent ¶
GetComponentHandler retrieves a component by name.
func GetComponents ¶
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
GetMedia returns one media file. Requires the create permission, like ListMedia.
func GetSingleItem ¶
GetSingleItem returns a singleton's content in the flat item shape, with relations populated down to "level" (default 1).
func GetSingleton ¶
GetSingleton retrieves a single type by its name.
func GetSingletons ¶
GetSingletons lists all singleton definitions.
func GraphQLHandler ¶
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 ¶
HandleWebhook is the Gin handler for incoming agent webhook requests.
func InitAsynqClient ¶
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
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 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 ¶
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 UpdateCollection ¶
UpdateCollection handles updating an existing collection.
func UpdateComponent ¶
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
UpdateMedia changes a file's name, alt text or caption: {"data": {"alt": "…"}}. Requires the update permission.
func UpdateUser ¶
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
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 ¶
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.