api

package
v0.0.0-...-a78c924 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(db *gorm.DB, jwtSecret string) echo.MiddlewareFunc

func CleanExpiredTokens

func CleanExpiredTokens(db *gorm.DB)

CleanExpiredTokens removes revocation entries whose JWTs have naturally expired. Called periodically to keep the table small.

func CustomErrorHandler

func CustomErrorHandler(err error, c echo.Context)

func GetUserFromContext

func GetUserFromContext(c echo.Context) (userID, email, role string)

func HashToken

func HashToken(token string) string

HashToken returns the SHA-256 hex digest of a raw JWT string.

func IsTokenRevoked

func IsTokenRevoked(db *gorm.DB, token string) bool

IsTokenRevoked checks whether a token has been explicitly revoked.

func MigratePublicBucketPolicies

func MigratePublicBucketPolicies(db *gorm.DB, client bucketClient)

MigratePublicBucketPolicies ensures all buckets marked public in the DB have a corresponding public-read bucket policy in SeaweedFS. This covers buckets created before the bucket policy implementation.

func NewS3Proxy

func NewS3Proxy(s3Endpoint string) http.Handler

NewS3Proxy creates a reverse proxy that forwards requests to the SeaweedFS S3 endpoint. Auth and public access are handled by SeaweedFS itself via its s3.config.json and bucket policies.

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, db *gorm.DB, cfg *config.Config, store *storage.Manager, serverVersion string, workerEngine *worker.Engine, s3Client *minio.Client, iamClient *seaweedfs.Client, region string, analyticsDB *gorm.DB)

func RequireAdmin

func RequireAdmin() echo.MiddlewareFunc

func RequireRole

func RequireRole(roles ...string) echo.MiddlewareFunc

func RequireSiteOwner

func RequireSiteOwner(db *gorm.DB) echo.MiddlewareFunc

RequireSiteOwner checks that the authenticated user owns the site identified by the :id path parameter, or has an admin/superadmin role.

func RevokeToken

func RevokeToken(db *gorm.DB, token string, expiresAt time.Time) error

RevokeToken adds a token to the revocation table. The expiresAt should match the token's natural expiry so the entry can be cleaned up later.

func SubdomainRouter

func SubdomainRouter(db *gorm.DB, store *storage.Manager, cache *storage.SiteRulesCache, domain string, workerEngine *worker.Engine, s3Proxy http.Handler, workerDeps *WorkerDeps, collector *analytics.Collector) echo.MiddlewareFunc

SubdomainRouter inspects the Host header and routes subdomain requests to the static site handler. Bare-domain requests pass through to the API. When collector is non-nil, each served request is recorded for analytics.

func VersionCheckMiddleware

func VersionCheckMiddleware(minVersion string) echo.MiddlewareFunc

VersionCheckMiddleware rejects requests from CLI clients whose version is below the configured minimum. Skips if no minimum is set, if the header is absent (browser/curl), or if the version is unparseable (dev builds).

Types

type APIKeyHandler

type APIKeyHandler struct {
	DB *gorm.DB
}

func (*APIKeyHandler) Create

func (h *APIKeyHandler) Create(c echo.Context) error

func (*APIKeyHandler) Delete

func (h *APIKeyHandler) Delete(c echo.Context) error

func (*APIKeyHandler) List

func (h *APIKeyHandler) List(c echo.Context) error

type AdminHandler

type AdminHandler struct {
	DB        *gorm.DB
	Storage   *storage.Manager
	S3Client  *minio.Client     // optional; nil when object storage is disabled
	IAMClient *seaweedfs.Client // optional; nil when object storage is disabled
}

func (*AdminHandler) CreateInvite

func (h *AdminHandler) CreateInvite(c echo.Context) error

func (*AdminHandler) DeleteUser

func (h *AdminHandler) DeleteUser(c echo.Context) error

func (*AdminHandler) GetSettings

func (h *AdminHandler) GetSettings(c echo.Context) error

func (*AdminHandler) ListInvites

func (h *AdminHandler) ListInvites(c echo.Context) error

func (*AdminHandler) ListUsers

func (h *AdminHandler) ListUsers(c echo.Context) error

func (*AdminHandler) RevokeInvite

func (h *AdminHandler) RevokeInvite(c echo.Context) error

func (*AdminHandler) UpdateSettings

