This commit is contained in:
oiov
2024-10-30 16:03:13 +08:00
parent daf06a32c8
commit 413abe900b
6 changed files with 41 additions and 53 deletions
+1 -4
View File
@@ -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 });
}
}
+2 -8
View File
@@ -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 });
}
}
+21 -16
View File
@@ -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,
},
);
}
}
+15 -15
View File
@@ -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 });
}
}
+1 -4
View File
@@ -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 });
}
}
+1 -6
View File
@@ -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 });
}
}