type fix
This commit is contained in:
parent
ef4a98cfd2
commit
67eb895988
2 changed files with 14 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
||||||
import type RedisInstance from "ioredis";
|
import Redis from "ioredis";
|
||||||
|
|
||||||
async function applyCache(
|
async function applyCache(
|
||||||
redis: RedisInstance,
|
redis: Redis,
|
||||||
key: string,
|
key: string,
|
||||||
query: string,
|
query: string,
|
||||||
gql: boolean,
|
gql: boolean,
|
||||||
|
@ -19,7 +19,7 @@ async function applyCache(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchEndpoint(
|
async function fetchEndpoint(
|
||||||
redis: RedisInstance,
|
redis: Redis,
|
||||||
query: string,
|
query: string,
|
||||||
gql: boolean = false
|
gql: boolean = false
|
||||||
) {
|
) {
|
||||||
|
@ -53,7 +53,7 @@ async function fetchGQL(query: string) {
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGlobalEmotes(redis: RedisInstance) {
|
async function getGlobalEmotes(redis: Redis) {
|
||||||
const gqlQuery = `query {
|
const gqlQuery = `query {
|
||||||
namedEmoteSet(name: GLOBAL) {
|
namedEmoteSet(name: GLOBAL) {
|
||||||
emote_count
|
emote_count
|
||||||
|
@ -84,7 +84,7 @@ async function getGlobalEmotes(redis: RedisInstance) {
|
||||||
return await applyCache(redis, "7TV.GLOBAL_EMOTES", gqlQuery, true, 3600);
|
return await applyCache(redis, "7TV.GLOBAL_EMOTES", gqlQuery, true, 3600);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChannelEmotes(redis: RedisInstance, channelID: string) {
|
async function getChannelEmotes(redis: Redis, channelID: string) {
|
||||||
const gqlQuery = `query {
|
const gqlQuery = `query {
|
||||||
user(id: "${channelID}") {
|
user(id: "${channelID}") {
|
||||||
emote_sets {
|
emote_sets {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import type RedisInstance from "ioredis";
|
// ioredis types
|
||||||
|
import Redis from "ioredis";
|
||||||
|
|
||||||
async function applyCache(
|
async function applyCache(
|
||||||
redis: RedisInstance,
|
redis: Redis,
|
||||||
key: string,
|
key: string,
|
||||||
query: string,
|
query: string,
|
||||||
cacheTime: number
|
cacheTime: number
|
||||||
|
@ -17,7 +18,7 @@ async function applyCache(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function authTwitch(redis: RedisInstance) {
|
async function authTwitch(redis: Redis) {
|
||||||
let auth = await redis.get("TWITCH.AUTH");
|
let auth = await redis.get("TWITCH.AUTH");
|
||||||
if (auth) {
|
if (auth) {
|
||||||
return auth;
|
return auth;
|
||||||
|
@ -35,7 +36,7 @@ async function authTwitch(redis: RedisInstance) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchEndpoint(redis: RedisInstance, query: string) {
|
async function fetchEndpoint(redis: Redis, query: string) {
|
||||||
if (await redis.get("TWITCH.RATE_LIMIT")) {
|
if (await redis.get("TWITCH.RATE_LIMIT")) {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
} else {
|
} else {
|
||||||
|
@ -55,7 +56,7 @@ async function fetchEndpoint(redis: RedisInstance, query: string) {
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUserByName(redis: RedisInstance, username: string) {
|
async function getUserByName(redis: Redis, username: string) {
|
||||||
return await applyCache(
|
return await applyCache(
|
||||||
redis,
|
redis,
|
||||||
"TWITCH.USER_" + username,
|
"TWITCH.USER_" + username,
|
||||||
|
@ -64,7 +65,7 @@ async function getUserByName(redis: RedisInstance, username: string) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUserByID(redis: RedisInstance, userID: string) {
|
async function getUserByID(redis: Redis, userID: string) {
|
||||||
return await applyCache(
|
return await applyCache(
|
||||||
redis,
|
redis,
|
||||||
"TWITCH.USER_" + userID,
|
"TWITCH.USER_" + userID,
|
||||||
|
@ -73,7 +74,7 @@ async function getUserByID(redis: RedisInstance, userID: string) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGlobalEmotes(redis: RedisInstance) {
|
async function getGlobalEmotes(redis: Redis) {
|
||||||
return await applyCache(
|
return await applyCache(
|
||||||
redis,
|
redis,
|
||||||
"TWITCH.GLOBAL_EMOTES",
|
"TWITCH.GLOBAL_EMOTES",
|
||||||
|
@ -82,7 +83,7 @@ async function getGlobalEmotes(redis: RedisInstance) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChannelEmotes(redis: RedisInstance, channelID: string) {
|
async function getChannelEmotes(redis: Redis, channelID: string) {
|
||||||
return await applyCache(
|
return await applyCache(
|
||||||
redis,
|
redis,
|
||||||
"TWITCH.CHANNEL_EMOTES_" + channelID,
|
"TWITCH.CHANNEL_EMOTES_" + channelID,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue