mirror of
https://github.com/NohamR/lanyard-profile-readme.git
synced 2026-05-26 04:17:19 +00:00
add count logging w redis + display on main page
This commit is contained in:
@@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import axios from "axios";
|
||||
import renderCard from "../../src/renderCard";
|
||||
import { isSnowflake } from "../../src/snowflake";
|
||||
import redis from "../../src/redis";
|
||||
|
||||
type Data = {
|
||||
id?: string | string[];
|
||||
@@ -30,7 +31,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
|
||||
try {
|
||||
getUser = await axios(`https://api.lanyard.rest/v1/users/${userId}`);
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
if (error.response.status === 404) return res.status(404).send({ error: "Invalid user!" });
|
||||
|
||||
console.log(error); // Only console log the error if its not a 404
|
||||
@@ -40,6 +41,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
});
|
||||
}
|
||||
|
||||
let user = await redis.hget("users", userId);
|
||||
if (!user) await redis.hset("users", userId, "true");
|
||||
|
||||
res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
|
||||
res.setHeader("content-security-policy", "default-src 'none'; img-src * data:; style-src 'unsafe-inline'");
|
||||
|
||||
|
||||
9
pages/api/getUserCount.ts
Normal file
9
pages/api/getUserCount.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import redis from "../../src/redis";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
let users = await redis.hgetall("users");
|
||||
let count = Object.keys(users);
|
||||
|
||||
res.status(200).send({ count: count.length });
|
||||
}
|
||||
Reference in New Issue
Block a user