mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-05-12 19:06:19 +02:00
Add another logging webhook
This commit is contained in:
parent
e7f3753077
commit
cbc38c5ac8
4 changed files with 72 additions and 56 deletions
|
@ -48,6 +48,7 @@ addDefaults(config, {
|
||||||
discordDeArrowLockedWebhookURL: null,
|
discordDeArrowLockedWebhookURL: null,
|
||||||
discordDeArrowWarnedWebhookURL: null,
|
discordDeArrowWarnedWebhookURL: null,
|
||||||
discordNewUserWebhookURL: null,
|
discordNewUserWebhookURL: null,
|
||||||
|
discordRejectedNewUserWebhookURL: null,
|
||||||
minReputationToSubmitChapter: 0,
|
minReputationToSubmitChapter: 0,
|
||||||
minReputationToSubmitFiller: 0,
|
minReputationToSubmitFiller: 0,
|
||||||
getTopUsersCacheTimeMinutes: 240,
|
getTopUsersCacheTimeMinutes: 240,
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Request, Response } from "express";
|
||||||
import { config } from "../config";
|
import { config } from "../config";
|
||||||
import { db, privateDB } from "../databases/databases";
|
import { db, privateDB } from "../databases/databases";
|
||||||
|
|
||||||
import { BrandingSubmission, BrandingUUID, TimeThumbnailSubmission } from "../types/branding.model";
|
import { BrandingSubmission, BrandingUUID, TimeThumbnailSubmission, TitleSubmission } from "../types/branding.model";
|
||||||
import { HashedIP, IPAddress, VideoID } from "../types/segments.model";
|
import { HashedIP, IPAddress, VideoID } from "../types/segments.model";
|
||||||
import { Feature, HashedUserID } from "../types/user.model";
|
import { Feature, HashedUserID } from "../types/user.model";
|
||||||
import { getHashCache } from "../utils/getHashCache";
|
import { getHashCache } from "../utils/getHashCache";
|
||||||
|
@ -73,6 +73,7 @@ export async function postBranding(req: Request, res: Response) {
|
||||||
},
|
},
|
||||||
endpoint: "dearrow-postBranding",
|
endpoint: "dearrow-postBranding",
|
||||||
})) {
|
})) {
|
||||||
|
sendNewUserWebhook(config.discordRejectedNewUserWebhookURL, hashedUserID, videoID, userAgent, req, videoDuration, title);
|
||||||
Logger.warn(`Dearrow submission rejected by request validator: ${hashedUserID} ${videoID} ${videoDuration} ${userAgent} ${req.headers["user-agent"]} ${title.title} ${thumbnail.timestamp}`);
|
Logger.warn(`Dearrow submission rejected by request validator: ${hashedUserID} ${videoID} ${videoDuration} ${userAgent} ${req.headers["user-agent"]} ${title.title} ${thumbnail.timestamp}`);
|
||||||
res.status(200).send("OK");
|
res.status(200).send("OK");
|
||||||
return;
|
return;
|
||||||
|
@ -84,34 +85,8 @@ export async function postBranding(req: Request, res: Response) {
|
||||||
|
|
||||||
res.status(403).send(permission.reason);
|
res.status(403).send(permission.reason);
|
||||||
return;
|
return;
|
||||||
} else if (permission.newUser && config.discordNewUserWebhookURL) {
|
} else if (permission.newUser) {
|
||||||
axios.post(config.discordNewUserWebhookURL, {
|
sendNewUserWebhook(config.discordNewUserWebhookURL, hashedUserID, videoID, userAgent, req, videoDuration, title);
|
||||||
"embeds": [{
|
|
||||||
"title": hashedUserID,
|
|
||||||
"url": `https://www.youtube.com/watch?v=${videoID}`,
|
|
||||||
"description": `**User Agent**: ${userAgent}\
|
|
||||||
\n**Sent User Agent**: ${req.body.userAgent}\
|
|
||||||
\n**Real User Agent**: ${req.headers["user-agent"]}\
|
|
||||||
\n**Video Duration**: ${videoDuration}\
|
|
||||||
\n**Title**: ${title?.title}`,
|
|
||||||
"color": 1184701,
|
|
||||||
"thumbnail": {
|
|
||||||
"url": getMaxResThumbnail(videoID),
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
if (res.status >= 400) {
|
|
||||||
Logger.error("Error sending reported submission Discord hook");
|
|
||||||
Logger.error(JSON.stringify((res.data)));
|
|
||||||
Logger.error("\n");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
Logger.error("Failed to send reported submission Discord hook.");
|
|
||||||
Logger.error(JSON.stringify(err));
|
|
||||||
Logger.error("\n");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (videoDuration && thumbnail && await checkForWrongVideoDuration(videoID, videoDuration)) {
|
if (videoDuration && thumbnail && await checkForWrongVideoDuration(videoID, videoDuration)) {
|
||||||
|
@ -235,6 +210,38 @@ export async function postBranding(req: Request, res: Response) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendNewUserWebhook(webhookUrl: string, hashedUserID: HashedUserID, videoID: VideoID, userAgent: any, req: Request, videoDuration: number, title: TitleSubmission) {
|
||||||
|
if (!webhookUrl) return;
|
||||||
|
|
||||||
|
axios.post(webhookUrl, {
|
||||||
|
"embeds": [{
|
||||||
|
"title": hashedUserID,
|
||||||
|
"url": `https://www.youtube.com/watch?v=${videoID}`,
|
||||||
|
"description": `**User Agent**: ${userAgent}\
|
||||||
|
\n**Sent User Agent**: ${req.body.userAgent}\
|
||||||
|
\n**Real User Agent**: ${req.headers["user-agent"]}\
|
||||||
|
\n**Video Duration**: ${videoDuration}\
|
||||||
|
\n**Title**: ${title?.title}`,
|
||||||
|
"color": 1184701,
|
||||||
|
"thumbnail": {
|
||||||
|
"url": getMaxResThumbnail(videoID),
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status >= 400) {
|
||||||
|
Logger.error("Error sending reported submission Discord hook");
|
||||||
|
Logger.error(JSON.stringify((res.data)));
|
||||||
|
Logger.error("\n");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
Logger.error("Failed to send reported submission Discord hook.");
|
||||||
|
Logger.error(JSON.stringify(err));
|
||||||
|
Logger.error("\n");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds an existing vote, if found, and it's for a different submission, it undoes it, and points to the new submission.
|
* Finds an existing vote, if found, and it's for a different submission, it undoes it, and points to the new submission.
|
||||||
* If no existing vote, it adds one.
|
* If no existing vote, it adds one.
|
||||||
|
|
|
@ -520,6 +520,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
||||||
segments,
|
segments,
|
||||||
endpoint: "sponsorblock-postSkipSegments"
|
endpoint: "sponsorblock-postSkipSegments"
|
||||||
})) {
|
})) {
|
||||||
|
sendNewUserWebhook(config.discordRejectedNewUserWebhookURL, userID, videoID, userAgent, req, videoDurationParam);
|
||||||
Logger.warn(`Sponsorblock submission rejected by request validator: ${userID} ${videoID} ${videoDurationParam} ${userAgent} ${req.headers["user-agent"]}`);
|
Logger.warn(`Sponsorblock submission rejected by request validator: ${userID} ${videoID} ${videoDurationParam} ${userAgent} ${req.headers["user-agent"]}`);
|
||||||
return res.status(200).send("OK");
|
return res.status(200).send("OK");
|
||||||
}
|
}
|
||||||
|
@ -570,33 +571,8 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
||||||
|
|
||||||
Logger.warn(`New user trying to submit: ${userID} ${videoID} ${videoDurationParam} ${userAgent} ${req.headers["user-agent"]}`);
|
Logger.warn(`New user trying to submit: ${userID} ${videoID} ${videoDurationParam} ${userAgent} ${req.headers["user-agent"]}`);
|
||||||
return res.status(403).send(permission.reason);
|
return res.status(403).send(permission.reason);
|
||||||
} else if (permission.newUser && config.discordNewUserWebhookURL) {
|
} else if (permission.newUser) {
|
||||||
axios.post(config.discordNewUserWebhookURL, {
|
sendNewUserWebhook(config.discordNewUserWebhookURL, userID, videoID, userAgent, req, videoDurationParam);
|
||||||
"embeds": [{
|
|
||||||
"title": userID,
|
|
||||||
"url": `https://www.youtube.com/watch?v=${videoID}`,
|
|
||||||
"description": `**User Agent**: ${userAgent}\
|
|
||||||
\n**Sent User Agent**: ${req.query.userAgent ?? req.body.userAgent}\
|
|
||||||
\n**Real User Agent**: ${req.headers["user-agent"]}\
|
|
||||||
\n**Video Duration**: ${videoDurationParam}`,
|
|
||||||
"color": 10813440,
|
|
||||||
"thumbnail": {
|
|
||||||
"url": getMaxResThumbnail(videoID),
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
if (res.status >= 400) {
|
|
||||||
Logger.error("Error sending reported submission Discord hook");
|
|
||||||
Logger.error(JSON.stringify((res.data)));
|
|
||||||
Logger.error("\n");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
Logger.error("Failed to send reported submission Discord hook.");
|
|
||||||
Logger.error(JSON.stringify(err));
|
|
||||||
Logger.error("\n");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will be filled when submitting
|
// Will be filled when submitting
|
||||||
|
@ -685,6 +661,37 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendNewUserWebhook(webhookUrl: string, userID: HashedUserID, videoID: any, userAgent: any, req: Request, videoDurationParam: VideoDuration) {
|
||||||
|
if (!webhookUrl) return;
|
||||||
|
|
||||||
|
axios.post(webhookUrl, {
|
||||||
|
"embeds": [{
|
||||||
|
"title": userID,
|
||||||
|
"url": `https://www.youtube.com/watch?v=${videoID}`,
|
||||||
|
"description": `**User Agent**: ${userAgent}\
|
||||||
|
\n**Sent User Agent**: ${req.query.userAgent ?? req.body.userAgent}\
|
||||||
|
\n**Real User Agent**: ${req.headers["user-agent"]}\
|
||||||
|
\n**Video Duration**: ${videoDurationParam}`,
|
||||||
|
"color": 10813440,
|
||||||
|
"thumbnail": {
|
||||||
|
"url": getMaxResThumbnail(videoID),
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.status >= 400) {
|
||||||
|
Logger.error("Error sending reported submission Discord hook");
|
||||||
|
Logger.error(JSON.stringify((res.data)));
|
||||||
|
Logger.error("\n");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
Logger.error("Failed to send reported submission Discord hook.");
|
||||||
|
Logger.error(JSON.stringify(err));
|
||||||
|
Logger.error("\n");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Takes an array of arrays:
|
// Takes an array of arrays:
|
||||||
// ex)
|
// ex)
|
||||||
// [
|
// [
|
||||||
|
|
|
@ -86,6 +86,7 @@ export interface SBSConfig {
|
||||||
discordNewUserWebhookURL?: string;
|
discordNewUserWebhookURL?: string;
|
||||||
neuralBlockURL?: string;
|
neuralBlockURL?: string;
|
||||||
discordNeuralBlockRejectWebhookURL?: string;
|
discordNeuralBlockRejectWebhookURL?: string;
|
||||||
|
discordRejectedNewUserWebhookURL?: string;
|
||||||
minReputationToSubmitChapter: number;
|
minReputationToSubmitChapter: number;
|
||||||
minReputationToSubmitFiller: number;
|
minReputationToSubmitFiller: number;
|
||||||
userCounterURL?: string;
|
userCounterURL?: string;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue