mirror of
https://github.com/NohamR/lanyard-profile-readme.git
synced 2026-05-25 04:17:18 +00:00
fix(fetch): add cache: 'no-store' to avoid errors
This commit is contained in:
@@ -6,80 +6,80 @@ import { NextRequest } from "next/server";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
options: { params: { id: string[] } },
|
||||
req: NextRequest,
|
||||
options: { params: { id: string[] } },
|
||||
) {
|
||||
const userId = options.params.id.join("/");
|
||||
const userId = options.params.id.join("/");
|
||||
|
||||
if (!userId)
|
||||
return Response.json(
|
||||
{
|
||||
data: {
|
||||
error: "No ID provided.",
|
||||
},
|
||||
success: false,
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
},
|
||||
);
|
||||
if (!userId)
|
||||
return Response.json(
|
||||
{
|
||||
data: {
|
||||
error: "No ID provided.",
|
||||
},
|
||||
success: false,
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
},
|
||||
);
|
||||
|
||||
if (!isSnowflake(userId))
|
||||
return Response.json(
|
||||
{
|
||||
data: {
|
||||
error: "The ID you provide is not a valid snowflake.",
|
||||
},
|
||||
success: false,
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
},
|
||||
);
|
||||
if (!isSnowflake(userId))
|
||||
return Response.json(
|
||||
{
|
||||
data: {
|
||||
error: "The ID you provide is not a valid snowflake.",
|
||||
},
|
||||
success: false,
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
},
|
||||
);
|
||||
|
||||
let getUser: any = {};
|
||||
let getUser: any = {};
|
||||
|
||||
getUser.data = await fetch(
|
||||
`https://api.lanyard.rest/v1/users/${userId}`,
|
||||
).then(async (res) => {
|
||||
const data = await res.json();
|
||||
getUser.data = await fetch(`https://api.lanyard.rest/v1/users/${userId}`, {
|
||||
cache: "no-store",
|
||||
}).then(async (res) => {
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.success) {
|
||||
getUser.error = data.error;
|
||||
if (!data.success) {
|
||||
getUser.error = data.error;
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
|
||||
if (getUser.error) {
|
||||
return Response.json(
|
||||
{
|
||||
data: getUser.error,
|
||||
success: false,
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
|
||||
if (getUser.error) {
|
||||
return Response.json(
|
||||
{
|
||||
data: getUser.error,
|
||||
success: false,
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
},
|
||||
const params: Parameters = Object.fromEntries(
|
||||
req.nextUrl.searchParams.entries(),
|
||||
);
|
||||
}
|
||||
|
||||
const params: Parameters = Object.fromEntries(
|
||||
req.nextUrl.searchParams.entries(),
|
||||
);
|
||||
try {
|
||||
let user = await redis.hget("users", userId);
|
||||
if (!user) await redis.hset("users", userId, "true");
|
||||
} catch {
|
||||
null;
|
||||
}
|
||||
|
||||
try {
|
||||
let user = await redis.hget("users", userId);
|
||||
if (!user) await redis.hset("users", userId, "true");
|
||||
} catch {
|
||||
null;
|
||||
}
|
||||
|
||||
return new Response(await renderCard(getUser.data, params), {
|
||||
headers: {
|
||||
"Content-Type": "image/svg+xml; charset=utf-8",
|
||||
"content-security-policy":
|
||||
"default-src 'none'; img-src * data:; style-src 'unsafe-inline'",
|
||||
},
|
||||
status: 200,
|
||||
});
|
||||
return new Response(await renderCard(getUser.data, params), {
|
||||
headers: {
|
||||
"Content-Type": "image/svg+xml; charset=utf-8",
|
||||
"content-security-policy":
|
||||
"default-src 'none'; img-src * data:; style-src 'unsafe-inline'",
|
||||
},
|
||||
status: 200,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ export async function getUserCount() {
|
||||
}
|
||||
|
||||
export async function isUserMonitored(userId: string) {
|
||||
const user = await fetch(
|
||||
`https://api.lanyard.rest/v1/users/${userId}`,
|
||||
).then((res) => res.json());
|
||||
const user = await fetch(`https://api.lanyard.rest/v1/users/${userId}`, {
|
||||
cache: "no-store",
|
||||
}).then((res) => res.json());
|
||||
|
||||
return user.success === true;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ export const encodeBase64 = async (url: string): Promise<string> => {
|
||||
let response = "";
|
||||
|
||||
try {
|
||||
response = await fetch(url)
|
||||
response = await fetch(url, {
|
||||
cache: "no-store",
|
||||
})
|
||||
.then((res) => res.blob())
|
||||
.then(async (blob) => {
|
||||
const buffer = Buffer.from(await blob.arrayBuffer());
|
||||
|
||||
Reference in New Issue
Block a user