mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-17 03:44:20 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into switch-axios
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {config} from "../config";
|
||||
import {Request} from "express";
|
||||
import { config } from "../config";
|
||||
import { Request } from "express";
|
||||
import { IPAddress } from "../types/segments.model";
|
||||
|
||||
export function getIP(req: Request): IPAddress {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {getHash} from "./getHash";
|
||||
import { getHash } from "./getHash";
|
||||
import { HashedValue } from "../types/hash.model";
|
||||
import { ActionType, VideoID } from "../types/segments.model";
|
||||
import { UserID } from "../types/user.model";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {config} from "../config";
|
||||
import { config } from "../config";
|
||||
|
||||
const minimumPrefix = config.minimumPrefix || "3";
|
||||
const maximumPrefix = config.maximumPrefix || "32"; // Half the hash.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {db} from "../databases/databases";
|
||||
import { db } from "../databases/databases";
|
||||
|
||||
/**
|
||||
* Returns true if the user is considered trustworthy. This happens after a user has made 5 submissions and has less than 60% downvoted submissions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {db} from "../databases/databases";
|
||||
import { db } from "../databases/databases";
|
||||
import { HashedUserID } from "../types/user.model";
|
||||
|
||||
export async function isUserVIP(userID: HashedUserID): Promise<boolean> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {config} from "../config";
|
||||
import { config } from "../config";
|
||||
|
||||
const enum LogLevel {
|
||||
ERROR = "ERROR",
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Service, VideoID, VideoIDHash } from "../types/segments.model";
|
||||
import { UserID } from "../types/user.model";
|
||||
|
||||
async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
||||
const {err, reply} = await redis.getAsync(key);
|
||||
const { err, reply } = await redis.getAsync(key);
|
||||
|
||||
if (!err && reply) {
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {config} from "../config";
|
||||
import {Logger} from "./logger";
|
||||
import redis, {Callback} from "redis";
|
||||
import { config } from "../config";
|
||||
import { Logger } from "./logger";
|
||||
import redis, { Callback } from "redis";
|
||||
|
||||
interface RedisSB {
|
||||
get(key: string, callback?: Callback<string | null>): void;
|
||||
@@ -13,10 +13,10 @@ interface RedisSB {
|
||||
let exportObject: RedisSB = {
|
||||
get: (key, callback?) => callback(null, undefined),
|
||||
getAsync: () =>
|
||||
new Promise((resolve) => resolve({err: null, reply: undefined})),
|
||||
new Promise((resolve) => resolve({ err: null, reply: undefined })),
|
||||
set: (key, value, callback) => callback(null, undefined),
|
||||
setAsync: () =>
|
||||
new Promise((resolve) => resolve({err: null, reply: undefined})),
|
||||
new Promise((resolve) => resolve({ err: null, reply: undefined })),
|
||||
delAsync: () =>
|
||||
new Promise((resolve) => resolve(null)),
|
||||
};
|
||||
@@ -26,8 +26,8 @@ if (config.redis) {
|
||||
const client = redis.createClient(config.redis);
|
||||
exportObject = client;
|
||||
|
||||
exportObject.getAsync = (key) => new Promise((resolve) => client.get(key, (err, reply) => resolve({err, reply})));
|
||||
exportObject.setAsync = (key, value) => new Promise((resolve) => client.set(key, value, (err, reply) => resolve({err, reply})));
|
||||
exportObject.getAsync = (key) => new Promise((resolve) => client.get(key, (err, reply) => resolve({ err, reply })));
|
||||
exportObject.setAsync = (key, value) => new Promise((resolve) => client.set(key, value, (err, reply) => resolve({ err, reply })));
|
||||
exportObject.delAsync = (...keys) => new Promise((resolve) => client.del(keys, (err) => resolve(err)));
|
||||
|
||||
client.on("error", function(error) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {config} from "../config";
|
||||
import {Logger} from "../utils/logger";
|
||||
import { config } from "../config";
|
||||
import { Logger } from "../utils/logger";
|
||||
import axios from "axios";
|
||||
|
||||
function getVoteAuthorRaw(submissionCount: number, isVIP: boolean, isOwnSubmission: boolean): string {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {config} from "../config";
|
||||
import {Logger} from "./logger";
|
||||
import { config } from "../config";
|
||||
import { Logger } from "./logger";
|
||||
import { APIVideoData, APIVideoInfo } from "../types/youtubeApi.model";
|
||||
import DiskCache from "./diskCache";
|
||||
import axios from "axios";
|
||||
@@ -24,7 +24,7 @@ export class YouTubeAPI {
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.newLeafURLs || config.newLeafURLs.length <= 0) return {err: "NewLeaf URL not found", data: null};
|
||||
if (!config.newLeafURLs || config.newLeafURLs.length <= 0) return { err: "NewLeaf URL not found", data: null };
|
||||
|
||||
try {
|
||||
const result = await axios.get(`${config.newLeafURLs[Math.floor(Math.random() * config.newLeafURLs.length)]}/api/v1/videos/${videoID}`);
|
||||
@@ -45,7 +45,7 @@ export class YouTubeAPI {
|
||||
return { err: result.statusText, data: null };
|
||||
}
|
||||
} catch (err) {
|
||||
return {err: err as string | boolean, data: null};
|
||||
return { err: err as string | boolean, data: null };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user