mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
add hashedVideoID to lockCategories
This commit is contained in:
parent
c2d4f2578c
commit
ede02eaa8c
2 changed files with 43 additions and 1 deletions
|
@ -3,6 +3,7 @@ import {getHash} from '../utils/getHash';
|
|||
import {isUserVIP} from '../utils/isUserVIP';
|
||||
import {db} from '../databases/databases';
|
||||
import {Request, Response} from 'express';
|
||||
import { VideoIDHash } from "../types/segments.model";
|
||||
|
||||
export async function postLockCategories(req: Request, res: Response): Promise<string[]> {
|
||||
// Collect user input data
|
||||
|
@ -56,10 +57,13 @@ export async function postLockCategories(req: Request, res: Response): Promise<s
|
|||
return categoriesToMark.indexOf(category) === index;
|
||||
});
|
||||
|
||||
// calculate hash of videoID
|
||||
const hashedVideoID: VideoIDHash = getHash(videoID, 1);
|
||||
|
||||
// create database entry
|
||||
for (const category of categoriesToMark) {
|
||||
try {
|
||||
await db.prepare('run', `INSERT INTO "lockCategories" ("videoID", "userID", "category") VALUES(?, ?, ?)`, [videoID, userID, category]);
|
||||
await db.prepare('run', `INSERT INTO "lockCategories" ("videoID", "userID", "category", "hashedVideoID") VALUES(?, ?, ?, ?)`, [videoID, userID, category, hashedVideoID]);
|
||||
} catch (err) {
|
||||
Logger.error("Error submitting 'lockCategories' marker for category '" + category + "' for video '" + videoID + "'");
|
||||
Logger.error(err);
|
||||
|
|
|
@ -536,4 +536,42 @@ describe('lockCategoriesRecords', () => {
|
|||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should be able to get existing category lock', (done: Done) => {
|
||||
const expected = {
|
||||
categories: [
|
||||
'sponsor',
|
||||
'intro',
|
||||
'outro',
|
||||
'shilling'
|
||||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/lockCategories?videoID=" + "no-segments-video-id")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const data = await res.json();
|
||||
if (JSON.stringify(data) === JSON.stringify(expected)) {
|
||||
done();
|
||||
} else {
|
||||
done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(data));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get hashedVideoID from lock', (done: Done) => {
|
||||
const hashedVideoID = getHash('no-segments-video-id', 1);
|
||||
db.prepare('get', 'SELECT "hashedVideoID" FROM "lockCategories" WHERE "videoID" = ?', ['no-segments-video-id'])
|
||||
.then(result => {
|
||||
if (result !== hashedVideoID) {
|
||||
done();
|
||||
} else {
|
||||
done("Got unexpected video hash " + result);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue