mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-11 22:17:14 +03:00
migrate to typescript
This commit is contained in:
committed by
Dainius Dauksevicius
parent
c462323dd5
commit
08d27265fc
31
src/routes/getSkipSegmentsByHash.ts
Normal file
31
src/routes/getSkipSegmentsByHash.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import {hashPrefixTester} from '../utils/hashPrefixTester';
|
||||
import {cleanGetSegments} from './getSkipSegments';
|
||||
import {db} from '../databases/databases';
|
||||
import {Request, Response} from 'express';
|
||||
|
||||
export async function getSkipSegmentsByHash(req: Request, res: Response) {
|
||||
let hashPrefix = req.params.prefix;
|
||||
if (!hashPrefixTester(req.params.prefix)) {
|
||||
res.status(400).send("Hash prefix does not match format requirements."); // Exit early on faulty prefix
|
||||
return;
|
||||
}
|
||||
|
||||
const categories = req.query.categories
|
||||
? JSON.parse(req.query.categories as string)
|
||||
: req.query.category
|
||||
? [req.query.category]
|
||||
: ['sponsor'];
|
||||
|
||||
// Get all video id's that match hash prefix
|
||||
const videoIds = db.prepare('all', 'SELECT DISTINCT videoId, hashedVideoID from sponsorTimes WHERE hashedVideoID LIKE ?', [hashPrefix + '%']);
|
||||
|
||||
let segments = videoIds.map((video: any) => {
|
||||
return {
|
||||
videoID: video.videoID,
|
||||
hash: video.hashedVideoID,
|
||||
segments: cleanGetSegments(req, video.videoID, categories),
|
||||
};
|
||||
});
|
||||
|
||||
res.status((segments.length === 0) ? 404 : 200).json(segments);
|
||||
}
|
||||
Reference in New Issue
Block a user