mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-18 09:08:42 +00:00
fixing linter
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
This commit is contained in:
parent
709dd76f74
commit
6fa725a833
13 changed files with 1141 additions and 320 deletions
|
|
@ -1,47 +1,45 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { url } = await request.json();
|
||||
|
||||
if (!url || typeof url !== 'string') {
|
||||
return NextResponse.json(
|
||||
{ error: 'URL is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
if (!url || typeof url !== "string") {
|
||||
return NextResponse.json({ error: "URL is required" }, { status: 400 });
|
||||
}
|
||||
|
||||
// Fetch the URL content
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||
}
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const contentType = response.headers.get('content-type') || '';
|
||||
const contentType = response.headers.get("content-type") || "";
|
||||
let content: string;
|
||||
|
||||
if (contentType.includes('application/json')) {
|
||||
if (contentType.includes("application/json")) {
|
||||
const json = await response.json();
|
||||
content = JSON.stringify(json, null, 2);
|
||||
} else if (contentType.includes('text/html')) {
|
||||
} else if (contentType.includes("text/html")) {
|
||||
const html = await response.text();
|
||||
// Basic HTML to text conversion - remove tags and decode entities
|
||||
content = html
|
||||
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
|
||||
.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, '')
|
||||
.replace(/<[^>]*>/g, '')
|
||||
.replace(/ /g, ' ')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "")
|
||||
.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, "")
|
||||
.replace(/<[^>]*>/g, "")
|
||||
.replace(/ /g, " ")
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'")
|
||||
.replace(/\s+/g, ' ')
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
} else {
|
||||
content = await response.text();
|
||||
|
|
@ -49,9 +47,9 @@ export async function POST(request: NextRequest) {
|
|||
|
||||
return NextResponse.json({ content });
|
||||
} catch (error) {
|
||||
console.error('Error fetching URL:', error);
|
||||
console.error("Error fetching URL:", error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch URL content' },
|
||||
{ error: "Failed to fetch URL content" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue