From 74a54e4b5e3e0f55d2bab15897496da6f759b17b Mon Sep 17 00:00:00 2001 From: Joakim Date: Thu, 11 Sep 2025 14:16:17 +0200 Subject: [PATCH] feat: add restore command integration and development workflow improvements - Add restore command to CLI root (cmd/root.go) - Add restore-clean justfile target for development workflow - Update justfile clean command to remove backups - Improve auth UI status display and enhance button visibility - Clean up auth.js formatting and enhance button management --- cmd/root.go | 1 + justfile | 11 ++++++-- lib/src/core/auth.js | 62 ++++++++++++++++++++------------------------ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 7913104..36a1dbd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -52,6 +52,7 @@ func init() { rootCmd.AddCommand(enhanceCmd) rootCmd.AddCommand(serveCmd) + rootCmd.AddCommand(restoreCmd) } func initConfig() { diff --git a/justfile b/justfile index aad35a7..747f831 100644 --- a/justfile +++ b/justfile @@ -135,7 +135,7 @@ health port="8080": @echo "๐Ÿ” Checking API server health..." @curl -s http://localhost:{{port}}/health | jq . || echo "โŒ Server not responding at localhost:{{port}}" -# Clean all build artifacts +# Clean all build artifacts and backups clean: rm -rf lib/dist rm -rf insertr @@ -145,6 +145,12 @@ clean: rm -rf lib/node_modules rm -f dev.db rm -f insertr.db + @echo "๐Ÿงน Cleaned all build artifacts and backups" + +# Restore demo site to clean original state +restore-clean: + @echo "๐Ÿงน Restoring demo site to clean state..." + ./insertr restore demo --clean # Lint code (placeholder for now) lint: @@ -180,7 +186,8 @@ status: @echo " just enhance - Build-time content injection" @echo "" @echo "๐Ÿ” Check server: just health" + @echo "๐Ÿงน Restore clean: just restore-clean" # Generate sqlc code (for database schema changes) sqlc: - sqlc generate \ No newline at end of file + sqlc generate diff --git a/lib/src/core/auth.js b/lib/src/core/auth.js index 037800c..da776e5 100644 --- a/lib/src/core/auth.js +++ b/lib/src/core/auth.js @@ -235,6 +235,8 @@ export class InsertrAuth { if (editToggle) { editToggle.addEventListener('click', () => this.toggleEditMode()); } + + } /** @@ -313,6 +315,9 @@ export class InsertrAuth { editBtn.textContent = `Edit Mode: ${this.state.editMode ? 'On' : 'Off'}`; editBtn.className = `insertr-auth-btn ${this.state.editMode ? 'insertr-edit-active' : ''}`; } + + // Update enhance button visibility + this.updateEnhanceButtonVisibility(); } /** @@ -325,14 +330,14 @@ export class InsertrAuth { } const statusHtml = ` -
-
- Visitor Mode - +
+
+
+ Visitor Mode + +
- +
`; @@ -362,8 +367,7 @@ export class InsertrAuth { statusDot.className = 'insertr-status-dot insertr-status-authenticated'; } - // Update enhance button visibility - this.updateEnhanceButtonVisibility(); + } /** @@ -405,28 +409,6 @@ export class InsertrAuth { body.insertr-hide-gates .insertr-gate { display: none !important; } - - /* Enhance button styles */ - .insertr-enhance-btn { - background: #2563eb; - color: white; - border: none; - padding: 4px 8px; - border-radius: 4px; - font-size: 11px; - margin-left: 8px; - cursor: pointer; - transition: background 0.2s ease; - } - - .insertr-enhance-btn:hover { - background: #1d4ed8; - } - - .insertr-enhance-btn:disabled { - background: #9ca3af; - cursor: not-allowed; - } `; const styleSheet = document.createElement('style'); @@ -486,17 +468,23 @@ export class InsertrAuth { background: #b91c1c; } - .insertr-status { + .insertr-status-controls { position: fixed; bottom: 20px; left: 20px; z-index: 9999; + display: flex; + flex-direction: column; + gap: 8px; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; + } + + .insertr-status { background: white; border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 200px; } @@ -631,8 +619,14 @@ export class InsertrAuth { enhanceBtn.textContent = 'โณ Enhancing...'; enhanceBtn.disabled = true; + // Smart server detection for enhance API (same logic as ApiClient) + const isDevelopment = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'; + const enhanceUrl = isDevelopment + ? `http://localhost:8080/api/enhance?site_id=${siteId}` // Development: separate API server + : `/api/enhance?site_id=${siteId}`; // Production: same-origin API + // Call enhance API - const response = await fetch(`/api/enhance?site_id=${siteId}`, { + const response = await fetch(enhanceUrl, { method: 'POST', headers: { 'Content-Type': 'application/json',