api

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 15 Imported by: 2 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MediaHandler

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

func NewMediaHandler

func NewMediaHandler(
	mediaService MediaServiceInterface,
	imageGenService media.ImageGenerationService,
	logger kernel.Logger,
	opts ...MediaHandlerOption,
) *MediaHandler

func (*MediaHandler) DeleteMedia

func (h *MediaHandler) DeleteMedia(w http.ResponseWriter, r *http.Request)

func (*MediaHandler) GenerateImage

func (h *MediaHandler) GenerateImage(w http.ResponseWriter, r *http.Request)

func (*MediaHandler) GetMedia

func (h *MediaHandler) GetMedia(w http.ResponseWriter, r *http.Request)

GetMedia handles GET /api/v1/media (browser admin realm). Admins manage all site media; every other role is scoped to their own library so one account cannot inventory another's file paths, hashes, and original filenames. Rows come newest-first (id DESC) using opaque keyset (cursor) pagination — the SAME contract as the agent media list (bare data array + meta.pagination). It reuses the response package's cursor helpers and SuccessList/ Pagination/ListMeta types so both auth realms share one envelope.

func (*MediaHandler) GetMediaByID

func (h *MediaHandler) GetMediaByID(w http.ResponseWriter, r *http.Request)

func (*MediaHandler) Upload

func (h *MediaHandler) Upload(w http.ResponseWriter, r *http.Request)

type MediaHandlerOption

type MediaHandlerOption func(*MediaHandler)

MediaHandlerOption configures a MediaHandler. A role service makes the media capabilities config-driven; without one every authenticated user may upload, generate, and delete media (the legacy behavior).

func WithMediaRoleService

func WithMediaRoleService(rs RoleCapabilities) MediaHandlerOption

WithMediaRoleService attaches the config-driven role registry so upload, generate, and delete are gated by the caller's CanMedia capability.

type MediaServiceInterface

type MediaServiceInterface interface {
	Upload(ctx context.Context, req media.UploadRequest) (*media.Media, error)
	ForceUpload(ctx context.Context, req media.UploadRequest) (*media.Media, error)
	GenerateFromBytes(ctx context.Context, imageBytes []byte, principal kernel.Principal, altText string, originalFilename string) (*media.Media, error)
	GetByID(ctx context.Context, id int) (*media.Media, error)
	Delete(ctx context.Context, id int, principal kernel.Principal) error
	SearchMediaByCursor(ctx context.Context, principal kernel.Principal, search string, dateFilter string, limit int, beforeID int) ([]*media.Media, error)
	Count(ctx context.Context, principal kernel.Principal, search string, dateFilter string) (int, error)
}

type RoleCapabilities

type RoleCapabilities interface {
	CanMedia(name string) bool
}

RoleCapabilities is the narrow role-registry seam this handler depends on. Core satisfies it with an adapter over *role.Service (which cannot be imported here); the users module implements it natively when it lands.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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