mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 15:06:59 +03:00
added tests and route
This commit is contained in:
@@ -29,6 +29,7 @@ import {apiCspMiddleware} from './middleware/apiCsp';
|
||||
import {rateLimitMiddleware} from './middleware/requestRateLimit';
|
||||
import dumpDatabase, {redirectLink} from './routes/dumpDatabase';
|
||||
import {endpoint as getSegmentInfo} from './routes/getSegmentInfo';
|
||||
import {postClearCache} from './routes/postClearCache';
|
||||
|
||||
export function createServer(callback: () => void) {
|
||||
// Create a service (the app object is just a callback).
|
||||
@@ -136,6 +137,9 @@ function setupRoutes(app: Express) {
|
||||
//get segment info
|
||||
app.get('/api/segmentInfo', getSegmentInfo);
|
||||
|
||||
//clear cache as VIP
|
||||
app.post('/api/clearCache', postClearCache)
|
||||
|
||||
if (config.postgres) {
|
||||
app.get('/database', (req, res) => dumpDatabase(req, res, true));
|
||||
app.get('/database.json', (req, res) => dumpDatabase(req, res, false));
|
||||
|
||||
@@ -9,7 +9,9 @@ import { UserID } from '../types/user.model';
|
||||
export async function postClearCache(req: Request, res: Response) {
|
||||
const videoID = req.query.videoID as VideoID;
|
||||
let userID = req.query.userID as UserID;
|
||||
let service = req.query.service as Service ?? Service.YouTube;
|
||||
const service = req.query.service as Service ?? Service.YouTube;
|
||||
// hash the userID as early as possible
|
||||
userID = getHash(userID);
|
||||
|
||||
const invalidFields = [];
|
||||
if (typeof videoID !== 'string') {
|
||||
@@ -26,8 +28,6 @@ export async function postClearCache(req: Request, res: Response) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// hash the userID
|
||||
userID = getHash(userID);
|
||||
// hash videoID
|
||||
const hashedVideoID = getHash(videoID, 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user