mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 12:37:00 +03:00
Move dispatchEvent to webhookUtils
This commit is contained in:
@@ -5,8 +5,7 @@ var getHash = require('../utils/getHash.js');
|
|||||||
var getIP = require('../utils/getIP.js');
|
var getIP = require('../utils/getIP.js');
|
||||||
var getFormattedTime = require('../utils/getFormattedTime.js');
|
var getFormattedTime = require('../utils/getFormattedTime.js');
|
||||||
var isUserTrustworthy = require('../utils/isUserTrustworthy.js');
|
var isUserTrustworthy = require('../utils/isUserTrustworthy.js');
|
||||||
const dispatchWebhooks = require('../utils/dispatchWebhooks.js');
|
const {getVoteAuthor, getVoteAuthorRaw, dispatchEvent} = require('../utils/webhookUtils.js');
|
||||||
const {getVoteAuthor, getVoteAuthorRaw} = require('../utils/webhookUtils.js');
|
|
||||||
|
|
||||||
|
|
||||||
var databases = require('../databases/databases.js');
|
var databases = require('../databases/databases.js');
|
||||||
@@ -214,7 +213,7 @@ async function voteOnSponsorTime(req, res) {
|
|||||||
}
|
}
|
||||||
let isUpvote = incrementAmount > 0;
|
let isUpvote = incrementAmount > 0;
|
||||||
// Send custom webhooks
|
// Send custom webhooks
|
||||||
dispatchWebhooks(isUpvote ? "vote.up" : "vote.down", {
|
dispatchEvent(isUpvote ? "vote.up" : "vote.down", {
|
||||||
"user": {
|
"user": {
|
||||||
"status": getVoteAuthorRaw(userSubmissionCountRow.submissionCount, isVIP, isOwnSubmission)
|
"status": getVoteAuthorRaw(userSubmissionCountRow.submissionCount, isVIP, isOwnSubmission)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
const config = require("../config.js");
|
|
||||||
const logger = require('../utils/logger.js');
|
|
||||||
const request = require('request');
|
|
||||||
|
|
||||||
|
|
||||||
function dispatchEvent(scope, data) {
|
|
||||||
let webhooks = config.webhooks;
|
|
||||||
if (webhooks === undefined || webhooks.length === 0) return;
|
|
||||||
logger.debug("Dispatching webhooks");
|
|
||||||
webhooks.forEach(webhook => {
|
|
||||||
let webhookURL = webhook.url;
|
|
||||||
let authKey = webhook.key;
|
|
||||||
let scopes = webhook.scopes || [];
|
|
||||||
if (!scopes.includes(scope.toLowerCase())) return;
|
|
||||||
request.post(webhookURL, {json: data, headers: {
|
|
||||||
"Authorization": authKey,
|
|
||||||
"Event-Type": scope // Maybe change this in the future?
|
|
||||||
}});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = dispatchEvent;
|
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
const config = require('../config.js');
|
||||||
|
const logger = require('../utils/logger.js');
|
||||||
|
const request = require('request');
|
||||||
|
|
||||||
function getVoteAuthorRaw(submissionCount, isVIP, isOwnSubmission) {
|
function getVoteAuthorRaw(submissionCount, isVIP, isOwnSubmission) {
|
||||||
if (isOwnSubmission) {
|
if (isOwnSubmission) {
|
||||||
return "self";
|
return "self";
|
||||||
@@ -22,5 +26,24 @@ function getVoteAuthor(submissionCount, isVIP, isOwnSubmission) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getVoteAuthorRaw = getVoteAuthorRaw;
|
function dispatchEvent(scope, data) {
|
||||||
module.exports.getVoteAuthor = getVoteAuthor;
|
let webhooks = config.webhooks;
|
||||||
|
if (webhooks === undefined || webhooks.length === 0) return;
|
||||||
|
logger.debug("Dispatching webhooks");
|
||||||
|
webhooks.forEach(webhook => {
|
||||||
|
let webhookURL = webhook.url;
|
||||||
|
let authKey = webhook.key;
|
||||||
|
let scopes = webhook.scopes || [];
|
||||||
|
if (!scopes.includes(scope.toLowerCase())) return;
|
||||||
|
request.post(webhookURL, {json: data, headers: {
|
||||||
|
"Authorization": authKey,
|
||||||
|
"Event-Type": scope // Maybe change this in the future?
|
||||||
|
}});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getVoteAuthorRaw,
|
||||||
|
getVoteAuthor,
|
||||||
|
dispatchEvent
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user