mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-15 07:57:05 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into mute-skip
This commit is contained in:
@@ -9,8 +9,8 @@
|
|||||||
"dev:bash": "nodemon -x 'npm test ; npm start'",
|
"dev:bash": "nodemon -x 'npm test ; npm start'",
|
||||||
"start": "ts-node src/index.ts",
|
"start": "ts-node src/index.ts",
|
||||||
"tsc": "tsc -p tsconfig.json",
|
"tsc": "tsc -p tsconfig.json",
|
||||||
"lint": "eslint src",
|
"lint": "eslint src test",
|
||||||
"lint:fix": "eslint src --fix"
|
"lint:fix": "eslint src test --fix"
|
||||||
},
|
},
|
||||||
"author": "Ajay Ramachandran",
|
"author": "Ajay Ramachandran",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ addDefaults(config, {
|
|||||||
function addDefaults(config: SBSConfig, defaults: SBSConfig) {
|
function addDefaults(config: SBSConfig, defaults: SBSConfig) {
|
||||||
for (const key in defaults) {
|
for (const key in defaults) {
|
||||||
if (!Object.prototype.hasOwnProperty.call(config, key)) {
|
if (!Object.prototype.hasOwnProperty.call(config, key)) {
|
||||||
// @ts-ignore
|
|
||||||
config[key] = defaults[key];
|
config[key] = defaults[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import * as redis from 'redis';
|
|||||||
import { CacheOptions } from "@ajayyy/lru-diskcache";
|
import { CacheOptions } from "@ajayyy/lru-diskcache";
|
||||||
|
|
||||||
export interface SBSConfig {
|
export interface SBSConfig {
|
||||||
|
[index: string]: any
|
||||||
port: number;
|
port: number;
|
||||||
mockPort?: number;
|
mockPort?: number;
|
||||||
globalSalt: string;
|
globalSalt: string;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export function createMemoryCache(memoryFn: (...args: any[]) => void, cacheTimeMs: number) {
|
export function createMemoryCache(memoryFn: (...args: any[]) => void, cacheTimeMs: number): any {
|
||||||
if (isNaN(cacheTimeMs)) cacheTimeMs = 0;
|
if (isNaN(cacheTimeMs)) cacheTimeMs = 0;
|
||||||
|
|
||||||
// holds the promise results
|
// holds the promise results
|
||||||
@@ -22,8 +22,8 @@ export function createMemoryCache(memoryFn: (...args: any[]) => void, cacheTimeM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create new promise
|
// create new promise
|
||||||
const promise = new Promise(async (resolve) => {
|
const promise = new Promise((resolve) => {
|
||||||
resolve((await memoryFn(...args)));
|
resolve(memoryFn(...args));
|
||||||
});
|
});
|
||||||
// store promise reference until fulfilled
|
// store promise reference until fulfilled
|
||||||
promiseMemory.set(cacheKey, promise);
|
promiseMemory.set(cacheKey, promise);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ if (config.diskCache) {
|
|||||||
DiskCache.init();
|
DiskCache.init();
|
||||||
} else {
|
} else {
|
||||||
DiskCache = {
|
DiskCache = {
|
||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
// constructor(rootPath, options): {};
|
// constructor(rootPath, options): {};
|
||||||
|
|
||||||
init(): void { return; },
|
init(): void { return; },
|
||||||
@@ -16,16 +17,17 @@ if (config.diskCache) {
|
|||||||
|
|
||||||
has(key: string): boolean { return false; },
|
has(key: string): boolean { return false; },
|
||||||
|
|
||||||
get(key: string, opts): string { return null; },
|
get(key: string, opts?: {encoding?: string}): string { return null; },
|
||||||
|
|
||||||
// Returns size
|
// Returns size
|
||||||
set(key: string, dataOrSteam): Promise<number> { return new Promise(() => 0); },
|
set(key: string, dataOrSteam: string): Promise<number> { return new Promise(() => 0); },
|
||||||
|
|
||||||
del(key: string): void { return; },
|
del(key: string): void { return; },
|
||||||
|
|
||||||
size(): number { return 0; },
|
size(): number { return 0; },
|
||||||
|
|
||||||
prune(): void {return; },
|
prune(): void {return; },
|
||||||
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ describe('getSkipSegments', () => {
|
|||||||
else done();
|
else done();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => done("Couldn't call endpoint"));
|
.catch(() => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get specific segments with repeating requiredSegment', (done: Done) => {
|
it('Should be able to get specific segments with repeating requiredSegment', (done: Done) => {
|
||||||
@@ -341,6 +341,6 @@ describe('getSkipSegments', () => {
|
|||||||
else done();
|
else done();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => done("Couldn't call endpoint"));
|
.catch(() => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ describe('getSegmentsByHash', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => ("Couldn't call endpoint"));
|
.catch(() => ("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get specific segments with requiredSegments', (done: Done) => {
|
it('Should be able to get specific segments with requiredSegments', (done: Done) => {
|
||||||
@@ -268,7 +268,7 @@ describe('getSegmentsByHash', () => {
|
|||||||
else done();
|
else done();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => done("Couldn't call endpoint"));
|
.catch(() => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to get specific segments with repeating requiredSegment', (done: Done) => {
|
it('Should be able to get specific segments with repeating requiredSegment', (done: Done) => {
|
||||||
@@ -284,6 +284,6 @@ describe('getSegmentsByHash', () => {
|
|||||||
else done();
|
else done();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => done("Couldn't call endpoint"));
|
.catch(() => done("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ describe('getUserInfo', () => {
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
for (const value in data) {
|
for (const value in data) {
|
||||||
if (data[value] === null && value !== "lastSegmentID") {
|
if (data[value] === null && value !== "lastSegmentID") {
|
||||||
done(`returned null for ${value}`)
|
done(`returned null for ${value}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done(); // pass
|
done(); // pass
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ async function getLastLogUserNameChange(userID: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wellFormatUserName(userName: string) {
|
function wellFormatUserName(userName: string) {
|
||||||
|
// eslint-disable-next-line no-control-regex
|
||||||
return userName.replace(/[\u0000-\u001F\u007F-\u009F]/g, '');
|
return userName.replace(/[\u0000-\u001F\u007F-\u009F]/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import {config} from '../src/config';
|
import {config} from '../src/config';
|
||||||
|
import { Server } from 'http';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
@@ -46,6 +47,6 @@ app.post('/CustomWebhook', (req, res) => {
|
|||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
export function createMockServer(callback: () => void) {
|
export function createMockServer(callback: () => void): Server {
|
||||||
return app.listen(config.mockPort, callback);
|
return app.listen(config.mockPort, callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ async function init() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// delete old test database
|
// delete old test database
|
||||||
if (fs.existsSync(config.db)) fs.unlinkSync(config.db)
|
if (fs.existsSync(config.db)) fs.unlinkSync(config.db);
|
||||||
if (fs.existsSync(config.privateDB)) fs.unlinkSync(config.privateDB);
|
if (fs.existsSync(config.privateDB)) fs.unlinkSync(config.privateDB);
|
||||||
|
|
||||||
await initDb();
|
await initDb();
|
||||||
|
|
||||||
const dbMode = config.mysql ? 'mysql'
|
const dbMode = config.mysql ? 'mysql'
|
||||||
: config.postgres ? 'postgres'
|
: config.postgres ? 'postgres'
|
||||||
: 'sqlite'
|
: 'sqlite';
|
||||||
Logger.info('Database Mode: ' + dbMode)
|
Logger.info('Database Mode: ' + dbMode);
|
||||||
|
|
||||||
// Instantiate a Mocha instance.
|
// Instantiate a Mocha instance.
|
||||||
const mocha = new Mocha();
|
const mocha = new Mocha();
|
||||||
|
|||||||
Reference in New Issue
Block a user