Skip to content

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

fix(browser): make downloaded files retrievable from the UI

Adam Eivycc29661f4813
diff --git a/client/src/pages/Browser.jsx b/client/src/pages/Browser.jsx
index f711f74774..6a34a27140 100644
--- a/client/src/pages/Browser.jsx
+++ b/client/src/pages/Browser.jsx
@@ -3,12 +3,13 @@ import {
Globe, Play, Square, RefreshCw, Settings, Activity,
Monitor, Wifi, WifiOff, Clock, Cpu, MemoryStick,
FileText, ChevronDown, ChevronRight, ExternalLink,
- Mail, MessageSquare, Download, FolderOpen
+ Mail, MessageSquare, Download, FolderOpen, Trash2
} from 'lucide-react';
import {
getBrowserStatus, getBrowserConfig, updateBrowserConfig,
launchBrowser, stopBrowser, restartBrowser,
- getBrowserLogs, navigateBrowser
+ getBrowserLogs, navigateBrowser,
+ browserDownloadUrl, deleteBrowserDownload
} from '../services/api';
import toast from '../components/ui/Toast';
import { formatBytes } from '../utils/formatters';
@@ -110,6 +111,19 @@ export default function BrowserPage() {
}
}, [configDraft]);
+ const handleDeleteDownload = useCallback(async (name) => {
+ const ok = await deleteBrowserDownload(name).then(() => true).catch(err => {
+ toast.error(`Failed to delete: ${err.message}`);
+ return false;
+ });
+ if (ok) {
+ setStatus(prev => ({
+ ...prev,
+ downloads: { ...prev.downloads, files: prev.downloads.files.filter(f => f.name !== name) }
+ }));
+ }
+ }, []);
+
const handleNavigate = useCallback(async () => {
const trimmed = navUrl.trim();
if (!trimmed) return;
@@ -525,12 +539,37 @@ export default function BrowserPage() {
<div className="divide-y divide-port-border">
{status.downloads.files.map(file => (
<div key={file.name} className="p-3 hover:bg-port-border/20 transition-colors">
- <div className="flex items-start justify-between gap-2">
- <div className="min-w-0">
- <div className="text-sm font-medium text-white truncate">{file.name}</div>
+ <div className="flex items-center justify-between gap-2">
+ <a
+ href={browserDownloadUrl(file.name)}
+ target="_blank"
+ rel="noreferrer"
+ className="min-w-0 flex-1 group"
+ title="Open in new tab"
+ >
+ <div className="text-sm font-medium text-white truncate group-hover:text-port-accent">
+ {file.name}
+ </div>
<div className="text-xs text-gray-500 mt-0.5">
{formatBytes(file.size)} &middot; {new Date(file.modified).toLocaleString()}
</div>
+ </a>
+ <div className="flex items-center gap-1 shrink-0">
+ <a
+ href={`${browserDownloadUrl(file.name)}?attachment=1`}
+ download={file.name}
+ className="p-1.5 rounded-md text-gray-400 hover:text-white hover:bg-port-border/50 transition-colors"
+ title="Save to device"
+ >
+ <Download size={16} />
+ </a>
+ <button
+ onClick={() => handleDeleteDownload(file.name)}
+ className="p-1.5 rounded-md text-gray-400 hover:text-port-error hover:bg-port-border/50 transition-colors"
+ title="Delete file"
+ >
+ <Trash2 size={16} />
+ </button>
</div>
</div>
</div>
diff --git a/client/src/services/apiSystem.js b/client/src/services/apiSystem.js
index 77d59f82f7..2867beb591 100644
--- a/client/src/services/apiSystem.js
+++ b/client/src/services/apiSystem.js
@@ -99,6 +99,10 @@ export const getBrowserPages = () => request('/browser/pages');
export const getBrowserVersion = () => request('/browser/version');
export const getBrowserLogs = (lines = 50) => request(`/browser/logs?lines=${lines}`);
export const getBrowserDownloads = () => request('/browser/downloads');
+export const deleteBrowserDownload = (name) =>
+ request(`/browser/downloads/${encodeURIComponent(name)}`, { method: 'DELETE' });
+export const browserDownloadUrl = (name) =>
+ `/api/browser/downloads/${encodeURIComponent(name)}`;
export const navigateBrowser = (url) => request('/browser/navigate', {
method: 'POST',
body: JSON.stringify({ url })
diff --git a/server/routes/browser.js b/server/routes/browser.js
index 220319e43c..e8a24166fb 100644
--- a/server/routes/browser.js
+++ b/server/routes/browser.js
@@ -111,4 +111,38 @@ router.get('/downloads', asyncHandler(async (req, res) => {
res.json(downloads);
}));
+// Extensions that could execute scripts when served inline at the same origin —
+// always force attachment to keep XSS via a downloaded asset off the table.
+const RISKY_DOWNLOAD_EXTS = new Set(['.html', '.htm', '.svg', '.js', '.mjs', '.xml']);
+
+// GET /api/browser/downloads/:name - Stream a downloaded file to the client.
+// Inline by default so previewable types (images, PDFs, videos) open in the
+// browser; the listing UI passes ?attachment=1 + HTML5 `download` for save-to-disk.
+router.get('/downloads/:name', asyncHandler(async (req, res) => {
+ const file = await browserService.resolveDownload(req.params.name);
+ if (!file) return res.status(404).json({ error: 'File not found' });
+ res.set('X-Content-Type-Options', 'nosniff');
+ // Files of the same name can be replaced by a fresh Chrome download; bypass
+ // any aggressive client/intermediary caching so the user always sees current.
+ res.set('Cache-Control', 'no-cache, must-revalidate');
+ const forceAttachment = RISKY_DOWNLOAD_EXTS.has(file.ext) || req.query.attachment === '1';
+ if (forceAttachment) {
+ // RFC 5987: ASCII-safe fallback + utf-8 form for non-ASCII names.
+ const ascii = file.name.replace(/[^\x20-\x7e]/g, '_').replace(/"/g, '');
+ res.set(
+ 'Content-Disposition',
+ `attachment; filename="${ascii}"; filename*=UTF-8''${encodeURIComponent(file.name)}`
+ );
+ }
+ res.type(file.mime).sendFile(file.absPath);
+}));
+
+// DELETE /api/browser/downloads/:name - Remove a downloaded file
+router.delete('/downloads/:name', asyncHandler(async (req, res) => {
+ const removed = await browserService.deleteDownload(req.params.name);
+ if (!removed) return res.status(404).json({ error: 'File not found' });
+ console.log(`🗑️ Browser download deleted: ${req.params.name}`);
+ res.json({ success: true });
+}));
+
export default router;
diff --git a/server/services/browserService.js b/server/services/browserService.js
index 3b3388d970..bf1e2d351e 100644
--- a/server/services/browserService.js
+++ b/server/services/browserService.js
@@ -4,10 +4,10 @@
* Stores config in data/browser-config.json
*/
-import { readFile, writeFile, readdir, stat } from 'fs/promises';
+import { readFile, writeFile, readdir, stat, unlink } from 'fs/promises';
import { execFile } from 'child_process';
import { promisify } from 'util';
-import { join } from 'path';
+import { join, basename, resolve, extname } from 'path';
import { EventEmitter } from 'events';
import { ensureDir, safeJSONParse, PATHS } from '../lib/fileUtils.js';
import { fetchWithTimeout } from '../lib/fetchWithTimeout.js';
@@ -303,6 +303,42 @@ export async function getDownloads() {
return { downloadDir, files };
}
+const DOWNLOAD_MIME_TYPES = {
+ '.txt': 'text/plain', '.md': 'text/markdown', '.json': 'application/json',
+ '.csv': 'text/csv', '.xml': 'application/xml', '.pdf': 'application/pdf',
+ '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
+ '.gif': 'image/gif', '.webp': 'image/webp', '.bmp': 'image/bmp',
+ '.mp3': 'audio/mpeg', '.wav': 'audio/wav', '.ogg': 'audio/ogg', '.m4a': 'audio/mp4',
+ '.mp4': 'video/mp4', '.webm': 'video/webm', '.mov': 'video/quicktime',
+ '.zip': 'application/zip', '.tar': 'application/x-tar', '.gz': 'application/gzip',
+ '.7z': 'application/x-7z-compressed'
+};
+
+export async function resolveDownload(name) {
+ const config = await loadConfig();
+ const downloadDir = resolve(config.downloadDir || DEFAULT_DOWNLOAD_DIR);
+ const safeName = basename(name || '');
+ if (!safeName || safeName.startsWith('.') || safeName.endsWith('.crdownload')) return null;
+ const absPath = resolve(downloadDir, safeName);
+ if (!absPath.startsWith(downloadDir + '/')) return null;
+ const info = await stat(absPath).catch(() => null);
+ if (!info?.isFile()) return null;
+ const ext = extname(safeName).toLowerCase();
+ return {
+ absPath,
+ name: safeName,
+ ext,
+ mime: DOWNLOAD_MIME_TYPES[ext] || 'application/octet-stream'
+ };
+}
+
+export async function deleteDownload(name) {
+ const file = await resolveDownload(name);
+ if (!file) return false;
+ await unlink(file.absPath);
+ return true;
+}
+
// ---------- Full combined status ----------
export async function getFullStatus() {