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

@@ -29,24 +29,15 @@ export class ApiClient {
}
async createContent(contentId, content, type, htmlMarkup = null) {
async createContent(content, type, htmlMarkup) {
try {
const payload = {
html_markup: htmlMarkup, // Always send HTML markup - server extracts ID or generates new one
value: content,
type: type,
file_path: this.getCurrentFilePath() // Always include file path for consistent ID generation
};
if (contentId) {
// Enhanced site - provide existing ID
payload.id = contentId;
} else if (htmlMarkup) {
// Non-enhanced site - provide HTML markup for unified engine ID generation
payload.html_markup = htmlMarkup;
} else {
throw new Error('Either contentId or htmlMarkup must be provided');
}
const response = await fetch(`${this.baseUrl}?site_id=${this.siteId}`, {
method: 'POST',
headers: {
@@ -61,7 +52,7 @@ export class ApiClient {
console.log(`✅ Content created: ${result.id} (${result.type})`);
return result;
} else {
console.warn(`⚠️ Create failed (${response.status}): ${contentId || 'backend-generated'}`);
console.warn(`⚠️ Create failed (${response.status}): server will generate ID`);
return null;
}
} catch (error) {
@@ -69,7 +60,7 @@ export class ApiClient {
console.warn(`🔌 API Server not reachable at ${this.baseUrl}`);
console.warn('💡 Start full-stack development: just dev');
} else {
console.error('Failed to create content:', contentId, error);
console.error('Failed to create content:', error);
}
return false;
}