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
const segmentCheckResult = await checkEachSegmentValid(rawIP, paramUserID, userID, videoID, segments, service, isVIP, isTempVIP, lockedCategoryList);
if (!segmentCheckResult.pass) {
lock.unlock();
return res.status(segmentCheckResult.errorCode).send(segmentCheckResult.errorMessage);
}
if (!(isVIP || isTempVIP)) {
const autoModerateCheckResult = await checkByAutoModerator(videoID, userID, segments, service, apiVideoDetails, videoDurationParam);
if (!autoModerateCheckResult.pass) {
lock.unlock();
return res.status(autoModerateCheckResult.errorCode).send(autoModerateCheckResult.errorMessage);
}
}
@ -607,6 +609,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
} catch (err) {
//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}`);
lock.unlock();
return res.sendStatus(500);
}
@ -619,6 +622,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
}
} catch (err) {
Logger.error(err as string);
lock.unlock();
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]);
// segment doesnt exist
if (!segmentInfo) {
lock.unlock();
return { status: 404 };
}
@ -367,6 +368,7 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
// disallow vote types 10/11
if (type === 10 || type === 11) {
lock.unlock();
return { status: 400 };
}
@ -385,7 +387,10 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
// no type but has category, categoryVote
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)
@ -405,8 +410,11 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
if (!isNaN(type) && segmentInfo.votes <= -2 && segmentInfo.actionType !== ActionType.Full &&
!(isVIP || isTempVIP || isOwnSubmission)) {
if (type == 1) {
lock.unlock();
return { status: 403, message: "Not allowed to upvote segment with too many downvotes unless you are VIP." };
} else if (type == 0) {
lock.unlock();
// Already downvoted enough, ignore
return { status: 200 };
}
@ -439,6 +447,8 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
//undo/cancel vote
incrementAmount = 0;
} else {
lock.unlock();
//unrecongnised type of vote
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 };
} catch (err) {
lock.unlock();
Logger.error(err as string);
return { status: 500, message: finalResponse.finalMessage ?? undefined, json: { error: "Internal error creating segment vote" } };
}