- Move all ContentItem, ContentClient, ContentResponse types to engine/types.go as single source of truth - Remove duplicate type definitions from content/types.go - Update all imports across codebase to use engine types - Enhance engine to extract existing data-content-id from HTML markup - Simplify frontend to always send html_markup, let server handle ID extraction/generation - Fix contentId reference errors in frontend error handling - Add getAttribute helper method to engine for ID extraction - Add GetAllContent method to engine.DatabaseClient - Update enhancer to use engine.ContentClient interface - All builds and API endpoints verified working This resolves the 400 Bad Request errors and creates a unified architecture where the server is the single source of truth for all ID generation and content type management.
68 lines
2.3 KiB
Go
68 lines
2.3 KiB
Go
package engine
|
|
|
|
import (
|
|
"golang.org/x/net/html"
|
|
)
|
|
|
|
// ProcessMode defines how the engine should process content
|
|
type ProcessMode int
|
|
|
|
const (
|
|
// Enhancement mode: Parse + Generate IDs + Inject content + Add editor assets
|
|
Enhancement ProcessMode = iota
|
|
// IDGeneration mode: Parse + Generate IDs only (for API)
|
|
IDGeneration
|
|
// ContentInjection mode: Parse + Generate IDs + Inject content only
|
|
ContentInjection
|
|
)
|
|
|
|
// ContentInput represents input to the content engine
|
|
type ContentInput struct {
|
|
HTML []byte // Raw HTML or markup
|
|
FilePath string // File context (e.g., "index.html")
|
|
SiteID string // Site identifier
|
|
Mode ProcessMode // Processing mode
|
|
}
|
|
|
|
// ContentResult represents the result of content processing
|
|
type ContentResult struct {
|
|
Document *html.Node // Processed HTML document
|
|
Elements []ProcessedElement // All processed elements
|
|
GeneratedIDs map[string]string // Map of element positions to generated IDs
|
|
}
|
|
|
|
// ProcessedElement represents an element that has been processed
|
|
type ProcessedElement struct {
|
|
Node *html.Node // HTML node
|
|
ID string // Generated content ID
|
|
Type string // Content type (text, markdown, link)
|
|
Content string // Injected content (if any)
|
|
Generated bool // Whether ID was generated (vs existing)
|
|
Tag string // Element tag name
|
|
Classes []string // Element CSS classes
|
|
}
|
|
|
|
// ContentClient interface for accessing content data
|
|
// This will be implemented by database clients, HTTP clients, and mock clients
|
|
type ContentClient interface {
|
|
GetContent(siteID, contentID string) (*ContentItem, error)
|
|
GetBulkContent(siteID string, contentIDs []string) (map[string]ContentItem, error)
|
|
GetAllContent(siteID string) (map[string]ContentItem, error)
|
|
}
|
|
|
|
// ContentItem represents a piece of content from the database
|
|
type ContentItem struct {
|
|
ID string `json:"id"`
|
|
SiteID string `json:"site_id"`
|
|
Value string `json:"value"`
|
|
Type string `json:"type"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
LastEditedBy string `json:"last_edited_by,omitempty"`
|
|
}
|
|
|
|
// ContentResponse represents the API response structure
|
|
type ContentResponse struct {
|
|
Content []ContentItem `json:"content"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|