Skip to content

Conversation

@Rtur2003
Copy link
Owner

This pull request introduces a new unified analysis gateway endpoint using Netlify Functions and refactors the analysis logic to support this integration. It also improves error handling, standardizes preview indicators, and adds utility functions for analysis. The most important changes are summarized below:

Backend/Infrastructure:

  • Added a Netlify Function (netlify/functions/analyze.js) that acts as a mock analysis gateway, returning a preview response for POST requests. This sets up the structure for integrating real analysis providers in the future.
  • Updated netlify.toml to specify the new functions directory for Netlify Functions.

Analysis Logic & API Integration:

  • Introduced platform/hooks/analysisGateway.ts with the analyzeSource function to handle analysis requests via the new gateway, supporting both file and URL sources, and improved error mapping for backend responses.
  • Expanded the AnalysisErrorCode type in platform/hooks/analysisTypes.ts to include new backend-related error codes for more robust error handling.

Preview/Mock Logic Standardization:

  • Added a previewIndicators utility in platform/hooks/analysisUtils.ts to standardize artificial indicator messages across preview/mock results. Updated both file and YouTube analysis hooks to use this utility. [1] [2] [3] [4] [5]

Copilot AI review requested due to automatic review settings December 18, 2025 18:25
@netlify
Copy link

netlify bot commented Dec 18, 2025

Deploy Preview for crowncode-by-rthur ready!

Name Link
🔨 Latest commit ea7391d
🔍 Latest deploy log https://app.netlify.com/projects/crowncode-by-rthur/deploys/69444701a00cc100087e6299
😎 Deploy Preview https://deploy-preview-8--crowncode-by-rthur.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 70
Accessibility: 100
Best Practices: 100
SEO: 100
PWA: 100
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@Rtur2003 Rtur2003 merged commit c43c957 into geliştirme Dec 18, 2025
6 of 8 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces a unified analysis gateway endpoint infrastructure using Netlify Functions, refactors the analysis logic for better maintainability, and standardizes preview indicators across the codebase.

Key changes:

  • Added a Netlify Function as a mock analysis gateway endpoint that returns preview responses, setting up infrastructure for future real analysis provider integration
  • Introduced a new analyzeSource function in analysisGateway.ts to handle analysis requests with improved error mapping and support for multiple source types
  • Standardized preview indicator messages by creating a previewIndicators() utility function, eliminating code duplication in file and YouTube analysis hooks

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
netlify/functions/analyze.js New Netlify Function providing a mock analysis gateway endpoint that returns preview responses
netlify.toml Configuration update specifying the functions directory for Netlify Functions
platform/hooks/analysisGateway.ts New gateway module for handling analysis requests with FormData support and error mapping
platform/hooks/analysisTypes.ts Extended error codes to include backend-related errors (not_configured, unreachable, unexpected_response)
platform/hooks/analysisUtils.ts Added previewIndicators() utility to standardize artificial indicator messages
platform/hooks/useFileAnalysis.ts Updated to use the new previewIndicators() utility instead of hardcoded messages
platform/hooks/useYouTubeAnalysis.ts Updated to use the new previewIndicators() utility instead of hardcoded messages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,49 @@
// Unified analysis gateway (mock/preview). Real integrations (yt-dlp/model) should be wired to the providers.
const { promises: fs } = require('fs')
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The imported fs module is never used in this function. Consider removing this unused import to keep the code clean.

Suggested change
const { promises: fs } = require('fs')

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +35
artificialIndicators: [
'Preview-only decision based on fingerprint.',
'No model inference was available at request time.'
]
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded preview indicator messages in the Netlify function are inconsistent with the previewIndicators() utility function used elsewhere in the codebase. The Netlify function uses "Preview-only decision based on fingerprint." while the utility in analysisUtils.ts returns the same message. However, this creates maintenance burden - if the preview indicator messages need to change, they must be updated in two places. Consider importing and using the previewIndicators() utility function, or if that's not possible in this Node.js context, document this duplication and the reason for it.

Copilot uses AI. Check for mistakes.
errors?: string[]
}

const MAX_BYTES = 30 * 1024 * 1024 // 30MB
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MAX_BYTES constant is set to 30MB here, but in useFileAnalysis.ts, the MAX_FILE_SIZE_BYTES constant is set to 100MB. This inconsistency means that files between 30MB and 100MB would be rejected by the gateway but accepted by the frontend validation. These limits should be aligned to prevent confusing user experiences where a file passes frontend validation but fails at the backend.

Suggested change
const MAX_BYTES = 30 * 1024 * 1024 // 30MB
const MAX_BYTES = 100 * 1024 * 1024 // 100MB

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +47
const response = await fetch(`${apiBaseUrl}/api/analyze`, {
method: 'POST',
body: formData
})

if (!response.ok) {
return { result: null, error: 'backend_unreachable' as AnalysisErrorCode }
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling for non-OK HTTP responses is too broad. A non-OK response could be a 400 (bad request), 500 (server error), or network timeout, but all are mapped to 'backend_unreachable'. Consider checking response.status to provide more specific error codes. For example, 4xx errors could map to different error codes than 5xx errors, improving the user experience with more accurate error messages.

Suggested change
const response = await fetch(`${apiBaseUrl}/api/analyze`, {
method: 'POST',
body: formData
})
if (!response.ok) {
return { result: null, error: 'backend_unreachable' as AnalysisErrorCode }
let response: Response
try {
response = await fetch(`${apiBaseUrl}/api/analyze`, {
method: 'POST',
body: formData
})
} catch {
// Network-level error (timeout, DNS failure, etc.)
return { result: null, error: 'backend_unreachable' as AnalysisErrorCode }
}
if (!response.ok) {
// Distinguish between client and server errors for better error reporting
if (response.status >= 400 && response.status < 500) {
return { result: null, error: 'backend_unexpected_response' as AnalysisErrorCode }
}
if (response.status >= 500 && response.status < 600) {
return { result: null, error: 'backend_unreachable' as AnalysisErrorCode }
}
return { result: null, error: 'backend_unexpected_response' as AnalysisErrorCode }

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +44
const response = await fetch(`${apiBaseUrl}/api/analyze`, {
method: 'POST',
body: formData
})
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fetch call does not handle network errors or exceptions. If the fetch fails due to network issues (e.g., no internet connection, DNS failure), this will throw an unhandled exception. Consider wrapping the fetch in a try-catch block to properly handle these errors and return an appropriate error code like 'backend_unreachable'.

Suggested change
const response = await fetch(`${apiBaseUrl}/api/analyze`, {
method: 'POST',
body: formData
})
let response: Response
try {
response = await fetch(`${apiBaseUrl}/api/analyze`, {
method: 'POST',
body: formData
})
} catch {
return { result: null, error: 'backend_unreachable' as AnalysisErrorCode }
}

Copilot uses AI. Check for mistakes.
return { result: null, error: 'backend_unreachable' as AnalysisErrorCode }
}

const data = await response.json() as AnalyzeResponse
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON parsing on line 50 could throw an exception if the response body is not valid JSON. Consider wrapping this in a try-catch block or handling the case where the response is malformed, returning 'backend_unexpected_response' error in such cases.

Suggested change
const data = await response.json() as AnalyzeResponse
let data: AnalyzeResponse
try {
data = (await response.json()) as AnalyzeResponse
} catch {
return { result: null, error: 'backend_unexpected_response' as AnalysisErrorCode }
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants