Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/api/scrape-screenshot/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { NextRequest, NextResponse } from 'next/server';
import { isValidUrl } from '@/lib/utils';

export async function POST(req: NextRequest) {
try {
const { url } = await req.json();

if (!url) {
return NextResponse.json({ error: 'URL is required' }, { status: 400 });
if (!url || !isValidUrl(url)) {
return NextResponse.json({ error: 'A valid URL is required' }, { status: 400 });
}

// Use Firecrawl API to capture screenshot
Expand Down
5 changes: 3 additions & 2 deletions app/api/scrape-url-enhanced/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
import { isValidUrl } from '@/lib/utils';

// Function to sanitize smart quotes and other problematic characters
function sanitizeQuotes(text: string): string {
Expand All @@ -20,10 +21,10 @@ export async function POST(request: NextRequest) {
try {
const { url } = await request.json();

if (!url) {
if (!url || !isValidUrl(url)) {
return NextResponse.json({
success: false,
error: 'URL is required'
error: 'A valid URL is required'
}, { status: 400 });
}

Expand Down
11 changes: 10 additions & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
}

export const isValidUrl = (url: string): boolean => {
try {
new URL(url);
return true;
} catch (error) {
return false;
}
};
Loading