mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 12:07:07 +03:00
Add option to trim UUIDs in skip segments endpoint
This commit is contained in:
@@ -150,7 +150,7 @@ async function getSegmentsByVideoID(req: Request, videoID: VideoID, categories:
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getSegmentsByHash(req: Request, hashedVideoIDPrefix: VideoIDHash, categories: Category[],
|
async function getSegmentsByHash(req: Request, hashedVideoIDPrefix: VideoIDHash, categories: Category[],
|
||||||
actionTypes: ActionType[], requiredSegments: SegmentUUID[], service: Service): Promise<SBRecord<VideoID, VideoData>> {
|
actionTypes: ActionType[], trimUUIDs: number, requiredSegments: SegmentUUID[], service: Service): Promise<SBRecord<VideoID, VideoData>> {
|
||||||
const cache: SegmentCache = { shadowHiddenSegmentIPs: {} };
|
const cache: SegmentCache = { shadowHiddenSegmentIPs: {} };
|
||||||
const segments: SBRecord<VideoID, VideoData> = {};
|
const segments: SBRecord<VideoID, VideoData> = {};
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ async function getSegmentsByHash(req: Request, hashedVideoIDPrefix: VideoIDHash,
|
|||||||
category: segment.category,
|
category: segment.category,
|
||||||
actionType: segment.actionType,
|
actionType: segment.actionType,
|
||||||
segment: segment.segment,
|
segment: segment.segment,
|
||||||
UUID: segment.UUID,
|
UUID: trimUUIDs ? segment.UUID.substring(0, trimUUIDs) as SegmentUUID : segment.UUID,
|
||||||
videoDuration: segment.videoDuration,
|
videoDuration: segment.videoDuration,
|
||||||
locked: segment.locked,
|
locked: segment.locked,
|
||||||
votes: segment.votes,
|
votes: segment.votes,
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ export async function getSkipSegmentsByHash(req: Request, res: Response): Promis
|
|||||||
if (parseResult.errors.length > 0) {
|
if (parseResult.errors.length > 0) {
|
||||||
return res.status(400).send(parseResult.errors);
|
return res.status(400).send(parseResult.errors);
|
||||||
}
|
}
|
||||||
const { categories, actionTypes, requiredSegments, service } = parseResult;
|
const { categories, actionTypes, trimUUIDs, requiredSegments, service } = parseResult;
|
||||||
|
|
||||||
// Get all video id's that match hash prefix
|
// Get all video id's that match hash prefix
|
||||||
const segments = await getSegmentsByHash(req, hashPrefix, categories, actionTypes, requiredSegments, service);
|
const segments = await getSegmentsByHash(req, hashPrefix, categories, actionTypes, trimUUIDs, requiredSegments, service);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getEtag("skipSegmentsHash", hashPrefix, service)
|
await getEtag("skipSegmentsHash", hashPrefix, service)
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ const errorMessage = (parameter: string) => `${parameter} parameter does not mat
|
|||||||
export function parseSkipSegments(req: Request): {
|
export function parseSkipSegments(req: Request): {
|
||||||
categories: Category[];
|
categories: Category[];
|
||||||
actionTypes: ActionType[];
|
actionTypes: ActionType[];
|
||||||
|
trimUUIDs: number | null;
|
||||||
requiredSegments: SegmentUUID[];
|
requiredSegments: SegmentUUID[];
|
||||||
service: Service;
|
service: Service;
|
||||||
errors: string[];
|
errors: string[];
|
||||||
} {
|
} {
|
||||||
const categories: Category[] = parseCategories(req, [ "sponsor" as Category ]);
|
const categories: Category[] = parseCategories(req, [ "sponsor" as Category ]);
|
||||||
const actionTypes: ActionType[] = parseActionTypes(req, [ActionType.Skip]);
|
const actionTypes: ActionType[] = parseActionTypes(req, [ActionType.Skip]);
|
||||||
|
const trimUUIDs: number | null = req.query.trimUUIDs ? (parseInt(req.query.trimUUIDs as string) || null) : null;
|
||||||
const requiredSegments: SegmentUUID[] = parseRequiredSegments(req);
|
const requiredSegments: SegmentUUID[] = parseRequiredSegments(req);
|
||||||
const service: Service = getService(req.query.service, req.body.services);
|
const service: Service = getService(req.query.service, req.body.services);
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
@@ -27,6 +29,7 @@ export function parseSkipSegments(req: Request): {
|
|||||||
return {
|
return {
|
||||||
categories,
|
categories,
|
||||||
actionTypes,
|
actionTypes,
|
||||||
|
trimUUIDs,
|
||||||
requiredSegments,
|
requiredSegments,
|
||||||
service,
|
service,
|
||||||
errors
|
errors
|
||||||
|
|||||||
Reference in New Issue
Block a user