mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 19:47:00 +03:00
Fix redis type issues
This commit is contained in:
@@ -2,18 +2,15 @@ import {config} from '../config';
|
|||||||
import {Logger} from './logger';
|
import {Logger} from './logger';
|
||||||
import redis, {Callback} from 'redis';
|
import redis, {Callback} from 'redis';
|
||||||
|
|
||||||
let get, set;
|
let exportObject = {
|
||||||
|
get: (key: string, callback?: Callback<string | null>) => callback(null, undefined),
|
||||||
|
set: (key: string, value: string, callback?: Callback<string | null>) => callback(null, undefined)
|
||||||
|
};
|
||||||
|
|
||||||
if (config.redis) {
|
if (config.redis) {
|
||||||
Logger.info('Connected to redis');
|
Logger.info('Connected to redis');
|
||||||
const client = redis.createClient(config.redis);
|
const client = redis.createClient(config.redis);
|
||||||
get = client.get;
|
exportObject = client;
|
||||||
set = client.set;
|
|
||||||
} else {
|
|
||||||
get = (key: string, callback?: Callback<string | null>) => callback(null, undefined);
|
|
||||||
set = (key: string, value: string, callback?: Callback<string | null>) => callback(null, undefined);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export default exportObject;
|
||||||
get,
|
|
||||||
set,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {config} from '../config';
|
import {config} from '../config';
|
||||||
import {Logger} from './logger';
|
import {Logger} from './logger';
|
||||||
import * as redis from './redis';
|
import redis from './redis';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import _youTubeAPI from 'youtube-api';
|
import _youTubeAPI from 'youtube-api';
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ export class YouTubeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const redisKey = "youtube.video." + videoID;
|
const redisKey = "youtube.video." + videoID;
|
||||||
redis.get(redisKey, (getErr: string, result: string) => {
|
redis.get(redisKey, (getErr, result) => {
|
||||||
if (getErr || !result) {
|
if (getErr || !result) {
|
||||||
Logger.debug("redis: no cache for video information: " + videoID);
|
Logger.debug("redis: no cache for video information: " + videoID);
|
||||||
_youTubeAPI.videos.list({
|
_youTubeAPI.videos.list({
|
||||||
@@ -28,9 +28,9 @@ export class YouTubeAPI {
|
|||||||
if (!ytErr) {
|
if (!ytErr) {
|
||||||
// Only set cache if data returned
|
// Only set cache if data returned
|
||||||
if (data.items.length > 0) {
|
if (data.items.length > 0) {
|
||||||
redis.set(redisKey, JSON.stringify(data), (setErr: string) => {
|
redis.set(redisKey, JSON.stringify(data), (setErr) => {
|
||||||
if (setErr) {
|
if (setErr) {
|
||||||
Logger.warn(setErr);
|
Logger.warn(setErr.message);
|
||||||
} else {
|
} else {
|
||||||
Logger.debug("redis: video information cache set for: " + videoID);
|
Logger.debug("redis: video information cache set for: " + videoID);
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ export class YouTubeAPI {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Logger.debug("redis: fetched video information from cache: " + videoID);
|
Logger.debug("redis: fetched video information from cache: " + videoID);
|
||||||
callback(getErr, JSON.parse(result));
|
callback(getErr.message, JSON.parse(result));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user