Refactor error handling and localDb structure, and fix usage tracking bug.

This commit is contained in:
decolua
2026-04-17 12:15:10 +07:00
parent 3badf1cbb6
commit 75ad0bef8e
13 changed files with 162 additions and 109 deletions
@@ -217,7 +217,7 @@ export default function ClaudeToolCard({
return [
{
filename: "~/.claude/settings.json",
content: JSON.stringify({ env }, null, 2),
content: JSON.stringify({ hasCompletedOnboarding: true, env }, null, 2),
},
];
};
@@ -226,8 +226,30 @@ export default function APIPageClient({ machineId }) {
setTunnelLoading(true);
setTunnelStatus(null);
setTunnelProgress("Creating tunnel...");
// Poll download progress while enable request is pending
let polling = true;
const pollProgress = async () => {
while (polling) {
try {
const r = await fetch("/api/tunnel/status");
if (r.ok) {
const s = await r.json();
if (s.download?.downloading) {
setTunnelProgress(`Downloading cloudflared... ${s.download.progress}%`);
} else if (polling) {
setTunnelProgress("Creating tunnel...");
}
}
} catch { /* ignore */ }
await new Promise((r) => setTimeout(r, 1000));
}
};
pollProgress();
try {
const res = await fetch("/api/tunnel/enable", { method: "POST" });
polling = false;
const data = await res.json();
if (!res.ok) {
setTunnelStatus({ type: "error", message: data.error || "Failed to enable tunnel" });
@@ -246,6 +268,7 @@ export default function APIPageClient({ machineId }) {
} catch (error) {
setTunnelStatus({ type: "error", message: error.message });
} finally {
polling = false;
setTunnelLoading(false);
setTunnelProgress("");
}
@@ -120,6 +120,7 @@ export async function POST(request) {
// Merge new env with existing settings
const newSettings = {
...currentSettings,
hasCompletedOnboarding: true,
env: {
...(currentSettings.env || {}),
...env,
+3 -1
View File
@@ -1,10 +1,12 @@
import { NextResponse } from "next/server";
import { getTunnelStatus, getTailscaleStatus } from "@/lib/tunnel/tunnelManager";
import { getDownloadStatus } from "@/lib/tunnel/cloudflared";
export async function GET() {
try {
const [tunnel, tailscale] = await Promise.all([getTunnelStatus(), getTailscaleStatus()]);
return NextResponse.json({ tunnel, tailscale });
const download = getDownloadStatus();
return NextResponse.json({ tunnel, tailscale, download });
} catch (error) {
console.error("Tunnel status error:", error);
return NextResponse.json({ error: error.message }, { status: 500 });