Consolidate type definitions and fix API contract

- 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.
This commit is contained in:
2025-09-16 16:45:29 +02:00
parent d0ac3088b4
commit d877366be0
15 changed files with 150 additions and 181 deletions

View File

@@ -37,20 +37,33 @@ func (e *ContentEngine) ProcessContent(input ContentInput) (*ContentResult, erro
processedElements := make([]ProcessedElement, len(elements))
for i, elem := range elements {
// Generate ID using the same algorithm as the parser
id := e.idGenerator.Generate(elem.Node, input.FilePath)
// Check if element already has a data-content-id
existingID := e.getAttribute(elem.Node, "data-content-id")
var id string
var wasGenerated bool
if existingID != "" {
// Use existing ID from enhanced element
id = existingID
wasGenerated = false
} else {
// Generate new ID for unprocessed element
id = e.idGenerator.Generate(elem.Node, input.FilePath)
wasGenerated = true
}
generatedIDs[fmt.Sprintf("element_%d", i)] = id
processedElements[i] = ProcessedElement{
Node: elem.Node,
ID: id,
Type: elem.Type,
Generated: true,
Generated: wasGenerated,
Tag: elem.Node.Data,
Classes: GetClasses(elem.Node),
}
// Add content attributes to the node
// Add/update content attributes to the node
e.addContentAttributes(elem.Node, id, elem.Type)
}
@@ -133,6 +146,16 @@ func (e *ContentEngine) addContentAttributes(node *html.Node, contentID, content
e.setAttribute(node, "data-content-type", contentType)
}
// getAttribute gets an attribute value from an HTML node
func (e *ContentEngine) getAttribute(node *html.Node, key string) string {
for _, attr := range node.Attr {
if attr.Key == key {
return attr.Val
}
}
return ""
}
// setAttribute sets an attribute on an HTML node
func (e *ContentEngine) setAttribute(node *html.Node, key, value string) {
// Remove existing attribute if it exists