Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into stricter-eslint

This commit is contained in:
Michael C
2021-07-18 02:27:48 -04:00
6 changed files with 87 additions and 12 deletions

View File

@@ -56,8 +56,12 @@ export const archiveDownvoteSegment = async (dayLimit: number, voteLimit: number
};
const DownvoteSegmentArchiveJob = new CronJob(
jobConfig?.schedule || new Date(1),
jobConfig?.schedule || "0 0 * * * 0",
() => archiveDownvoteSegment(jobConfig?.timeThresholdInDays, jobConfig?.voteThreshold)
);
if (serverConfig?.crons?.enabled && jobConfig && !jobConfig.schedule) {
Logger.error("Invalid cron schedule for downvoteSegmentArchive");
}
export default DownvoteSegmentArchiveJob;

View File

@@ -338,11 +338,13 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
});
const invalidFields = [];
const errors = [];
if (typeof videoID !== "string") {
invalidFields.push("videoID");
}
if (typeof userID !== "string" || userID.length < 30) {
invalidFields.push("userID");
if (userID.length < 30) errors.push(`userID must be at least 30 characters long`);
}
if (!Array.isArray(segments) || segments.length < 1) {
invalidFields.push("segments");
@@ -350,8 +352,9 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
if (invalidFields.length !== 0) {
// invalid request
const fields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ", " : "") + c, "");
return res.status(400).send(`No valid ${fields} field(s) provided`);
const formattedFields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ", " : "") + c, "");
const formattedErrors = errors.reduce((p, c, i) => p + (i !== 0 ? ". " : " ") + c, "");
return res.status(400).send(`No valid ${formattedFields} field(s) provided.${formattedErrors}`);
}
//hash the userID

View File

@@ -62,7 +62,7 @@ export async function setUsername(req: Request, res: Response): Promise<Response
const locked = adminUserIDInput === undefined ? 0 : 1;
let oldUserName = "";
if (row?.userName?.length > 0) {
if (row?.userName !== undefined) {
//already exists, update this row
oldUserName = row.userName;
await db.prepare("run", `UPDATE "userNames" SET "userName" = ?, "locked" = ? WHERE "userID" = ?`, [userName, locked, userID]);

View File

@@ -256,6 +256,10 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
//invalid request
return res.sendStatus(400);
}
if (paramUserID.length < 30 && config.mode !== "test") {
// Ignore this vote, invalid
return res.sendStatus(200);
}
//hash the userID
const nonAnonUserID = getHash(paramUserID);
@@ -426,7 +430,7 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
if (isVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) {
// Unide and Lock this submission
await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 1, hidden = 0 WHERE "UUID" = ?', [UUID]);
} else if (isVIP && incrementAmount < 0 && voteTypeEnum === voteTypes.normal) {
} else if (isVIP && incrementAmount <= 0 && voteTypeEnum === voteTypes.normal) {
// Unlock if a VIP downvotes it
await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 0 WHERE "UUID" = ?', [UUID]);
}