mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-03-25 15:27:39 +03:00
Added youtube api cache (optional)
This commit is contained in:
@@ -48,10 +48,7 @@ function sendWebhooks(userID, videoID, UUID, segmentInfo) {
|
||||
if (config.youtubeAPIKey !== null) {
|
||||
let userSubmissionCountRow = db.prepare('get', "SELECT count(*) as submissionCount FROM sponsorTimes WHERE userID = ?", [userID]);
|
||||
|
||||
YouTubeAPI.videos.list({
|
||||
part: "snippet",
|
||||
id: videoID
|
||||
}, function (err, data) {
|
||||
YouTubeAPI.listVideos(videoID, "snippet", (err, data) => {
|
||||
if (err || data.items.length === 0) {
|
||||
err && logger.error(err);
|
||||
return;
|
||||
@@ -108,10 +105,7 @@ async function autoModerateSubmission(submission, callback) {
|
||||
// Get the video information from the youtube API
|
||||
if (config.youtubeAPIKey !== null) {
|
||||
let {err, data} = await new Promise((resolve, reject) => {
|
||||
YouTubeAPI.videos.list({
|
||||
part: "contentDetails",
|
||||
id: submission.videoID
|
||||
}, (err, data) => resolve({err, data}));
|
||||
YouTubeAPI.listVideos(submission.videoID, "contentDetails", (err, data) => resolve({err, data}));
|
||||
});
|
||||
|
||||
if (err) {
|
||||
@@ -134,7 +128,6 @@ async function autoModerateSubmission(submission, callback) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
logger.debug("Skipped YouTube API");
|
||||
|
||||
@@ -214,6 +207,10 @@ module.exports = async function postSkipSegments(req, res) {
|
||||
if (isNaN(startTime) || isNaN(endTime)
|
||||
|| startTime === Infinity || endTime === Infinity || startTime < 0 || startTime >= endTime) {
|
||||
//invalid request
|
||||
logger.debug(videoID);
|
||||
logger.debug(userID);
|
||||
logger.debug(JSON.stringify(segments));
|
||||
logger.debug('400');
|
||||
res.sendStatus(400);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -48,10 +48,7 @@ function sendWebhooks(voteData) {
|
||||
}
|
||||
|
||||
if (config.youtubeAPIKey !== null) {
|
||||
YouTubeAPI.videos.list({
|
||||
part: "snippet",
|
||||
id: submissionInfoRow.videoID
|
||||
}, function (err, data) {
|
||||
YouTubeAPI.listVideos(submissionInfoRow.videoID, "snippet", (err, data) => {
|
||||
if (err || data.items.length === 0) {
|
||||
err && logger.error(err);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user