diff --git a/config.json.example b/config.json.example index dbd009e..1934a98 100644 --- a/config.json.example +++ b/config.json.example @@ -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] diff --git a/src/config.ts b/src/config.ts index 2f6d774..34e5438 100644 --- a/src/config.ts +++ b/src/config.ts @@ -44,7 +44,7 @@ addDefaults(config, { }, }, userCounterURL: null, - newLeafURL: null, + newLeafURLs: null, maxRewardTimePerSegmentInSeconds: 86400, postgres: null, dumpDatabase: { diff --git a/src/routes/postSkipSegments.ts b/src/routes/postSkipSegments.ts index 3da291a..b79b855 100644 --- a/src/routes/postSkipSegments.ts +++ b/src/routes/postSkipSegments.ts @@ -265,7 +265,7 @@ async function autoModerateSubmission(apiVideoInfo: APIVideoInfo, } async function getYouTubeVideoInfo(videoID: VideoID, ignoreCache = false): Promise { - if (config.newLeafURL !== null) { + if (config.newLeafURLs !== null) { return YouTubeAPI.listVideos(videoID, ignoreCache); } else { return null; diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 0e37732..ce59172 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -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", { diff --git a/src/types/config.model.ts b/src/types/config.model.ts index aa0a863..f5614d9 100644 --- a/src/types/config.model.ts +++ b/src/types/config.model.ts @@ -6,7 +6,7 @@ export interface SBSConfig { mockPort?: number; globalSalt: string; adminUserID: string; - newLeafURL?: string; + newLeafURLs?: string[]; discordReportChannelWebhookURL?: string; discordFirstTimeSubmissionsWebhookURL?: string; discordCompletelyIncorrectReportWebhookURL?: string; diff --git a/src/utils/youtubeApi.ts b/src/utils/youtubeApi.ts index 855a2d6..e68370a 100644 --- a/src/utils/youtubeApi.ts +++ b/src/utils/youtubeApi.ts @@ -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 }; } diff --git a/test.json b/test.json index c3b1096..f695671 100644 --- a/test.json +++ b/test.json @@ -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",