mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-05-11 10:26:25 +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,
|
||||
discordDeArrowWarnedWebhookURL: null,
|
||||
discordNewUserWebhookURL: null,
|
||||
discordRejectedNewUserWebhookURL: null,
|
||||
minReputationToSubmitChapter: 0,
|
||||
minReputationToSubmitFiller: 0,
|
||||
getTopUsersCacheTimeMinutes: 240,
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Request, Response } from "express";
|
|||
import { config } from "../config";
|
||||
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 { Feature, HashedUserID } from "../types/user.model";
|
||||
import { getHashCache } from "../utils/getHashCache";
|
||||
|
@ -73,6 +73,7 @@ export async function postBranding(req: Request, res: Response) {
|
|||
},
|
||||
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}`);
|
||||
res.status(200).send("OK");
|
||||
return;
|
||||
|
@ -84,34 +85,8 @@ export async function postBranding(req: Request, res: Response) {
|
|||
|
||||
res.status(403).send(permission.reason);
|
||||
return;
|
||||
} else if (permission.newUser && config.discordNewUserWebhookURL) {
|
||||
axios.post(config.discordNewUserWebhookURL, {
|
||||
"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");
|
||||
});
|
||||
} else if (permission.newUser) {
|
||||
sendNewUserWebhook(config.discordNewUserWebhookURL, hashedUserID, videoID, userAgent, req, videoDuration, title);
|
||||
}
|
||||
|
||||
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.
|
||||
* If no existing vote, it adds one.
|
||||
|
|
|
@ -520,6 +520,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
|||
segments,
|
||||
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"]}`);
|
||||
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"]}`);
|
||||
return res.status(403).send(permission.reason);
|
||||
} else if (permission.newUser && config.discordNewUserWebhookURL) {
|
||||
axios.post(config.discordNewUserWebhookURL, {
|
||||
"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");
|
||||
});
|
||||
} else if (permission.newUser) {
|
||||
sendNewUserWebhook(config.discordNewUserWebhookURL, userID, videoID, userAgent, req, videoDurationParam);
|
||||
}
|
||||
|
||||
// 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:
|
||||
// ex)
|
||||
// [
|
||||
|
|
|
@ -86,6 +86,7 @@ export interface SBSConfig {
|
|||
discordNewUserWebhookURL?: string;
|
||||
neuralBlockURL?: string;
|
||||
discordNeuralBlockRejectWebhookURL?: string;
|
||||
discordRejectedNewUserWebhookURL?: string;
|
||||
minReputationToSubmitChapter: number;
|
||||
minReputationToSubmitFiller: number;
|
||||
userCounterURL?: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue