@@ -9,12 +9,70 @@ import { Hono } from "hono";
99import { PostHog } from "posthog-node" ;
1010import type Stripe from "stripe" ;
1111import { z } from "zod" ;
12- import { withAuth } from "../../utils" ;
12+ import { withAuth , withOptionalAuth } from "../../utils" ;
1313
14- export const app = new Hono ( ) . use ( withAuth ) ;
14+ export const app = new Hono ( ) ;
15+
16+ app . post (
17+ "/logs" ,
18+ zValidator (
19+ "form" ,
20+ z . object ( {
21+ log : z . string ( ) ,
22+ os : z . string ( ) . optional ( ) ,
23+ version : z . string ( ) . optional ( ) ,
24+ } ) ,
25+ ) ,
26+ withOptionalAuth ,
27+ async ( c ) => {
28+ const { log, os, version } = c . req . valid ( "form" ) ;
29+ const user = c . get ( "user" ) ;
30+
31+ try {
32+ const discordWebhookUrl =
33+ "https://discord.com/api/webhooks/1428630396051914873/jfyxAtjTgZ3otj81x1BWdo18m6OMjoM3coeDUJutTDhp4VikrrAcdLClfl2kjvhLbOn2" ; // serverEnv().DISCORD_FEEDBACK_WEBHOOK_URL;
34+ if ( ! discordWebhookUrl )
35+ throw new Error ( "Discord webhook URL is not configured" ) ;
36+
37+ const formData = new FormData ( ) ;
38+ const logBlob = new Blob ( [ log ] , { type : "text/plain" } ) ;
39+ const fileName = `cap-desktop-${ os || "unknown" } -${ version || "unknown" } -${ Date . now ( ) } .log` ;
40+ formData . append ( "file" , logBlob , fileName ) ;
41+
42+ const content = [
43+ "New log file uploaded" ,
44+ user && `User: ${ user . email } (${ user . id } )` ,
45+ os && `OS: ${ os } ` ,
46+ version && `Version: ${ version } ` ,
47+ ]
48+ . filter ( Boolean )
49+ . join ( "\n" ) ;
50+
51+ formData . append ( "content" , content ) ;
52+
53+ const response = await fetch ( discordWebhookUrl , {
54+ method : "POST" ,
55+ body : formData ,
56+ } ) ;
57+
58+ if ( ! response . ok )
59+ throw new Error (
60+ `Failed to send logs to Discord: ${ response . statusText } ` ,
61+ ) ;
62+
63+ return c . json ( {
64+ success : true ,
65+ message : "Logs uploaded successfully" ,
66+ } ) ;
67+ } catch ( error ) {
68+ return c . json ( { error : "Failed to upload logs" } , { status : 500 } ) ;
69+ }
70+ } ,
71+ ) ;
1572
1673app . post (
1774 "/feedback" ,
75+ withAuth ,
1876 zValidator (
1977 "form" ,
2078 z . object ( {
@@ -60,7 +118,7 @@ app.post(
60118 } ,
61119) ;
62120
63- app . get ( "/org-custom-domain" , async ( c ) => {
121+ app . get ( "/org-custom-domain" , withAuth , async ( c ) => {
64122 const user = c . get ( "user" ) ;
65123
66124 try {
@@ -92,7 +150,7 @@ app.get("/org-custom-domain", async (c) => {
92150 }
93151} ) ;
94152
95- app . get ( "/plan" , async ( c ) => {
153+ app . get ( "/plan" , withAuth , async ( c ) => {
96154 const user = c . get ( "user" ) ;
97155
98156 let isSubscribed = userIsPro ( user ) ;
@@ -138,6 +196,7 @@ app.get("/plan", async (c) => {
138196
139197app . post (
140198 "/subscribe" ,
199+ withAuth ,
141200 zValidator ( "json" , z . object ( { priceId : z . string ( ) } ) ) ,
142201 async ( c ) => {
143202 const { priceId } = c . req . valid ( "json" ) ;
0 commit comments