-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(frontend): adding project screenshot #159
Changes from all commits
70fdfa7
460fa98
b4b9918
4bc0028
ef21686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,10 @@ import { exec } from 'child_process'; | |||||||
import * as path from 'path'; | ||||||||
import * as net from 'net'; | ||||||||
import { getProjectPath } from 'codefox-common'; | ||||||||
import puppetter from 'puppeteer'; | ||||||||
import { useMutation } from '@apollo/client/react/hooks/useMutation'; | ||||||||
import { toast } from 'sonner'; | ||||||||
import { UPDATE_PROJECT_PHOTO_URL } from '@/graphql/request'; | ||||||||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unused imports. These imports are not used in this file and should be removed. In particular, -import { useMutation } from '@apollo/client/react/hooks/useMutation';
-import { toast } from 'sonner';
-import { UPDATE_PROJECT_PHOTO_URL } from '@/graphql/request'; 📝 Committable suggestion
Suggested change
|
||||||||
|
||||||||
const runningContainers = new Map< | ||||||||
string, | ||||||||
|
@@ -294,6 +298,7 @@ export async function GET(req: Request) { | |||||||
|
||||||||
try { | ||||||||
const { domain, containerId } = await buildAndRunDocker(projectPath); | ||||||||
|
||||||||
return NextResponse.json({ | ||||||||
message: 'Docker container started', | ||||||||
domain, | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { randomUUID } from 'crypto'; | ||
import { NextResponse } from 'next/server'; | ||
import puppeteer from 'puppeteer'; | ||
|
||
export async function GET(req: Request) { | ||
const { searchParams } = new URL(req.url); | ||
const url = searchParams.get('url'); | ||
|
||
if (!url) { | ||
return NextResponse.json( | ||
{ error: 'URL parameter is required' }, | ||
{ status: 400 } | ||
); | ||
} | ||
|
||
try { | ||
const browser = await puppeteer.launch({ | ||
headless: true, | ||
}); | ||
const page = await browser.newPage(); | ||
|
||
// Set viewport to a reasonable size | ||
await page.setViewport({ | ||
width: 1280, | ||
height: 720, | ||
}); | ||
|
||
await page.goto(url, { | ||
waitUntil: 'networkidle0', | ||
timeout: 30000, | ||
}); | ||
|
||
// Take screenshot | ||
const screenshot = await page.screenshot({ | ||
path: `dsadas.png`, | ||
type: 'png', | ||
fullPage: true, | ||
}); | ||
|
||
await browser.close(); | ||
|
||
// Return the screenshot as a PNG image | ||
return new Response(screenshot, { | ||
headers: { | ||
'Content-Type': 'image/png', | ||
'Cache-Control': 's-maxage=3600', | ||
}, | ||
}); | ||
} catch (error: any) { | ||
console.error('Screenshot error:', error); | ||
return NextResponse.json( | ||
{ error: error.message || 'Failed to capture screenshot' }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo in puppeteer import.
There's a typo in the puppeteer import that could cause runtime errors.
📝 Committable suggestion