Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: attach structured reports to desktop support uploads

Richie McIlroy990e4f10b1a3
diff --git a/apps/web/app/api/desktop/[...route]/root.ts b/apps/web/app/api/desktop/[...route]/root.ts
index 9c14a656c..7ae82cb19 100644
--- a/apps/web/app/api/desktop/[...route]/root.ts
+++ b/apps/web/app/api/desktop/[...route]/root.ts
@@ -24,6 +24,10 @@ import { Effect, Option } from "effect";
import { type Context, Hono } from "hono";
import type Stripe from "stripe";
import { z } from "zod";
+import {
+ confirmedDesktopLogWebhookUrl,
+ createDesktopLogUpload,
+} from "@/lib/desktop-log-upload";
import { getCheckoutRedirectUrls } from "@/lib/mobile-checkout";
import { runPromise } from "@/lib/server";
import { trackServerEvent } from "@/lib/server-analytics";
@@ -178,156 +182,6 @@ async function applyOrganizationLogoUpdate(
}).pipe(runPromise);
}
-const diagnosticsSchema = z.object({
- system: z
- .object({
- windowsVersion: z
- .object({
- displayName: z.string(),
- meetsRequirements: z.boolean().optional(),
- isWindows11: z.boolean().optional(),
- })
- .optional(),
- macosVersion: z.object({ displayName: z.string() }).optional(),
- linuxVersion: z.object({ displayName: z.string() }).optional(),
- gpuInfo: z
- .object({
- vendor: z.string(),
- description: z.string(),
- dedicatedVideoMemoryMb: z.number().optional(),
- isSoftwareAdapter: z.boolean().optional(),
- isBasicRenderDriver: z.boolean().optional(),
- supportsHardwareEncoding: z.boolean().optional(),
- })
- .optional(),
- allGpus: z
- .object({
- gpus: z.array(
- z.object({
- vendor: z.string(),
- description: z.string(),
- dedicatedVideoMemoryMb: z.number().optional(),
- }),
- ),
- isMultiGpuSystem: z.boolean().optional(),
- hasDiscreteGpu: z.boolean().optional(),
- })
- .optional(),
- renderingStatus: z
- .object({
- isUsingSoftwareRendering: z.boolean().optional(),
- isUsingBasicRenderDriver: z.boolean().optional(),
- hardwareEncodingAvailable: z.boolean().optional(),
- warningMessage: z.string().optional(),
- })
- .optional(),
- availableEncoders: z.array(z.string()).optional(),
- graphicsCaptureSupported: z.boolean().optional(),
- screenCaptureSupported: z.boolean().optional(),
- d3D11VideoProcessorAvailable: z.boolean().optional(),
- })
- .optional(),
- cameras: z.array(z.string()).optional(),
- microphones: z.array(z.string()).optional(),
- permissions: z
- .object({
- screenRecording: z.string().optional(),
- camera: z.string().optional(),
- microphone: z.string().optional(),
- })
- .optional(),
-});
-
-function formatDiagnosticsForDiscord(
- diagnostics: z.infer<typeof diagnosticsSchema>,
-): string {
- const lines: string[] = [];
- const sys = diagnostics.system;
-
- if (sys?.windowsVersion?.displayName) {
- lines.push(`**OS:** ${sys.windowsVersion.displayName}`);
- } else if (sys?.macosVersion?.displayName) {
- lines.push(`**OS:** ${sys.macosVersion.displayName}`);
- } else if (sys?.linuxVersion?.displayName) {
- lines.push(`**OS:** ${sys.linuxVersion.displayName}`);
- }
-
- if (sys?.gpuInfo) {
- const gpu = sys.gpuInfo;
- let gpuLine = `**GPU:** ${gpu.description}`;
- if (gpu.vendor) gpuLine += ` (${gpu.vendor})`;
- if (gpu.dedicatedVideoMemoryMb)
- gpuLine += ` - ${gpu.dedicatedVideoMemoryMb}MB VRAM`;
- lines.push(gpuLine);
-
- const flags: string[] = [];
- if (gpu.isSoftwareAdapter) flags.push("⚠️ Software Adapter");
- if (gpu.isBasicRenderDriver) flags.push("⚠️ Basic Render Driver");
- if (gpu.supportsHardwareEncoding === false) flags.push("❌ No HW Encoding");
- if (gpu.supportsHardwareEncoding === true) flags.push("✅ HW Encoding");
- if (flags.length > 0) lines.push(`**GPU Status:** ${flags.join(", ")}`);
- }
-
- if (sys?.allGpus?.gpus && sys.allGpus.gpus.length > 1) {
- const gpuList = sys.allGpus.gpus
- .map((g) => `${g.description} (${g.vendor})`)
- .join(", ");
- lines.push(`**All GPUs:** ${gpuList}`);
- }
-
- if (sys?.renderingStatus?.warningMessage) {
- lines.push(`**⚠️ Warning:** ${sys.renderingStatus.warningMessage}`);
- }
-
- const captureSupported =
- sys?.graphicsCaptureSupported ?? sys?.screenCaptureSupported;
- if (captureSupported !== undefined) {
- lines.push(
- `**Screen Capture:** ${captureSupported ? "✅ Supported" : "❌ Not Supported"}`,
- );
- }
-
- if (sys?.d3D11VideoProcessorAvailable !== undefined) {
- lines.push(
- `**D3D11 Video Processor:** ${sys.d3D11VideoProcessorAvailable ? "✅" : "❌"}`,
- );
- }
-
- if (sys?.availableEncoders && sys.availableEncoders.length > 0) {
- lines.push(`**Encoders:** ${sys.availableEncoders.join(", ")}`);
- }
-
- if (diagnostics.permissions) {
- const perms = diagnostics.permissions;
- const permList = [
- perms.screenRecording && `Screen: ${perms.screenRecording}`,
- perms.camera && `Camera: ${perms.camera}`,
- perms.microphone && `Mic: ${perms.microphone}`,
- ]
- .filter(Boolean)
- .join(", ");
- if (permList) lines.push(`**Permissions:** ${permList}`);
- }
-
- if (diagnostics.cameras && diagnostics.cameras.length > 0) {
- lines.push(
- `**Cameras (${diagnostics.cameras.length}):** ${diagnostics.cameras.join(", ")}`,
- );
- } else {
- lines.push("**Cameras:** None detected");
- }
-
- if (diagnostics.microphones && diagnostics.microphones.length > 0) {
- lines.push(
- `**Mics (${diagnostics.microphones.length}):** ${diagnostics.microphones.join(", ")}`,
- );
- } else {
- lines.push("**Mics:** None detected");
- }
-
- return lines.join("\n");
-}
-
app.post(
"/logs",
zValidator(
@@ -337,6 +191,8 @@ app.post(
os: z.string().optional(),
version: z.string().optional(),
diagnostics: z.string().optional(),
+ report: z.string().optional(),
+ context: z.string().optional(),
}),
),
withOptionalAuth,
@@ -346,6 +202,8 @@ app.post(
os,
version,
diagnostics: diagnosticsJson,
+ report,
+ context,
} = c.req.valid("form");
const user = c.get("user");
@@ -354,43 +212,24 @@ app.post(
if (!discordWebhookUrl)
throw new Error("Discord webhook URL is not configured");
- const formData = new FormData();
- const logBlob = new Blob([log], { type: "text/plain" });
- const fileName = `cap-desktop-${os || "unknown"}-${version || "unknown"}-${Date.now()}.log`;
- formData.append("file", logBlob, fileName);
-
- let diagnosticsContent = "";
- if (diagnosticsJson) {
- try {
- const parsed = JSON.parse(diagnosticsJson);
- const validated = diagnosticsSchema.safeParse(parsed);
- if (validated.success) {
- diagnosticsContent = formatDiagnosticsForDiscord(validated.data);
- }
- } catch {
- diagnosticsContent = "";
- }
- }
-
- const content = [
- "📋 **New Log File Uploaded**",
- "",
- user ? `**User:** ${user.email} (${user.id})` : null,
- os ? `**Platform:** ${os}` : null,
- version ? `**App Version:** ${version}` : null,
- diagnosticsContent ? "" : null,
- diagnosticsContent || null,
- ]
- .filter((line): line is string => line !== null)
- .join("\n");
-
- formData.append("content", content);
-
- const response = await fetch(discordWebhookUrl, {
- method: "POST",
- body: formData,
+ const formData = createDesktopLogUpload({
+ log,
+ os,
+ version,
+ diagnostics: diagnosticsJson,
+ report,
+ context,
+ user: user ? { email: user.email, id: user.id } : undefined,
});
+ const response = await fetch(
+ confirmedDesktopLogWebhookUrl(discordWebhookUrl),
+ {
+ method: "POST",
+ body: formData,
+ },
+ );
+
if (!response.ok)
throw new Error(
`Failed to send logs to Discord: ${response.statusText}`,