Support commas in timestamps

This commit is contained in:
Ajay Ramachandran
2021-08-10 23:12:20 -04:00
parent f24c962785
commit 1cbd162a22
2 changed files with 30 additions and 0 deletions

View File

@@ -548,6 +548,8 @@ function preprocessInput(req: Request) {
if (!Object.values(ActionType).some((val) => val === segment.actionType)){ if (!Object.values(ActionType).some((val) => val === segment.actionType)){
segment.actionType = ActionType.Skip; segment.actionType = ActionType.Skip;
} }
segment.segment = segment.segment.map((time) => typeof segment.segment[0] === "string" ? time?.replace(",", ".") : time);
}); });
const userAgent = req.query.userAgent ?? req.body.userAgent ?? parseUserAgent(req.get("user-agent")) ?? ""; const userAgent = req.query.userAgent ?? req.body.userAgent ?? parseUserAgent(req.get("user-agent")) ?? "";

View File

@@ -959,4 +959,32 @@ describe("postSkipSegments", () => {
}) })
.catch(err => done(err)); .catch(err => done(err));
}); });
it("Should be able to submit with commas in timestamps", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
videoID: "commas-1",
segments: [{
segment: ["0,2", "10,392"],
category: "sponsor",
}]
}),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["commas-1"]);
const expected = {
startTime: 0.2,
endTime: 10.392
};
assert.ok(partialDeepEquals(row, expected));
done();
})
.catch(err => done(err));
});
}); });