Add post for actionType

untested
This commit is contained in:
Ajay Ramachandran 2021-07-04 18:35:15 -04:00
parent 43ae471038
commit d20320e87e
3 changed files with 51 additions and 6 deletions

View file

@ -0,0 +1,32 @@
BEGIN TRANSACTION;
/* Add actionType field */
CREATE TABLE "sqlb_temp_table_18" (
"videoID" TEXT NOT NULL,
"startTime" REAL NOT NULL,
"endTime" REAL NOT NULL,
"votes" INTEGER NOT NULL,
"locked" INTEGER NOT NULL default '0',
"incorrectVotes" INTEGER NOT NULL default '1',
"UUID" TEXT NOT NULL UNIQUE,
"userID" TEXT NOT NULL,
"timeSubmitted" INTEGER NOT NULL,
"views" INTEGER NOT NULL,
"category" TEXT NOT NULL DEFAULT 'sponsor',
"actionType" TEXT NOT NULL DEFAULT 'skip',
"service" TEXT NOT NULL DEFAULT 'YouTube',
"videoDuration" REAL NOT NULL DEFAULT '0',
"hidden" INTEGER NOT NULL DEFAULT '0',
"reputation" REAL NOT NULL DEFAULT 0,
"shadowHidden" INTEGER NOT NULL,
"hashedVideoID" TEXT NOT NULL default ''
);
INSERT INTO sqlb_temp_table_18 SELECT "videoID","startTime","endTime","votes","locked","incorrectVotes","UUID","userID","timeSubmitted","views","category",'skip',"service","videoDuration","hidden","reputation","shadowHidden","hashedVideoID" FROM "sponsorTimes";
DROP TABLE "sponsorTimes";
ALTER TABLE sqlb_temp_table_18 RENAME TO "sponsorTimes";
UPDATE "config" SET value = 18 WHERE key = 'version';
COMMIT;

View file

@ -10,7 +10,7 @@ import {getFormattedTime} from '../utils/getFormattedTime';
import {isUserTrustworthy} from '../utils/isUserTrustworthy'; import {isUserTrustworthy} from '../utils/isUserTrustworthy';
import {dispatchEvent} from '../utils/webhookUtils'; import {dispatchEvent} from '../utils/webhookUtils';
import {Request, Response} from 'express'; import {Request, Response} from 'express';
import { Category, CategoryActionType, IncomingSegment, SegmentUUID, Service, VideoDuration, VideoID } from '../types/segments.model'; import { ActionType, Category, CategoryActionType, IncomingSegment, SegmentUUID, Service, VideoDuration, VideoID } from '../types/segments.model';
import { deleteLockCategories } from './deleteLockCategories'; import { deleteLockCategories } from './deleteLockCategories';
import { getCategoryActionType } from '../utils/categoryInfo'; import { getCategoryActionType } from '../utils/categoryInfo';
import { QueryCacher } from '../utils/queryCacher'; import { QueryCacher } from '../utils/queryCacher';
@ -315,7 +315,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
const videoID = req.query.videoID || req.body.videoID; const videoID = req.query.videoID || req.body.videoID;
let userID = req.query.userID || req.body.userID; let userID = req.query.userID || req.body.userID;
let service: Service = req.query.service ?? req.body.service ?? Service.YouTube; let service: Service = req.query.service ?? req.body.service ?? Service.YouTube;
if (!Object.values(Service).some((val) => val == service)) { if (!Object.values(Service).some((val) => val === service)) {
service = Service.YouTube; service = Service.YouTube;
} }
let videoDuration: VideoDuration = (parseFloat(req.query.videoDuration || req.body.videoDuration) || 0) as VideoDuration; let videoDuration: VideoDuration = (parseFloat(req.query.videoDuration || req.body.videoDuration) || 0) as VideoDuration;
@ -325,9 +325,16 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
// Use query instead // Use query instead
segments = [{ segments = [{
segment: [req.query.startTime as string, req.query.endTime as string], segment: [req.query.startTime as string, req.query.endTime as string],
category: req.query.category as Category category: req.query.category as Category,
actionType: (req.query.actionType as ActionType) ?? ActionType.Skip
}]; }];
} }
// Add default action type
segments.forEach((segment) => {
if (!Object.values(ActionType).some((val) => val === segment.actionType)){
segment.actionType = ActionType.Skip;
}
});
const invalidFields = []; const invalidFields = [];
if (typeof videoID !== 'string') { if (typeof videoID !== 'string') {
@ -518,9 +525,9 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
const startingLocked = isVIP ? 1 : 0; const startingLocked = isVIP ? 1 : 0;
try { try {
await db.prepare('run', `INSERT INTO "sponsorTimes" await db.prepare('run', `INSERT INTO "sponsorTimes"
("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "service", "videoDuration", "reputation", "shadowHidden", "hashedVideoID") ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "reputation", "shadowHidden", "hashedVideoID")
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
videoID, segmentInfo.segment[0], segmentInfo.segment[1], startingVotes, startingLocked, UUID, userID, timeSubmitted, 0, segmentInfo.category, service, videoDuration, reputation, shadowBanned, hashedVideoID, videoID, segmentInfo.segment[0], segmentInfo.segment[1], startingVotes, startingLocked, UUID, userID, timeSubmitted, 0, segmentInfo.category, segmentInfo.actionType, service, videoDuration, reputation, shadowBanned, hashedVideoID,
], ],
); );

View file

@ -10,6 +10,11 @@ export type VideoIDHash = VideoID & HashedValue;
export type IPAddress = string & { __ipAddressBrand: unknown }; export type IPAddress = string & { __ipAddressBrand: unknown };
export type HashedIP = IPAddress & HashedValue; export type HashedIP = IPAddress & HashedValue;
export enum ActionType {
Skip = "skip",
Mute = "mute",
}
// Uncomment as needed // Uncomment as needed
export enum Service { export enum Service {
YouTube = 'YouTube', YouTube = 'YouTube',
@ -23,6 +28,7 @@ export enum Service {
export interface IncomingSegment { export interface IncomingSegment {
category: Category; category: Category;
actionType: ActionType;
segment: string[]; segment: string[];
} }