upd
This commit is contained in:
@@ -97,9 +97,6 @@ export async function GET(req: Request) {
|
||||
|
||||
return Response.json({ list: combinedData.reverse(), total });
|
||||
} catch (error) {
|
||||
return Response.json(error?.statusText || error, {
|
||||
status: error.status || 500,
|
||||
statusText: error.statusText || "Server error",
|
||||
});
|
||||
return Response.json({ statusText: "Server error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,8 @@ export async function POST(req: Request) {
|
||||
if (res) {
|
||||
return Response.json(res.apiKey);
|
||||
}
|
||||
return Response.json(res, {
|
||||
status: 501,
|
||||
statusText: "Server error",
|
||||
});
|
||||
return Response.json({ statusText: "Server error" }, { status: 501 });
|
||||
} catch (error) {
|
||||
return Response.json("An error occurred", {
|
||||
status: error.status || 500,
|
||||
statusText: error.statusText || "Server error",
|
||||
});
|
||||
return Response.json({ statusText: "Server error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,22 +12,23 @@ export async function GET(req: Request) {
|
||||
const url = new URL(req.url);
|
||||
const link = url.searchParams.get("url");
|
||||
if (!link || !isLink(link)) {
|
||||
return Response.json("Url is required", {
|
||||
status: 400,
|
||||
statusText: "Url is required",
|
||||
});
|
||||
return Response.json(
|
||||
{ statusText: "Url is required" },
|
||||
{
|
||||
status: 400,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Get the API key from the request
|
||||
const custom_apiKey = url.searchParams.get("key");
|
||||
if (!custom_apiKey) {
|
||||
return Response.json(
|
||||
"API key is required. You can get your API key from Dashboard->Settings.",
|
||||
{
|
||||
status: 400,
|
||||
statusText:
|
||||
"API key is required. You can get your API key from Dashboard->Settings.",
|
||||
},
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -37,7 +38,7 @@ export async function GET(req: Request) {
|
||||
return Response.json(
|
||||
{
|
||||
statusText:
|
||||
"API key is required. You can get your API key from Dashboard->Settings.",
|
||||
"Invalid API key. You can get your API key from Dashboard->Settings.",
|
||||
},
|
||||
{ status: 401 },
|
||||
);
|
||||
@@ -45,10 +46,12 @@ export async function GET(req: Request) {
|
||||
|
||||
const res = await fetch(link);
|
||||
if (!res.ok) {
|
||||
return Response.json("Failed to fetch url", {
|
||||
status: 405,
|
||||
statusText: "Failed to fetch url",
|
||||
});
|
||||
return Response.json(
|
||||
{ statusText: "Failed to fetch url" },
|
||||
{
|
||||
status: 405,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const html = await res.text();
|
||||
@@ -93,10 +96,12 @@ export async function GET(req: Request) {
|
||||
payload: `https://wr.do/api/scraping/meta?url=${link}&key=${custom_apiKey}`,
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error);
|
||||
return Response.json("An error occurred", {
|
||||
status: error.status || 500,
|
||||
statusText: error.statusText || "Server error",
|
||||
});
|
||||
console.log(error);
|
||||
return Response.json(
|
||||
{ statusText: "Server error" },
|
||||
{
|
||||
status: 500,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,22 +24,23 @@ export async function GET(req: Request) {
|
||||
|
||||
// Check if the url is valid
|
||||
if (!link || !isLink(link)) {
|
||||
return Response.json("Invalid url", {
|
||||
status: 400,
|
||||
statusText: "Invalid url",
|
||||
});
|
||||
return Response.json(
|
||||
{ statusText: "Url is required" },
|
||||
{
|
||||
status: 400,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Get the API key from the request
|
||||
const custom_apiKey = url.searchParams.get("key");
|
||||
if (!custom_apiKey) {
|
||||
return Response.json(
|
||||
"API key is required. You can get your API key from Dashboard->Settings.",
|
||||
{
|
||||
status: 400,
|
||||
statusText:
|
||||
"API key is required. You can get your API key from Dashboard->Settings.",
|
||||
},
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ export async function GET(req: Request) {
|
||||
return Response.json(
|
||||
{
|
||||
statusText:
|
||||
"API key is required. You can get your API key from Dashboard->Settings.",
|
||||
"Invalid API key. You can get your API key from Dashboard->Settings.",
|
||||
},
|
||||
{ status: 401 },
|
||||
);
|
||||
@@ -61,10 +62,12 @@ export async function GET(req: Request) {
|
||||
|
||||
const res = await fetch(scrape_url);
|
||||
if (!res.ok) {
|
||||
return Response.json("Failed to get screenshot", {
|
||||
status: 406,
|
||||
statusText: "Failed to get screenshot",
|
||||
});
|
||||
return Response.json(
|
||||
{ statusText: "Failed to get screenshot" },
|
||||
{
|
||||
status: 406,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const imageBuffer = await res.arrayBuffer();
|
||||
@@ -76,9 +79,6 @@ export async function GET(req: Request) {
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return Response.json("Server error", {
|
||||
status: error.status || 500,
|
||||
statusText: "Server error",
|
||||
});
|
||||
return Response.json({ statusText: "Server error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,6 @@ export async function GET(req: Request) {
|
||||
|
||||
return Response.json(data);
|
||||
} catch (error) {
|
||||
return Response.json(error?.statusText || error, {
|
||||
status: error.status || 500,
|
||||
statusText: error.statusText || "Server error",
|
||||
});
|
||||
return Response.json({ statusText: "Server error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ export async function POST(req: Request) {
|
||||
if (user.role !== "ADMIN") {
|
||||
return Response.json("Unauthorized", {
|
||||
status: 401,
|
||||
statusText: "Unauthorized",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,14 +25,10 @@ export async function POST(req: Request) {
|
||||
if (!res?.id) {
|
||||
return Response.json("An error occurred", {
|
||||
status: 400,
|
||||
statusText: "An error occurred",
|
||||
});
|
||||
}
|
||||
return Response.json("success");
|
||||
} catch (error) {
|
||||
return Response.json(error?.statusText || error, {
|
||||
status: error.status || 500,
|
||||
statusText: error.statusText || "Server error",
|
||||
});
|
||||
return Response.json({ statusText: "Server error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user