mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-24 16:38:41 +03:00
add more testing, change enabled
- add 404 if channelID cannot be dervived - added response message on success returning channel name - test limits of temp VIP - minor eslint
This commit is contained in:
@@ -45,7 +45,7 @@ import { youtubeApiProxy } from "./routes/youtubeApiProxy";
|
||||
import { getChapterNames } from "./routes/getChapterNames";
|
||||
import { postRating } from "./routes/ratings/postRating";
|
||||
import { getRating } from "./routes/ratings/getRating";
|
||||
import { postClearCache as ratingPostClearCache } from "./routes/ratings/postClearCache"
|
||||
import { postClearCache as ratingPostClearCache } from "./routes/ratings/postClearCache";
|
||||
import { getTopCategoryUsers } from "./routes/getTopCategoryUsers";
|
||||
import { addUserAsTempVIP } from "./routes/addUserAsTempVIP";
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ export async function addUserAsTempVIP(req: AddUserAsTempVIPRequest, res: Respon
|
||||
const enabled = req.query?.enabled === "true";
|
||||
const channelVideoID = req.query?.channelVideoID as VideoID;
|
||||
|
||||
if (!userID || !adminUserID || !channelVideoID ) {
|
||||
if ((!userID || !adminUserID || (!channelVideoID && enabled))) {
|
||||
// invalid request
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
@@ -57,15 +57,19 @@ export async function addUserAsTempVIP(req: AddUserAsTempVIPRequest, res: Respon
|
||||
}
|
||||
|
||||
const startTime = Date.now();
|
||||
const dayInSeconds = 86400;
|
||||
const channelInfo = await getChannelInfo(channelVideoID);
|
||||
|
||||
await privateDB.prepare("run", `INSERT INTO "tempVipLog" VALUES (?, ?, ?, ?)`, [adminUserID, userID, + enabled, startTime]);
|
||||
if (enabled) { // add to redis
|
||||
if (enabled) {
|
||||
const dayInSeconds = 86400;
|
||||
const channelInfo = await getChannelInfo(channelVideoID);
|
||||
if (!channelInfo?.id) {
|
||||
return res.status(404).send(`No channel found for videoID ${channelVideoID}`);
|
||||
}
|
||||
await redis.setAsyncEx(tempVIPKey(userID), channelInfo?.id, dayInSeconds);
|
||||
} else { // delete key
|
||||
await redis.delAsync(tempVIPKey(userID));
|
||||
await privateDB.prepare("run", `INSERT INTO "tempVipLog" VALUES (?, ?, ?, ?)`, [adminUserID, userID, + enabled, startTime]);
|
||||
return res.status(200).send(`Temp VIP added on channel ${channelInfo?.name}`);
|
||||
}
|
||||
|
||||
return res.sendStatus(200);
|
||||
await redis.delAsync(tempVIPKey(userID));
|
||||
await privateDB.prepare("run", `INSERT INTO "tempVipLog" VALUES (?, ?, ?, ?)`, [adminUserID, userID, + enabled, startTime]);
|
||||
return res.status(200).send(`Temp VIP removed`);
|
||||
}
|
||||
Reference in New Issue
Block a user