preview

package
v0.0.0-...-8acab51 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package preview provides preview mode functionality for ZimaOS-Blue. Preview mode allows users to experience the product without creating an account.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUsernameRequired is returned when username is empty.
	ErrUsernameRequired = errors.New("username is required")
	// ErrPasswordRequired is returned when password is empty.
	ErrPasswordRequired = errors.New("password is required")
	// ErrUsersAlreadyExist is returned when preview upgrade is attempted after any user exists.
	ErrUsersAlreadyExist = errors.New("users already exist")
	// ErrAdminAlreadyExists is returned when trying to upgrade but admin already exists.
	ErrAdminAlreadyExists = errors.New("admin already exists")
)

Functions

This section is empty.

Types

type Handler

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

Handler handles preview mode HTTP requests.

func NewHandler

func NewHandler(modeService *ModeService, upgradeService *UpgradeService, jwtService *auth.JWTService, userService *user.Service) *Handler

NewHandler creates a new preview Handler.

func (*Handler) GetOnboardingStatus

func (h *Handler) GetOnboardingStatus(c echo.Context) error

GetOnboardingStatus returns whether the user has seen the onboarding modal. GET /api/v1/preview/onboarding

func (*Handler) GetPresetQuestions

func (h *Handler) GetPresetQuestions(c echo.Context) error

GetPresetQuestions returns a paged selection of preset questions. GET /api/v1/preset-questions?count=4&offset=0&lang=en

func (*Handler) GetPreviewStatus

func (h *Handler) GetPreviewStatus(c echo.Context) error

GetPreviewStatus returns the preview mode status. GET /api/v1/preview/status

func (*Handler) GetPreviewToken

func (h *Handler) GetPreviewToken(c echo.Context) error

GetPreviewToken generates a temporary token for preview mode. POST /api/v1/preview/token

func (*Handler) GetSystemMode

func (h *Handler) GetSystemMode(c echo.Context) error

GetSystemMode returns the current system mode. GET /api/v1/system/mode

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(e *echo.Echo)

RegisterRoutes registers preview mode routes.

func (*Handler) SetDataDir

func (h *Handler) SetDataDir(dataDir string)

SetDataDir sets the data directory for storing onboarding state.

func (*Handler) SetOnboardingSeen

func (h *Handler) SetOnboardingSeen(c echo.Context) error

SetOnboardingSeen marks the onboarding as seen. POST /api/v1/preview/onboarding

func (*Handler) Upgrade

func (h *Handler) Upgrade(c echo.Context) error

Upgrade handles the upgrade from preview mode to normal mode. POST /api/v1/preview/upgrade

type MigrationResult

type MigrationResult struct {
	MigratedCounts map[string]int64 `json:"migrated_counts"`
}

MigrationResult contains per-table row counts updated during preview migration.

type MigrationService

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

MigrationService handles migration of preview data to admin account.

func NewMigrationService

func NewMigrationService(db *sql.DB) *MigrationService

NewMigrationService creates a new MigrationService.

func NewMigrationServiceWithReadDB

func NewMigrationServiceWithReadDB(writeDB, readDB *sql.DB) *MigrationService

func (*MigrationService) GetMigrationStatus

func (s *MigrationService) GetMigrationStatus(ctx context.Context) (bool, error)

GetMigrationStatus checks if preview data has been migrated.

func (*MigrationService) MigratePreviewData

func (s *MigrationService) MigratePreviewData(ctx context.Context, adminUserID string) (*MigrationResult, error)

MigratePreviewData migrates all preview mode data to the new admin user.

type ModeService

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

ModeService provides preview mode detection and management.

func NewModeService

func NewModeService(userService *user.Service) *ModeService

NewModeService creates a new ModeService.

func (*ModeService) GetSystemMode

func (s *ModeService) GetSystemMode(ctx context.Context) (*SystemMode, error)

GetSystemMode returns the current system mode and available features.

func (*ModeService) IsPreviewMode

func (s *ModeService) IsPreviewMode(ctx context.Context) (bool, error)

IsPreviewMode checks if the system is in preview mode. Preview mode is active when no user exists yet.

type OnboardingStatusResponse

type OnboardingStatusResponse struct {
	Seen bool `json:"seen"`
}

