Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/routes/postSkipSegments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { HashedUserID, UserID } from "../types/user.model";
import { isUserVIP } from "../utils/isUserVIP";
import { isUserTempVIP } from "../utils/isUserTempVIP";
import { parseUserAgent } from "../utils/userAgent";
import { getService } from "../utils/getService";
import { getService, getUnsupportedService } from "../utils/getService";
import axios from "axios";
import { vote } from "./voteOnSponsorTime";
import { canSubmit } from "../utils/permissions";
Expand Down Expand Up @@ -500,6 +500,11 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
proxySubmission(req);
}

const unsupportedService = getUnsupportedService(req.query.service, req.body.service);
if (unsupportedService) {
return res.status(400).send(`Service is not supported: ${unsupportedService}`);
}

// eslint-disable-next-line prefer-const
let { videoID, userID: paramUserID, service, videoDuration, videoDurationParam, segments, userAgent } = preprocessInput(req);

Expand Down
19 changes: 19 additions & 0 deletions src/utils/getService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,22 @@ export function getService<T extends string>(...value: T[]): Service {

return Service.YouTube;
}

export function getUnsupportedService<T extends string>(...value: T[]): string | null {
const serviceByName = Object.values(Service).reduce((acc, serviceName) => {
acc[serviceName.toLowerCase()] = serviceName;

return acc;
}, {} as Record<string, Service>);

let unsupportedValue;
for (const name of value) {
const cleanName = name?.trim().toLowerCase();
if (cleanName in serviceByName) {
return null;
}
if (cleanName) unsupportedValue = name;
}

return unsupportedValue;
}
18 changes: 18 additions & 0 deletions test/cases/postSkipSegments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,24 @@ describe("postSkipSegments", () => {
.catch(err => done(err));
});

it("Should not be able to submit with unknown service", (done) => {
const videoID = "colon-1";
postSkipSegmentJSON({
userID: submitUserOne,
videoID,
service:"Unsupported-xxx",
segments: [{
segment: ["0", "3"],
category: "sponsor",
}]
})
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});

it("Should throw 409 on duplicate submission", (done) => {
const videoID = "private-video";
postSkipSegmentParam({
Expand Down
Loading