Store video info from submissions

This commit is contained in:
Ajay Ramachandran 2021-10-17 14:42:48 -04:00
parent bda2ff4d23
commit 450f4a2d44
4 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,13 @@
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "videoInfo" (
"videoID" TEXT PRIMARY KEY NOT NULL,
"channelID" TEXT NOT NULL,
"title" TEXT NOT NULL,
"published" REAL NOT NULL,
"genreUrl" REAL NOT NULL
);
UPDATE "config" SET value = 25 WHERE key = 'version';
COMMIT;

View file

@ -651,6 +651,11 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
//add to private db as well
await privateDB.prepare("run", `INSERT INTO "sponsorTimes" VALUES(?, ?, ?, ?)`, [videoID, hashedIP, timeSubmitted, service]);
await db.prepare("run", `INSERT INTO "videoInfo" ("videoID", "channelID", "title", "published", "genreUrl")
SELECT ?, ?, ?, ?, ?
WHERE NOT EXISTS (SELECT 1 FROM "videoInfo" WHERE "videoID" = ?)`, [
videoID, apiVideoInfo?.data?.authorId || "", apiVideoInfo?.data?.title || "", apiVideoInfo?.data?.published || 0, apiVideoInfo?.data?.genreUrl || "", videoID]);
// Clear redis cache for this video
QueryCacher.clearVideoCache({
videoID,

View file

@ -35,6 +35,7 @@ describe("postSkipSegments", () => {
const queryDatabase = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
const queryDatabaseActionType = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
const queryDatabaseDuration = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
const queryDatabaseVideoInfo = (videoID: string) => db.prepare("get", `SELECT * FROM "videoInfo" WHERE "videoID" = ?`, [videoID]);
const endpoint = "/api/skipSegments";
const postSkipSegmentJSON = (data: Record<string, any>) => client({
@ -107,6 +108,17 @@ describe("postSkipSegments", () => {
category: "sponsor",
};
assert.ok(partialDeepEquals(row, expected));
const videoInfo = await queryDatabaseVideoInfo(videoID);
const expectedVideoInfo = {
videoID,
title: "Example Title",
channelID: "ExampleChannel",
published: 123,
genreUrl: ""
};
assert.ok(partialDeepEquals(videoInfo, expectedVideoInfo));
done();
})
.catch(err => done(err));

View file

@ -35,6 +35,8 @@ export class YouTubeApiMock {
err: null,
data: {
title: "Example Title",
authorId: "ExampleChannel",
published: 123,
lengthSeconds: 4980,
videoThumbnails: [
{