InvestWeb/pages/api/bttv/emotes.ts

35 lines
889 B
TypeScript
Raw Normal View History

2023-01-21 05:36:29 -05:00
import type { NextApiRequest, NextApiResponse } from "next";
import { createRedisInstance } from "../../../misc/redis";
import { getUserByID, getGlobalEmotes } from "../../../misc/BTTVAPI";
type Data = {
[key: string]: any;
};
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
const redis = createRedisInstance();
2023-01-22 20:25:04 -05:00
if (!redis) {
res.status(500).json({
error: { message: "Internal API is down", code: 50200 },
});
return;
}
2023-01-21 05:36:29 -05:00
try {
const channel = req.query.c
? (await getUserByID(redis, req.query.c as string)).channelEmotes
: undefined;
const global = await getGlobalEmotes(redis);
redis.quit();
res.status(200).json({ channel, global });
} catch (e) {
console.log(e);
2023-01-22 20:25:04 -05:00
res.status(500).json({
error: { message: "BTTV or internal API is down", code: 10200 },
});
2023-01-21 05:36:29 -05:00
}
}