OnboardingStatusResponse represents the onboarding status response.

type PresetQuestion

type PresetQuestion struct {
	ID             string                     `json:"id"`
	Title          string                     `json:"title,omitempty"`
	Description    string                     `json:"description,omitempty"`
	Prompt         string                     `json:"prompt,omitempty"`
	Text           string                     `json:"text"`
	TextKey        string                     `json:"text_key,omitempty"` // i18n key for frontend translation
	Category       string                     `json:"category"`
	Tags           []string                   `json:"tags,omitempty"`
	Icon           string                     `json:"icon,omitempty"`
	EditorialScore int                        `json:"editorial_score,omitempty"`
	Attachments    []PresetQuestionAttachment `json:"attachments,omitempty"`
}

PresetQuestion represents a curated preset question.

type PresetQuestionAttachment

type PresetQuestionAttachment struct {
	Type        string `json:"type"`        // "image" or "file"
	Name        string `json:"name"`        // filename
	MimeType    string `json:"mime_type"`   // MIME type
	Placeholder string `json:"placeholder"` // reserved for legacy preview payload compatibility
}

PresetQuestionAttachment represents an attachment for a preset question.

type PresetQuestionsResponse

type PresetQuestionsResponse struct {
	Questions  []PresetQuestion `json:"questions"`
	Total      int              `json:"total"`
	NextOffset int              `json:"next_offset"`
	HasMore    bool             `json:"has_more"`
}

PresetQuestionsResponse represents the preset questions response.

type PreviewStatusResponse

type PreviewStatusResponse struct {
	Active  bool   `json:"active"`
	Message string `json:"message"`
}

PreviewStatusResponse represents the preview status response.

type PreviewTokenResponse

type PreviewTokenResponse struct {
	Token     string `json:"token"`
	ExpiresIn int    `json:"expires_in"`
}

PreviewTokenResponse represents the preview token response.

type QuestionsService

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

QuestionsService provides preset questions for preview-related UI.

func NewQuestionsService

func NewQuestionsService() *QuestionsService

NewQuestionsService creates a new QuestionsService.

func (*QuestionsService) GetAllQuestions

func (s *QuestionsService) GetAllQuestions(lang string) []PresetQuestion

GetAllQuestions returns all preset questions for a language.

func (*QuestionsService) GetPresetQuestionPage

func (s *QuestionsService) GetPresetQuestionPage(offset, count int, lang string) ([]PresetQuestion, int)

GetPresetQuestionPage returns a deterministic slice of preset questions for incremental loading.

func (*QuestionsService) GetPresetQuestions

func (s *QuestionsService) GetPresetQuestions(count int, lang string) []PresetQuestion

GetPresetQuestions returns the leading preset questions for a language.

func (*QuestionsService) GetQuestionsByCategory

func (s *QuestionsService) GetQuestionsByCategory(category string, lang string) []PresetQuestion

GetQuestionsByCategory returns questions filtered by category.

type SystemMode

type SystemMode struct {
	Mode     string          `json:"mode"`     // "preview" or "normal"
	Features map[string]bool `json:"features"` // Available features
}

SystemMode represents the current system mode.

type UpgradeRequest

type UpgradeRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

UpgradeRequest represents a request to upgrade from preview mode.

type UpgradeResponse

type UpgradeResponse struct {
	Success        bool             `json:"success"`
	User           *user.User       `json:"user"`
	DataMigrated   bool             `json:"data_migrated"`
	MigratedCounts map[string]int64 `json:"migrated_counts,omitempty"`
}

UpgradeResponse represents the response after successful upgrade.

type UpgradeService

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

UpgradeService handles upgrading from preview mode to normal mode.

func NewUpgradeService

func NewUpgradeService(userService *user.Service, db *sql.DB) *UpgradeService

NewUpgradeService creates a new UpgradeService.

func NewUpgradeServiceWithReadDB

func NewUpgradeServiceWithReadDB(userService *user.Service, writeDB, readDB *sql.DB) *UpgradeService

NewUpgradeServiceWithReadDB creates a new UpgradeService with separate write and read database handles for preview migration status checks.

func (*UpgradeService) Upgrade

Upgrade creates an admin user and migrates preview data.

Jump to

Keyboard shortcuts

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