mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-24 08:28:27 +03:00
getChapterNames
- remove identifier from segmentGen - add multiGenRandomValue - add videoInfo query
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import crypto from "crypto";
|
||||
|
||||
export const genRandom = (bytes=8) => crypto.pseudoRandomBytes(bytes).toString("hex");
|
||||
export const genRandom = (bytes=8): string => crypto.pseudoRandomBytes(bytes).toString("hex");
|
||||
|
||||
export const genRandomValue = (prefix: string, identifier: string, bytes=8) => `${prefix}-${identifier}-${genRandom(bytes)}`;
|
||||
export const genRandomValue = (prefix: string, identifier: string, bytes=8): string => `${prefix}-${identifier}-${genRandom(bytes)}`;
|
||||
export const multiGenRandomValue = (prefix: string, identifier: string, count: number, bytes=8): string[] => {
|
||||
const arr: string[] = [];
|
||||
for (let i = 0; i < count; i++) arr.push(genRandomValue(prefix, identifier, bytes));
|
||||
return arr;
|
||||
};
|
||||
@@ -39,3 +39,9 @@ export const insertUsernameBulk = async (db: IDatabase, users: usernameUserArray
|
||||
for (const user of Object.values(users))
|
||||
await insertUsername(db, user.pubID, user.username, false);
|
||||
};
|
||||
|
||||
// videoInfo
|
||||
export const insertVideoInfo = async (db: IDatabase, videoID: string, channelID: string, title = "", published = 0) => {
|
||||
const query = 'INSERT INTO "videoInfo" ("videoID", "channelID", "title", "published") VALUES(?, ?, ?, ?)';
|
||||
await db.prepare("run", query, [videoID, channelID, title, published]);
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IDatabase } from "../../src/databases/IDatabase";
|
||||
import { Service, VideoIDHash, VideoID } from "../../src/types/segments.model";
|
||||
import { HashedUserID, UserID } from "../../src/types/user.model";
|
||||
import { genRandomValue } from "./getRandom";
|
||||
import { genRandom, genRandomValue } from "./getRandom";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
|
||||
type insertSegmentParams = {
|
||||
@@ -43,12 +43,11 @@ const defaultSegmentParams: insertSegmentParams = {
|
||||
description: ""
|
||||
};
|
||||
|
||||
// sponsorTimes
|
||||
export const insertSegment = async(db: IDatabase, fnname: string, testcase: string, params: insertSegmentParams = {}) => {
|
||||
export const insertSegment = async(db: IDatabase, params: insertSegmentParams = {}) => {
|
||||
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID", "description") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
// corrections for parameters
|
||||
const identifier = `${fnname}-${testcase}`;
|
||||
const correctedParams = { ...defaultSegmentParams, ...params };
|
||||
const identifier = genRandom(7); // 7 to fill out videoID
|
||||
// generate defaults
|
||||
const videoID = (params.videoID || `vid-${identifier}`) as VideoID;
|
||||
const userID = (params.userID || `user-${identifier}`) as UserID;
|
||||
@@ -61,4 +60,8 @@ export const insertSegment = async(db: IDatabase, fnname: string, testcase: stri
|
||||
correctedParams.hidden = Number(correctedParams.hidden);
|
||||
correctedParams.shadowHidden = Number(correctedParams.shadowHidden);
|
||||
await db.prepare("run", query, Object.values(correctedParams));
|
||||
};
|
||||
export const insertChapter = async(db: IDatabase, description: string, params: insertSegmentParams = {}) => {
|
||||
const overrides = { category: "chapter", actionType: "chapter", description, ...params };
|
||||
await insertSegment(db, overrides);
|
||||
};
|
||||
Reference in New Issue
Block a user