Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: add error handling and secure API endpoints for app actions
Adam Eivy03253fdc202f
diff --git a/client/src/pages/Apps.jsx b/client/src/pages/Apps.jsxindex 17dac99650..e50564170e 100644--- a/client/src/pages/Apps.jsx+++ b/client/src/pages/Apps.jsx@@ -297,19 +297,13 @@ export default function Apps() {{/* Quick Actions */}<div className="flex gap-2 pt-2"><button- onClick={() => {- const cmd = `cd "${app.repoPath}" && ${app.editorCommand || 'code .'}`;- api.executeCommand(cmd).catch(() => null);- }}+ onClick={() => api.openAppInEditor(app.id).catch(() => null)}className="px-3 py-1.5 bg-port-border hover:bg-port-border/80 text-white rounded-lg text-xs flex items-center gap-1"><Code size={14} /> Open in Editor</button><button- onClick={() => {- const cmd = `open "${app.repoPath}"`;- api.executeCommand(cmd).catch(() => null);- }}+ onClick={() => api.openAppFolder(app.id).catch(() => null)}className="px-3 py-1.5 bg-port-border hover:bg-port-border/80 text-white rounded-lg text-xs flex items-center gap-1"><FolderOpen size={14} /> Open Folderdiff --git a/client/src/pages/DevTools.jsx b/client/src/pages/DevTools.jsxindex 2355cf7f22..3347048daa 100644--- a/client/src/pages/DevTools.jsx+++ b/client/src/pages/DevTools.jsx@@ -439,17 +439,35 @@ export function RunnerPage() {const reader = new FileReader();reader.onload = async (ev) => {- const base64 = ev.target.result.split(',')[1];- const uploaded = await api.uploadScreenshot(base64, file.name, file.type).catch(() => null);+ const result = ev?.target?.result;+ if (typeof result !== 'string') {+ console.error('Failed to read file: unexpected FileReader result type');+ return;+ }++ const parts = result.split(',');+ if (parts.length < 2) {+ console.error('Failed to read file: unexpected data URL format');+ return;+ }++ const base64 = parts[1];+ const uploaded = await api.uploadScreenshot(base64, file.name, file.type).catch((err) => {+ console.error('Failed to upload screenshot', err);+ return null;+ });if (uploaded) {setScreenshots(prev => [...prev, {id: uploaded.id,filename: uploaded.filename,- preview: ev.target.result,+ preview: result,path: uploaded.path}]);}};+ reader.onerror = (err) => {+ console.error('FileReader failed to read file', err);+ };reader.readAsDataURL(file);}e.target.value = '';diff --git a/client/src/services/api.js b/client/src/services/api.jsindex 79f78c13f4..c88362e1fc 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -45,6 +45,8 @@ export const deleteApp = (id) => request(`/apps/${id}`, { method: 'DELETE' });export const startApp = (id) => request(`/apps/${id}/start`, { method: 'POST' });export const stopApp = (id) => request(`/apps/${id}/stop`, { method: 'POST' });export const restartApp = (id) => request(`/apps/${id}/restart`, { method: 'POST' });+export const openAppInEditor = (id) => request(`/apps/${id}/open-editor`, { method: 'POST' });+export const openAppFolder = (id) => request(`/apps/${id}/open-folder`, { method: 'POST' });export const getAppStatus = (id) => request(`/apps/${id}/status`);export const getAppLogs = (id, lines = 100, processName) => {const params = new URLSearchParams({ lines: String(lines) });diff --git a/server/routes/apps.js b/server/routes/apps.jsindex 2d047c9a04..caf875bd2a 100644--- a/server/routes/apps.js+++ b/server/routes/apps.js@@ -1,4 +1,6 @@import { Router } from 'express';+import { spawn } from 'child_process';+import { existsSync } from 'fs';import * as appsService from '../services/apps.js';import * as pm2Service from '../services/pm2.js';import { logAction } from '../services/history.js';@@ -223,4 +225,66 @@ router.get('/:id/logs', async (req, res, next) => {res.json({ processName, lines, logs });});+// POST /api/apps/:id/open-editor - Open app in editor+router.post('/:id/open-editor', async (req, res, next) => {+ const app = await appsService.getAppById(req.params.id);++ if (!app) {+ return res.status(404).json({ error: 'App not found', code: 'NOT_FOUND' });+ }++ if (!existsSync(app.repoPath)) {+ return res.status(400).json({ error: 'App path does not exist', code: 'PATH_NOT_FOUND' });+ }++ const editorCommand = app.editorCommand || 'code .';+ const [cmd, ...args] = editorCommand.split(/\s+/);++ // Spawn the editor process detached so it doesn't block+ const child = spawn(cmd, args, {+ cwd: app.repoPath,+ detached: true,+ stdio: 'ignore'+ });+ child.unref();++ res.json({ success: true, command: editorCommand, path: app.repoPath });+});++// POST /api/apps/:id/open-folder - Open app folder in file manager+router.post('/:id/open-folder', async (req, res, next) => {+ const app = await appsService.getAppById(req.params.id);++ if (!app) {+ return res.status(404).json({ error: 'App not found', code: 'NOT_FOUND' });+ }++ if (!existsSync(app.repoPath)) {+ return res.status(400).json({ error: 'App path does not exist', code: 'PATH_NOT_FOUND' });+ }++ // Cross-platform folder open command+ const platform = process.platform;+ let cmd, args;++ if (platform === 'darwin') {+ cmd = 'open';+ args = [app.repoPath];+ } else if (platform === 'win32') {+ cmd = 'explorer';+ args = [app.repoPath];+ } else {+ cmd = 'xdg-open';+ args = [app.repoPath];+ }++ const child = spawn(cmd, args, {+ detached: true,+ stdio: 'ignore'+ });+ child.unref();++ res.json({ success: true, path: app.repoPath });+});+export default router;