Add more unlock calls

This commit is contained in:
Ajay 2023-07-23 23:32:38 -04:00
parent 8d518b184b
commit a52ecf2d37
2 changed files with 17 additions and 1 deletions

View file

@ -526,12 +526,14 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
// Check if all submissions are correct // Check if all submissions are correct
const segmentCheckResult = await checkEachSegmentValid(rawIP, paramUserID, userID, videoID, segments, service, isVIP, isTempVIP, lockedCategoryList); const segmentCheckResult = await checkEachSegmentValid(rawIP, paramUserID, userID, videoID, segments, service, isVIP, isTempVIP, lockedCategoryList);
if (!segmentCheckResult.pass) { if (!segmentCheckResult.pass) {
lock.unlock();
return res.status(segmentCheckResult.errorCode).send(segmentCheckResult.errorMessage); return res.status(segmentCheckResult.errorCode).send(segmentCheckResult.errorMessage);
} }
if (!(isVIP || isTempVIP)) { if (!(isVIP || isTempVIP)) {
const autoModerateCheckResult = await checkByAutoModerator(videoID, userID, segments, service, apiVideoDetails, videoDurationParam); const autoModerateCheckResult = await checkByAutoModerator(videoID, userID, segments, service, apiVideoDetails, videoDurationParam);
if (!autoModerateCheckResult.pass) { if (!autoModerateCheckResult.pass) {
lock.unlock();
return res.status(autoModerateCheckResult.errorCode).send(autoModerateCheckResult.errorMessage); return res.status(autoModerateCheckResult.errorCode).send(autoModerateCheckResult.errorMessage);
} }
} }
@ -607,6 +609,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
} catch (err) { } catch (err) {
//a DB change probably occurred //a DB change probably occurred
Logger.error(`Error when putting sponsorTime in the DB: ${videoID}, ${segmentInfo.segment[0]}, ${segmentInfo.segment[1]}, ${userID}, ${segmentInfo.category}. ${err}`); Logger.error(`Error when putting sponsorTime in the DB: ${videoID}, ${segmentInfo.segment[0]}, ${segmentInfo.segment[1]}, ${userID}, ${segmentInfo.category}. ${err}`);
lock.unlock();
return res.sendStatus(500); return res.sendStatus(500);
} }
@ -619,6 +622,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
} }
} catch (err) { } catch (err) {
Logger.error(err as string); Logger.error(err as string);
lock.unlock();
return res.sendStatus(500); return res.sendStatus(500);
} }

View file

@ -356,6 +356,7 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
const segmentInfo: DBSegment = await db.prepare("get", `SELECT * from "sponsorTimes" WHERE "UUID" = ?`, [UUID]); const segmentInfo: DBSegment = await db.prepare("get", `SELECT * from "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
// segment doesnt exist // segment doesnt exist
if (!segmentInfo) { if (!segmentInfo) {
lock.unlock();
return { status: 404 }; return { status: 404 };
} }
@ -367,6 +368,7 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
// disallow vote types 10/11 // disallow vote types 10/11
if (type === 10 || type === 11) { if (type === 10 || type === 11) {
lock.unlock();
return { status: 400 }; return { status: 400 };
} }
@ -385,7 +387,10 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
// no type but has category, categoryVote // no type but has category, categoryVote
if (!type && category) { if (!type && category) {
return categoryVote(UUID, nonAnonUserID, isVIP, isTempVIP, isOwnSubmission, category, hashedIP, finalResponse); const result = categoryVote(UUID, nonAnonUserID, isVIP, isTempVIP, isOwnSubmission, category, hashedIP, finalResponse);
lock.unlock();
return result;
} }
// If not upvote, or an upvote on a dead segment (for ActionType.Full) // If not upvote, or an upvote on a dead segment (for ActionType.Full)
@ -405,8 +410,11 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
if (!isNaN(type) && segmentInfo.votes <= -2 && segmentInfo.actionType !== ActionType.Full && if (!isNaN(type) && segmentInfo.votes <= -2 && segmentInfo.actionType !== ActionType.Full &&
!(isVIP || isTempVIP || isOwnSubmission)) { !(isVIP || isTempVIP || isOwnSubmission)) {
if (type == 1) { if (type == 1) {
lock.unlock();
return { status: 403, message: "Not allowed to upvote segment with too many downvotes unless you are VIP." }; return { status: 403, message: "Not allowed to upvote segment with too many downvotes unless you are VIP." };
} else if (type == 0) { } else if (type == 0) {
lock.unlock();
// Already downvoted enough, ignore // Already downvoted enough, ignore
return { status: 200 }; return { status: 200 };
} }
@ -439,6 +447,8 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
//undo/cancel vote //undo/cancel vote
incrementAmount = 0; incrementAmount = 0;
} else { } else {
lock.unlock();
//unrecongnised type of vote //unrecongnised type of vote
return { status: 400 }; return { status: 400 };
} }
@ -537,6 +547,8 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
return { status: finalResponse.finalStatus, message: finalResponse.finalMessage ?? undefined }; return { status: finalResponse.finalStatus, message: finalResponse.finalMessage ?? undefined };
} catch (err) { } catch (err) {
lock.unlock();
Logger.error(err as string); Logger.error(err as string);
return { status: 500, message: finalResponse.finalMessage ?? undefined, json: { error: "Internal error creating segment vote" } }; return { status: 500, message: finalResponse.finalMessage ?? undefined, json: { error: "Internal error creating segment vote" } };
} }