mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Store video info from submissions
This commit is contained in:
parent
bda2ff4d23
commit
450f4a2d44
4 changed files with 32 additions and 0 deletions
13
databases/_upgrade_sponsorTimes_25.sql
Normal file
13
databases/_upgrade_sponsorTimes_25.sql
Normal 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;
|
|
@ -651,6 +651,11 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
||||||
//add to private db as well
|
//add to private db as well
|
||||||
await privateDB.prepare("run", `INSERT INTO "sponsorTimes" VALUES(?, ?, ?, ?)`, [videoID, hashedIP, timeSubmitted, service]);
|
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
|
// Clear redis cache for this video
|
||||||
QueryCacher.clearVideoCache({
|
QueryCacher.clearVideoCache({
|
||||||
videoID,
|
videoID,
|
||||||
|
|
|
@ -35,6 +35,7 @@ describe("postSkipSegments", () => {
|
||||||
const queryDatabase = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
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 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 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 endpoint = "/api/skipSegments";
|
||||||
const postSkipSegmentJSON = (data: Record<string, any>) => client({
|
const postSkipSegmentJSON = (data: Record<string, any>) => client({
|
||||||
|
@ -107,6 +108,17 @@ describe("postSkipSegments", () => {
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(row, expected));
|
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();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
|
|
|
@ -35,6 +35,8 @@ export class YouTubeApiMock {
|
||||||
err: null,
|
err: null,
|
||||||
data: {
|
data: {
|
||||||
title: "Example Title",
|
title: "Example Title",
|
||||||
|
authorId: "ExampleChannel",
|
||||||
|
published: 123,
|
||||||
lengthSeconds: 4980,
|
lengthSeconds: 4980,
|
||||||
videoThumbnails: [
|
videoThumbnails: [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue