Skip to content

Commit fd9a4f6

Browse files
cleaned up messy code
1 parent 132ef55 commit fd9a4f6

File tree

24 files changed

+199
-232
lines changed

24 files changed

+199
-232
lines changed

app/api/ai/enhance-text/route.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function POST(req: NextRequest) {
3131
try {
3232
console.log(`[Enhance Text API ${requestId}] Processing request`)
3333

34-
// Parse and validate request body
34+
3535
let body: any
3636
try {
3737
body = await req.json()
@@ -51,7 +51,7 @@ export async function POST(req: NextRequest) {
5151

5252
const { textToEnhance } = body
5353

54-
// Get user authentication
54+
5555
const cookieStore = cookies()
5656
const supabase = createServerClient(
5757
process.env.NEXT_PUBLIC_SUPABASE_URL!,
@@ -88,7 +88,7 @@ export async function POST(req: NextRequest) {
8888
)
8989
}
9090

91-
// Apply rate limiting
91+
9292
try {
9393
const limit = rateLimitMaxRequests
9494
? await ratelimit(req.headers.get("x-forwarded-for"), rateLimitMaxRequests, ratelimitWindow)
@@ -115,10 +115,10 @@ export async function POST(req: NextRequest) {
115115
}
116116
} catch (error) {
117117
logError("Rate limiting check failed", error, { requestId })
118-
// Continue without rate limiting if it fails
118+
119119
}
120120

121-
// Get default model for enhancement
121+
122122
const defaultModel = modelsList.models.find(m => m.providerId === "openai" && m.id === "gpt-4o") ||
123123
modelsList.models.find(m => m.providerId === "anthropic" && m.id === "claude-3-5-sonnet-20241022") ||
124124
modelsList.models[0]
@@ -239,4 +239,4 @@ Make it more clear, engaging, and well-structured while keeping the same general
239239
{ status: 500 }
240240
)
241241
}
242-
}
242+
}

