Support multiple newleaf urls

This commit is contained in:
Ajay Ramachandran 2021-06-03 11:38:21 -04:00
parent 1e5849f504
commit ec081cf0c5
7 changed files with 10 additions and 10 deletions

View file

@ -4,7 +4,7 @@
"port": 80,
"globalSalt": "[global salt (pepper) that is added to every ip before hashing to make it even harder for someone to decode the ip]",
"adminUserID": "[the hashed id of the user who can perform admin actions]",
"newLeafURL": "http://localhost:3241",
"newLeafURLs": ["http://localhost:3241"],
"discordReportChannelWebhookURL": null, //URL from discord if you would like notifications when someone makes a report [optional]
"discordFirstTimeSubmissionsWebhookURL": null, //URL from discord if you would like notifications when someone makes a first time submission [optional]
"discordCompletelyIncorrectReportWebhookURL": null, //URL from discord if you would like notifications when someone reports a submission as completely incorrect [optional]

View file

@ -44,7 +44,7 @@ addDefaults(config, {
},
},
userCounterURL: null,
newLeafURL: null,
newLeafURLs: null,
maxRewardTimePerSegmentInSeconds: 86400,
postgres: null,
dumpDatabase: {

View file

@ -265,7 +265,7 @@ async function autoModerateSubmission(apiVideoInfo: APIVideoInfo,
}
async function getYouTubeVideoInfo(videoID: VideoID, ignoreCache = false): Promise<APIVideoInfo> {
if (config.newLeafURL !== null) {
if (config.newLeafURLs !== null) {
return YouTubeAPI.listVideos(videoID, ignoreCache);
} else {
return null;

View file

@ -57,10 +57,10 @@ async function sendWebhooks(voteData: VoteData) {
webhookURL = config.discordCompletelyIncorrectReportWebhookURL;
}
if (config.newLeafURL !== null) {
if (config.newLeafURLs !== null) {
const { err, data } = await YouTubeAPI.listVideos(submissionInfoRow.videoID);
if (err) return;
const isUpvote = voteData.incrementAmount > 0;
// Send custom webhooks
dispatchEvent(isUpvote ? "vote.up" : "vote.down", {

View file

@ -6,7 +6,7 @@ export interface SBSConfig {
mockPort?: number;
globalSalt: string;
adminUserID: string;
newLeafURL?: string;
newLeafURLs?: string[];
discordReportChannelWebhookURL?: string;
discordFirstTimeSubmissionsWebhookURL?: string;
discordCompletelyIncorrectReportWebhookURL?: string;

View file

@ -21,15 +21,15 @@ export class YouTubeAPI {
}
}
if (!config.newLeafURL) return {err: "NewLeaf URL not found", data: null};
if (!config.newLeafURLs || config.newLeafURLs.length <= 0) return {err: "NewLeaf URL not found", data: null};
try {
const result = await fetch(config.newLeafURL + "/api/v1/videos/" + videoID, { method: "GET" });
const result = await fetch(config.newLeafURLs[Math.floor(Math.random() * config.newLeafURLs.length)] + "/api/v1/videos/" + videoID, { method: "GET" });
if (result.ok) {
const data = await result.json();
if (data.error) {
Logger.warn("CloudTube API Error: " + data.error)
Logger.warn("NewLeaf API Error: " + data.error)
return { err: data.error, data: null };
}

View file

@ -3,7 +3,7 @@
"mockPort": 8081,
"globalSalt": "testSalt",
"adminUserID": "testUserId",
"newLeafURL": "placeholder",
"newLeafURLs": ["placeholder"],
"discordReportChannelWebhookURL": "http://127.0.0.1:8081/ReportChannelWebhook",
"discordFirstTimeSubmissionsWebhookURL": "http://127.0.0.1:8081/FirstTimeSubmissionsWebhook",
"discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/CompletelyIncorrectReportWebhook",