Major codebase cleanup after .insertr-add functionality overhaul

Consolidates duplicate code and removes technical debt accumulated during rapid development. This cleanup improves maintainability while preserving all functionality.

Backend cleanup:
- Remove unused legacy function findViableChildrenLegacy()
- Consolidate duplicate SQL null string helper functions into shared utils
- Unify text extraction functions across utils, engine, and id_generator
- Consolidate duplicate attribute getter functions into single implementation

Frontend cleanup:
- Remove duplicate authentication methods (authenticateWithOAuth vs performOAuthFlow)
- Remove unused hasPermission() method from auth.js
- Centralize repetitive API endpoint construction in api-client.js
- Reduce excessive console logging while preserving important error logs

Impact: -144 lines of code, improved maintainability, no functionality changes
All tests pass and builds succeed

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-23 19:00:41 +02:00
parent 1ae4176f23
commit 3e5cb76d1d
8 changed files with 71 additions and 215 deletions

View File

@@ -12,11 +12,18 @@ export class ApiClient {
this.baseUrl = options.apiEndpoint || defaultEndpoint;
this.siteId = options.siteId || this.handleMissingSiteId();
// Log API configuration in development
// Log API configuration in development (keep for debugging)
if (isDevelopment && !options.apiEndpoint) {
console.log(`🔌 API Client: Using development server at ${this.baseUrl}`);
}
}
/**
* Get collections API URL (helper to avoid repetition)
*/
getCollectionsUrl() {
return this.baseUrl.replace('/api/content', '/api/collections');
}
async getContent(contentId) {
try {
@@ -48,7 +55,6 @@ export class ApiClient {
if (response.ok) {
const result = await response.json();
console.log(`✅ Content created: ${result.id}`);
return result;
} else {
console.warn(`⚠️ Create failed (${response.status}): server will generate ID`);
@@ -82,7 +88,6 @@ export class ApiClient {
if (response.ok) {
const result = await response.json();
console.log(`✅ Content updated: ${contentId}`);
return result;
} else {
console.warn(`⚠️ Update failed (${response.status}): ${contentId}`);
@@ -154,7 +159,7 @@ export class ApiClient {
*/
async createCollectionItem(collectionId, templateId = 1, htmlContent = '') {
try {
const collectionsUrl = this.baseUrl.replace('/api/content', '/api/collections');
const collectionsUrl = this.getCollectionsUrl();
const payload = {
site_id: this.siteId,
template_id: templateId,
@@ -172,7 +177,6 @@ export class ApiClient {
if (response.ok) {
const result = await response.json();
console.log(`✅ Collection item created: ${result.item_id}`);
return result;
} else {
const errorText = await response.text();
@@ -193,7 +197,7 @@ export class ApiClient {
*/
async deleteCollectionItem(collectionId, itemId) {
try {
const collectionsUrl = this.baseUrl.replace('/api/content', '/api/collections');
const collectionsUrl = this.getCollectionsUrl();
const response = await fetch(`${collectionsUrl}/${collectionId}/items/${itemId}?site_id=${this.siteId}`, {
method: 'DELETE',
@@ -203,7 +207,6 @@ export class ApiClient {
});
if (response.ok) {
console.log(`✅ Collection item deleted: ${itemId}`);
return true;
} else {
const errorText = await response.text();
@@ -223,7 +226,7 @@ export class ApiClient {
*/
async getCollectionItems(collectionId) {
try {
const collectionsUrl = this.baseUrl.replace('/api/content', '/api/collections');
const collectionsUrl = this.getCollectionsUrl();
const response = await fetch(`${collectionsUrl}/${collectionId}/items?site_id=${this.siteId}`);
if (response.ok) {
@@ -248,7 +251,7 @@ export class ApiClient {
*/
async updateCollectionItemPosition(collectionId, itemId, newPosition) {
try {
const collectionsUrl = this.baseUrl.replace('/api/content', '/api/collections');
const collectionsUrl = this.getCollectionsUrl();
const payload = {
site_id: this.siteId,
position: newPosition
@@ -264,7 +267,6 @@ export class ApiClient {
});
if (response.ok) {
console.log(`✅ Collection item position updated: ${itemId} → position ${newPosition}`);
return true;
} else {
const errorText = await response.text();

View File

@@ -411,51 +411,7 @@ export class InsertrAuth {
return this.state.currentUser;
}
/**
* OAuth integration placeholder
* In production, this would handle real OAuth flows
*/
async authenticateWithOAuth(provider = 'google') {
// Mock OAuth flow for now
console.log(`🔐 Mock OAuth login with ${provider}`);
// Simulate OAuth callback
setTimeout(() => {
this.state.isAuthenticated = true;
this.state.currentUser = {
name: 'OAuth User',
email: 'user@example.com',
provider: provider,
role: 'editor'
};
this.emitStateChange();
console.log('✅ OAuth authentication successful');
}, 1000);
}
/**
* Validate if user has permission for specific action
*/
hasPermission(action) {
if (!this.isAuthenticated()) return false;
const user = this.getCurrentUser();
if (!user) return false;
// Simple role-based permissions
switch (action) {
case 'edit':
return ['admin', 'editor'].includes(user.role);
case 'enhance':
return ['admin'].includes(user.role);
case 'manage':
return user.role === 'admin';
default:
return false;
}
}
/**
* Get authentication state snapshot