mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 12:07:07 +03:00
Make hasStartSegment result optional
This commit is contained in:
@@ -34,7 +34,7 @@ async function getLabelsByVideoID(videoID: VideoID, service: Service): Promise<F
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLabelsByHash(hashedVideoIDPrefix: VideoIDHash, service: Service): Promise<SBRecord<VideoID, FullVideoSegmentVideoData>> {
|
async function getLabelsByHash(hashedVideoIDPrefix: VideoIDHash, service: Service, checkHasStartSegment: boolean): Promise<SBRecord<VideoID, FullVideoSegmentVideoData>> {
|
||||||
const segments: SBRecord<VideoID, FullVideoSegmentVideoData> = {};
|
const segments: SBRecord<VideoID, FullVideoSegmentVideoData> = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -57,10 +57,10 @@ async function getLabelsByHash(hashedVideoIDPrefix: VideoIDHash, service: Servic
|
|||||||
const result = chooseSegment(videoData.segments);
|
const result = chooseSegment(videoData.segments);
|
||||||
const data: FullVideoSegmentVideoData = {
|
const data: FullVideoSegmentVideoData = {
|
||||||
segments: result.segments,
|
segments: result.segments,
|
||||||
hasStartSegment: result.hasStartSegment
|
hasStartSegment: checkHasStartSegment ? result.hasStartSegment : undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
if (data.segments.length > 0 || data.hasStartSegment) {
|
if (data.segments.length > 0 || (data.hasStartSegment && checkHasStartSegment)) {
|
||||||
segments[videoID] = data;
|
segments[videoID] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ async function handleGetLabel(req: Request, res: Response): Promise<FullVideoSeg
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasStartSegment = !!req.query.hasStartSegment;
|
const hasStartSegment = req.query.hasStartSegment === "true";
|
||||||
|
|
||||||
const service = getService(req.query.service, req.body.service);
|
const service = getService(req.query.service, req.body.service);
|
||||||
const segmentData = await getLabelsByVideoID(videoID, service);
|
const segmentData = await getLabelsByVideoID(videoID, service);
|
||||||
|
|||||||
@@ -11,10 +11,12 @@ export async function getVideoLabelsByHash(req: Request, res: Response): Promise
|
|||||||
}
|
}
|
||||||
hashPrefix = hashPrefix.toLowerCase() as VideoIDHash;
|
hashPrefix = hashPrefix.toLowerCase() as VideoIDHash;
|
||||||
|
|
||||||
|
const checkHasStartSegment = req.query.hasStartSegment === "true";
|
||||||
|
|
||||||
const service: Service = getService(req.query.service, req.body.service);
|
const service: Service = getService(req.query.service, req.body.service);
|
||||||
|
|
||||||
// Get all video id's that match hash prefix
|
// Get all video id's that match hash prefix
|
||||||
const segments = await getLabelsByHash(hashPrefix, service);
|
const segments = await getLabelsByHash(hashPrefix, service, checkHasStartSegment);
|
||||||
|
|
||||||
if (!segments) return res.status(404).json([]);
|
if (!segments) return res.status(404).json([]);
|
||||||
|
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ describe("getVideoLabelHash", () => {
|
|||||||
assert.strictEqual(data[0].segments.length, 1);
|
assert.strictEqual(data[0].segments.length, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const get = (videoID: string) => client.get(`${endpoint}/${getHash(videoID, 1).substring(0, 4)}`);
|
const get = (videoID: string, hasStartSegment = false) => client.get(`${endpoint}/${getHash(videoID, 1).substring(0, 4)}?hasStartSegment=${hasStartSegment}`);
|
||||||
|
|
||||||
it("Should be able to get sponsor only label", (done) => {
|
it("Should be able to get sponsor only label", (done) => {
|
||||||
const videoID = "getLabelHashSponsor";
|
const videoID = "getLabelHashSponsor";
|
||||||
get(videoID)
|
get(videoID, true)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = res.data;
|
const data = res.data;
|
||||||
@@ -55,7 +55,7 @@ describe("getVideoLabelHash", () => {
|
|||||||
|
|
||||||
it("Should be able to get exclusive access only label", (done) => {
|
it("Should be able to get exclusive access only label", (done) => {
|
||||||
const videoID = "getLabelHashEA";
|
const videoID = "getLabelHashEA";
|
||||||
get(videoID)
|
get(videoID, true)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = res.data;
|
const data = res.data;
|
||||||
@@ -77,6 +77,7 @@ describe("getVideoLabelHash", () => {
|
|||||||
validateLabel(data, videoID);
|
validateLabel(data, videoID);
|
||||||
const result = data[0].segments[0];
|
const result = data[0].segments[0];
|
||||||
assert.strictEqual(result.category, "selfpromo");
|
assert.strictEqual(result.category, "selfpromo");
|
||||||
|
assert.strictEqual(data[0].hasStartSegment, undefined);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
|
|||||||
Reference in New Issue
Block a user