app/api/chat/route.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Duration } from "@/lib/duration"
22
import type { LLMModel, LLMModelConfig } from "@/lib/models"
3-
import { getModelClient } from "@/lib/models" // Assuming getModelClient is a named export
3+
import { getModelClient } from "@/lib/models"
44
import { toEnhancedPrompt } from "@/lib/enhanced-prompt"
55
import ratelimit from "@/lib/ratelimit"
66
import { fragmentSchema as schema } from "@/lib/schema"
@@ -22,7 +22,7 @@ export async function POST(req: Request) {
2222
try {
2323
console.log(`[Chat API ${requestId}] Processing request`)
2424

25-
// Parse request body with enhanced error handling
25+
2626
let body: any
2727
try {
2828
body = await req.json()
@@ -62,7 +62,7 @@ export async function POST(req: Request) {
6262
analysisInstructions?: string
6363
} = body
6464

65-
// Enhanced validation with better error messages
65+
6666
const validation = validateRequestData(body)
6767
if (!validation.valid) {
6868
logError("Request validation failed", new Error(validation.errors.join(", ")), { requestId, errors: validation.errors })
@@ -97,7 +97,7 @@ export async function POST(req: Request) {
9797
}
9898
}
9999

100-
// Rate limiting check
100+
101101
try {
102102
const limit = !config.apiKey
103103
? await ratelimit(req.headers.get("x-forwarded-for"), rateLimitMaxRequests, ratelimitWindow)
@@ -150,7 +150,7 @@ export async function POST(req: Request) {
150150
)
151151
}
152152

153-
// Extract user prompt from the last message
153+
154154
const lastMessage = messages[messages.length - 1]
155155
let userPrompt = ''
156156
if (Array.isArray(lastMessage?.content)) {
@@ -216,7 +216,7 @@ export async function POST(req: Request) {
216216
hasProjectContext: !!projectStructure
217217
})
218218

219-
// Enhanced error categorization
219+
220220
const errorMessage = error.message || "Unknown error"
221221

222222
if (errorMessage.includes("API key") || errorMessage.includes("authentication") || error.status === 401) {
@@ -322,4 +322,4 @@ IMPORTANT GUIDELINES:
322322
- Include proper security measures
323323
324324
Generate complete, functional code that fulfills the user's request.`
325-
}
325+
}

app/api/figma/analyze/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export async function POST(request: NextRequest) {
99
const body = await request.json()
1010
const { figmaUrl } = body
1111

12-
// Enhanced validation
12+
1313
if (!figmaUrl || typeof figmaUrl !== 'string') {
1414
return NextResponse.json(
1515
{
@@ -50,7 +50,7 @@ export async function POST(request: NextRequest) {
5050
)
5151
}
5252

53-
// Check if API key is available
53+
5454
if (!process.env.FIGMA_API_KEY) {
5555
return NextResponse.json(
5656
{
@@ -82,7 +82,7 @@ export async function POST(request: NextRequest) {
8282
const analysis = figmaIntegration.analyzeDesign(figmaFile)
8383
const designTokens = figmaIntegration.extractDesignTokens(figmaFile)
8484

85-
// Get main frame IDs for potential image export
85+
8686
const mainFrames =
8787
figmaFile.document.children
8888
?.filter((child) => child.type === "FRAME" && child.name !== "Cover")
@@ -108,7 +108,7 @@ export async function POST(request: NextRequest) {
108108
} catch (error) {
109109
console.error(`[Figma Analysis API ${requestId}] Analysis failed:`, error)
110110

111-
// Enhanced error handling with specific status codes
111+
112112
let errorMessage = "Failed to analyze Figma design"
113113
let statusCode = 500
114114
let errorCode = "ANALYSIS_ERROR"

app/api/github/auth/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function POST(request: NextRequest) {
1515
)
1616
}
1717

18-
// Exchange code for access token
18+
1919
const tokenResponse = await fetch('https://github.com/login/oauth/access_token', {
2020
method: 'POST',
2121
headers: {
@@ -74,7 +74,7 @@ export async function POST(request: NextRequest) {
7474
)
7575
}
7676

77-
// Store GitHub token in user metadata
77+
7878
const { error: updateError } = await supabase.auth.updateUser({
7979
data: {
8080
github_access_token: tokenData.access_token,

app/api/github/callback/route.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export async function GET(request: NextRequest) {
55
const code = url.searchParams.get('code')
66
const error = url.searchParams.get('error')
77
const errorDescription = url.searchParams.get('error_description')
8-
const state = url.searchParams.get('state') // GitHub returns state here
8+
const state = url.searchParams.get('state')
99

1010
const html = `
1111
<!DOCTYPE html>
@@ -16,30 +16,30 @@ export async function GET(request: NextRequest) {
1616
<body>
1717
<script>
1818
if (window.opener) {
19-
if (${error ? `true` : `false`}) { // Check if error exists
19+
if (${error ? `true` : `false`}) {
2020
window.opener.postMessage({
2121
type: 'GITHUB_AUTH_ERROR',
2222
error: '${error}',
2323
errorDescription: '${errorDescription}'
2424
}, '*');
25-
} else if (${code ? `true` : `false`}) { // Check if code exists
26-
// Send code and state to parent window
25+
} else if (${code ? `true` : `false`}) {
26+
2727
window.opener.postMessage({
28-
type: 'GITHUB_AUTH_CALLBACK', // New message type
28+
type: 'GITHUB_AUTH_CALLBACK',
2929
code: '${code}',
3030
state: '${state}'
3131
}, '*');
3232
} else {
33-
// Fallback error if neither code nor error is present
33+
3434
window.opener.postMessage({
3535
type: 'GITHUB_AUTH_ERROR',
3636
error: 'unknown_error',
3737
errorDescription: 'No authorization code or error returned from GitHub.'
3838
}, '*');
3939
}
4040
}
41-
// Always close the window after attempting to post message
42-
// Give a slight delay for the message to be potentially processed
41+
42+
4343
setTimeout(() => { window.close(); }, 500);
4444
</script>
4545
<p>Processing GitHub authentication...</p>

app/api/github/contents/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { NextRequest, NextResponse } from 'next/server'
22
import { cookies } from 'next/headers'
33
import { GitHubIntegration } from '@/lib/github-integration'
44

5-
// Handler for creating or updating a file
5+
66
export async function PUT(req: NextRequest) {
77
try {
8-
const cookieStore = await cookies() // Added await
8+
const cookieStore = await cookies()
99
const githubToken = cookieStore.get('github_token')?.value
1010

1111
if (!githubToken) {
@@ -32,10 +32,10 @@ export async function PUT(req: NextRequest) {
3232
}
3333
}
3434

35-
// Handler for deleting a file
35+
3636
export async function DELETE(req: NextRequest) {
3737
try {
38-
const cookieStore = await cookies() // Added await
38+
const cookieStore = await cookies()
3939
const githubToken = cookieStore.get('github_token')?.value
4040

4141
if (!githubToken) {

app/api/github/import/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function POST(request: NextRequest) {
8080
includeDotFolders,
8181
maxFileSizeMB
8282
}
83-
// Filter out undefined options so defaults in downloadRepository apply
83+
8484
const definedImportOptions = Object.fromEntries(
8585
Object.entries(importOptions).filter(([_, v]) => v !== undefined)
8686
);
@@ -94,17 +94,17 @@ export async function POST(request: NextRequest) {
9494
)
9595
}
9696

97-
// Convert to File objects for analysis
97+
9898
const fileObjects = files.map(file => {
9999
const blob = new Blob([file.content], { type: 'text/plain' })
100100
return new File([blob], file.name)
101101
})
102102

103-
// Analyze the project
103+
104104
const analyzer = new ProjectAnalyzer()
105105
const result = await analyzer.analyzeProject(fileObjects)
106106

107-
// Enhance the analysis structure with file contents for easier access
107+
108108
const enhancedStructure = {
109109
...result.structure,
110110
files: result.structure.files.map(file => {

app/api/github/repositories/route.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ export async function GET(request: NextRequest) {
2020
try {
2121
cookieStore.set(name, value, options)
2222
} catch (error) {
23-
// The `set` method was called from a Server Component.
24-
// This can be ignored if you have middleware refreshing
25-
// user sessions.
26-
// console.warn(`Failed to set cookie '${name}' from Server Component:`, error);
23+
24+
25+
26+
2727
}
2828
},
2929
remove(name: string, options: CookieOptions) {
3030
try {
3131
cookieStore.set({ name, value: '', ...options })
3232
} catch (error) {
33-
// The `delete` method was called from a Server Component.
34-
// This can be ignored if you have middleware refreshing
35-
// user sessions.
36-
// console.warn(`Failed to delete cookie '${name}' from Server Component:`, error);
33+
34+
35+
36+
3737
}
3838
},
3939
},

app/api/health/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ export async function GET() {
1212
const metrics = apiClient.getMetrics()
1313
const recentRequests = apiClient.getRecentRequests(10)
1414

15-
// Check system resources
15+
1616
const systemHealth = {
1717
uptime: process.uptime(),
1818
memory: process.memoryUsage(),
1919
nodeVersion: process.version,
2020
timestamp: new Date().toISOString(),
2121
}
2222

23-
// Determine overall system status
23+
2424
let overallStatus = "healthy"
2525
if (healthStatus.status === "unhealthy") {
2626
overallStatus = "unhealthy"

app/api/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function main() {
1111

1212
const codeToRun = 'print("hello world")';
1313
console.log(`Executing code: ${codeToRun}`);
14-
const execution = await sbx.runCode(codeToRun); // Execute Python inside the sandbox
14+
const execution = await sbx.runCode(codeToRun);
1515

1616
console.log('Execution logs:');
1717
execution.logs.stdout.forEach(log => console.log(`[STDOUT] ${log}`));
@@ -29,16 +29,16 @@ async function main() {
2929

3030
} catch (error) {
3131
console.error('An error occurred:', error);
32-
// Depending on the application, you might want to exit or handle the error differently
33-
// process.exit(1);
32+
33+
3434
} finally {
3535
if (sbx) {
3636
console.log('Closing preview...');
3737
try {
3838
await (sbx as any).close();
3939
console.log('Sandbox closed successfully.');
40-
} catch (closeError) { // Updated variable name
41-
console.error('Error closing sandbox:', closeError); // Updated log message
40+
} catch (closeError) {
41+
console.error('Error closing sandbox:', closeError);
4242
}
4343
}
4444
}

0 commit comments

Comments
 (0)