getLockCategoresByHash

This commit is contained in:
Michael C
2021-07-04 23:33:12 -04:00
parent 719a0956ac
commit a860e96d35
6 changed files with 189 additions and 5 deletions

View File

@@ -0,0 +1,27 @@
import {db} from '../databases/databases';
import {Logger} from '../utils/logger';
import {Request, Response} from 'express';
import {hashPrefixTester} from '../utils/hashPrefixTester';
import { Category, VideoID, VideoIDHash } from "../types/segments.model";
import { UserID } from '../types/user.model';
export async function getLockCategoriesByHash(req: Request, res: Response): Promise<Response> {
let hashPrefix = req.params.prefix as VideoIDHash;
if (!hashPrefixTester(req.params.prefix)) {
return res.status(400).send("Hash prefix does not match format requirements."); // Exit early on faulty prefix
}
hashPrefix = hashPrefix.toLowerCase() as VideoIDHash;
try {
// Get existing lock categories markers
let lockCategoryList = await db.prepare('all', 'SELECT * from "lockCategories" where "hashedVideoID" LIKE ? ORDER BY videoID', [hashPrefix + '%']) as {videoID: VideoID, userID: UserID,category: Category}[]
if (lockCategoryList.length === 0 || !lockCategoryList[0]) {
return res.sendStatus(404);
} else {
return res.send(lockCategoryList)
}
} catch (err) {
Logger.error(err);
return res.sendStatus(500);
}
}