func (h *AdminHandler) UpdateSettings(c echo.Context) error

func (*AdminHandler) UpdateUserRole

func (h *AdminHandler) UpdateUserRole(c echo.Context) error

type AnalyticsHandler

type AnalyticsHandler struct {
	DB          *gorm.DB // main database (for site ownership checks)
	AnalyticsDB *gorm.DB // analytics database
}

AnalyticsHandler serves analytics data for sites.

func (*AnalyticsHandler) GetPages

func (h *AnalyticsHandler) GetPages(c echo.Context) error

GetPages returns top pages for a site. GET /sites/:id/analytics/pages?period=24h|7d|30d&limit=10

func (*AnalyticsHandler) GetReferrers

func (h *AnalyticsHandler) GetReferrers(c echo.Context) error

GetReferrers returns top referrers for a site. GET /sites/:id/analytics/referrers?period=24h|7d|30d&limit=10

func (*AnalyticsHandler) GetSummary

func (h *AnalyticsHandler) GetSummary(c echo.Context) error

GetSummary returns aggregate analytics totals for a site. GET /sites/:id/analytics/summary?period=24h|7d|30d

func (*AnalyticsHandler) GetTimeseries

func (h *AnalyticsHandler) GetTimeseries(c echo.Context) error

GetTimeseries returns time-bucketed analytics data for charting. GET /sites/:id/analytics/timeseries?period=24h|7d|30d

type AuditHandler

type AuditHandler struct {
	DB *gorm.DB
}

AuditHandler serves the audit log listing endpoint.

func (*AuditHandler) List

func (h *AuditHandler) List(c echo.Context) error

List returns paginated audit log entries. Admins see all entries; regular users see only their own.

type AuthHandler

type AuthHandler struct {
	DB        *gorm.DB
	JWTSecret string
}

func (*AuthHandler) CLILogin

func (h *AuthHandler) CLILogin(c echo.Context) error

CLILogin serves a self-contained HTML login form for CLI authentication. GET /api/v1/auth/cli?port=PORT&state=STATE&code_challenge=CHALLENGE&code_challenge_method=S256

func (*AuthHandler) CLILoginSubmit

func (h *AuthHandler) CLILoginSubmit(c echo.Context) error

CLILoginSubmit validates credentials and returns a redirect URL with an auth code. POST /api/v1/auth/cli

func (*AuthHandler) Login

func (h *AuthHandler) Login(c echo.Context) error

func (*AuthHandler) Logout

func (h *AuthHandler) Logout(c echo.Context) error

func (*AuthHandler) Register

func (h *AuthHandler) Register(c echo.Context) error

func (*AuthHandler) RegistrationInfo

func (h *AuthHandler) RegistrationInfo(c echo.Context) error

RegistrationInfo returns public registration settings (no auth required). GET /api/v1/auth/registration

func (*AuthHandler) TokenExchange

func (h *AuthHandler) TokenExchange(c echo.Context) error

TokenExchange exchanges an authorization code + PKCE code verifier for a JWT. POST /api/v1/auth/token

type DeployHandler

type DeployHandler struct {
	DB              *gorm.DB
	Storage         *storage.Manager
	MaxScriptSizeKB int
	WorkerEngine    interface {
		CompileAndCache(siteID string, deployKey string, source string) ([]byte, error)
		InvalidatePool(siteID string, deployKey string)
	}
}

func (*DeployHandler) Deploy

func (h *DeployHandler) Deploy(c echo.Context) error

func (*DeployHandler) List

func (h *DeployHandler) List(c echo.Context) error

func (*DeployHandler) Rollback

func (h *DeployHandler) Rollback(c echo.Context) error

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type SiteHandler

type SiteHandler struct {
	DB        *gorm.DB
	Storage   *storage.Manager
	S3Client  *minio.Client     // optional; nil when object storage is disabled
	IAMClient *seaweedfs.Client // optional; nil when object storage is disabled
	DataDir   string
}

func (*SiteHandler) Create

func (h *SiteHandler) Create(c echo.Context) error

func (*SiteHandler) Delete

func (h *SiteHandler) Delete(c echo.Context) error

func (*SiteHandler) Get

func (h *SiteHandler) Get(c echo.Context) error

func (*SiteHandler) List

func (h *SiteHandler) List(c echo.Context) error

func (*SiteHandler) Update

func (h *SiteHandler) Update(c echo.Context) error

type StorageHandler

type StorageHandler struct {
	DB          *gorm.DB
	S3Client    bucketClient
	IAMClient   iamClient
	Region      string
	PublicS3URL string // public-facing S3 URL (e.g. https://storage.example.com)
}

StorageHandler manages object storage buckets and S3 credentials.

func (*StorageHandler) CreateBucket

func (h *StorageHandler) CreateBucket(c echo.Context) error

CreateBucket creates a storage bucket bound to a site.

func (*StorageHandler) CreateS3Credential

func (h *StorageHandler) CreateS3Credential(c echo.Context) error

CreateS3Credential creates an S3 credential for the current user.

func (*StorageHandler) DeleteBucket

func (h *StorageHandler) DeleteBucket(c echo.Context) error

DeleteBucket deletes a storage bucket.

func (*StorageHandler) DeleteS3Credential

func (h *StorageHandler) DeleteS3Credential(c echo.Context) error

DeleteS3Credential deletes an S3 credential.

func (*StorageHandler) ListBuckets

func (h *StorageHandler) ListBuckets(c echo.Context) error

ListBuckets returns all storage buckets for a site.

func (*StorageHandler) ListS3Credentials

func (h *StorageHandler) ListS3Credentials(c echo.Context) error

ListS3Credentials returns the user's S3 credentials (no secrets).

func (*StorageHandler) UpdateBucket

func (h *StorageHandler) UpdateBucket(c echo.Context) error

UpdateBucket updates a storage bucket's settings (e.g. public access toggle).

func (*StorageHandler) UploadURL

func (h *StorageHandler) UploadURL(c echo.Context) error

UploadURL generates a presigned PUT URL for uploading an object to a bucket.

type WorkerDeps

type WorkerDeps struct {
	MinioClient *minio.Client
	PublicS3URL string
	D1DataDir   string
}

WorkerDeps bundles worker-related dependencies needed by the HTTP serving chain to build complete worker environments.

type WorkerHandler

type WorkerHandler struct {
	DB      *gorm.DB
	DataDir string
}

func (*WorkerHandler) CreateCronSchedule

func (h *WorkerHandler) CreateCronSchedule(c echo.Context) error

func (*WorkerHandler) CreateD1Database

func (h *WorkerHandler) CreateD1Database(c echo.Context) error

func (*WorkerHandler) CreateDurableObjectNamespace

func (h *WorkerHandler) CreateDurableObjectNamespace(c echo.Context) error

func (*WorkerHandler) CreateKVNamespace

func (h *WorkerHandler) CreateKVNamespace(c echo.Context) error

func (*WorkerHandler) DeleteCronSchedule

func (h *WorkerHandler) DeleteCronSchedule(c echo.Context) error

func (*WorkerHandler) DeleteD1Database

func (h *WorkerHandler) DeleteD1Database(c echo.Context) error

func (*WorkerHandler) DeleteDurableObjectNamespace

func (h *WorkerHandler) DeleteDurableObjectNamespace(c echo.Context) error

func (*WorkerHandler) DeleteEnvVar

func (h *WorkerHandler) DeleteEnvVar(c echo.Context) error

func (*WorkerHandler) DeleteKVNamespace

func (h *WorkerHandler) DeleteKVNamespace(c echo.Context) error

func (*WorkerHandler) GetLogs

func (h *WorkerHandler) GetLogs(c echo.Context) error

func (*WorkerHandler) ListCronSchedules

func (h *WorkerHandler) ListCronSchedules(c echo.Context) error

func (*WorkerHandler) ListD1Databases

func (h *WorkerHandler) ListD1Databases(c echo.Context) error

func (*WorkerHandler) ListDurableObjectNamespaces

func (h *WorkerHandler) ListDurableObjectNamespaces(c echo.Context) error

func (*WorkerHandler) ListEnvVars

func (h *WorkerHandler) ListEnvVars(c echo.Context) error

func (*WorkerHandler) ListKVNamespaces

func (h *WorkerHandler) ListKVNamespaces(c echo.Context) error

func (*WorkerHandler) SetEnvVar

func (h *WorkerHandler) SetEnvVar(c echo.Context) error

Jump to

Keyboard shortcuts

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