InvestWeb/pages/api/7tv/emotes.ts

29 lines
754 B
TypeScript
Raw Normal View History

2022-12-08 09:57:59 -05:00
import type { NextApiRequest, NextApiResponse } from "next";
2023-01-19 22:17:49 -05:00
import { createRedisInstance } from "../../../misc/redis";
2022-12-08 09:57:59 -05:00
import { getChannelEmotes, getGlobalEmotes } from "../../../misc/7TVAPI";
type Data = {
[key: string]: any;
};
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
2023-01-19 22:17:49 -05:00
const redis = createRedisInstance();
2022-12-08 09:57:59 -05:00
2023-01-19 22:17:49 -05:00
try {
const channel = req.query.c
? await getChannelEmotes(redis, req.query.c as string)
: undefined;
const global = await getGlobalEmotes(redis);
redis.quit();
res.status(200).json({ channel, global });
} catch (e) {
console.log(e);
res
.status(500)
.json({ error: { message: "7TV or internal API is down", code: 10000 } });
}
2022-12-08 09:57:59 -05:00
}