Browse Source

refactor(YouTube): Configurable quotas

Owen Diffey 1 year ago
parent
commit
b2c0381732

+ 3 - 0
.wiki/Configuration.md

@@ -17,6 +17,9 @@ Location: `backend/config/default.json`
 | `apis.youtube.rateLimit` | Minimum interval between YouTube API requests in milliseconds. |
 | `apis.youtube.requestTimeout` | YouTube API requests timeout in milliseconds. |
 | `apis.youtube.retryAmount` | The amount of retries to perform of a failed YouTube API request. |
+| `apis.youtube.quotas.perDay` | Configure YouTube API quota per day. |
+| `apis.youtube.quotas.perMinute` | Configure YouTube API quota per minute. |
+| `apis.youtube.quotas.per100Seconds` | Configure YouTube API quota per day. |
 | `apis.recaptcha.secret` | ReCaptcha Site v3 secret, obtained from [here](https://www.google.com/recaptcha/admin). |
 | `apis.recaptcha.enabled` | Whether to enable ReCaptcha at email registration. |
 | `apis.github.client` | GitHub OAuth Application client, obtained from [here](https://github.com/settings/developers). |

+ 7 - 2
backend/config/template.json

@@ -13,7 +13,12 @@
 			"key": "",
 			"rateLimit": 500,
 			"requestTimeout": 5000,
-			"retryAmount": 2
+			"retryAmount": 2,
+			"quotas": {
+				"perDay": 10000,
+				"perMinute": 1800000,
+				"per100Seconds": 3000000
+			}
 		},
 		"recaptcha": {
 			"secret": "",
@@ -96,5 +101,5 @@
 			]
 		}
 	},
-	"configVersion": 9
+	"configVersion": 10
 }

+ 1 - 1
backend/index.js

@@ -6,7 +6,7 @@ import fs from "fs";
 
 import package_json from "./package.json" assert { type: "json" };
 
-const REQUIRED_CONFIG_VERSION = 9;
+const REQUIRED_CONFIG_VERSION = 10;
 
 // eslint-disable-next-line
 Array.prototype.remove = function (item) {

+ 7 - 3
backend/logic/youtube.js

@@ -46,15 +46,18 @@ let DBModule;
 const quotas = [
 	{
 		type: "QUERIES_PER_DAY",
-		limit: 10000
+		title: "Queries Per Day",
+		limit: config.get("apis.youtube.quotas.perDay")
 	},
 	{
 		type: "QUERIES_PER_MINUTE",
-		limit: 1800000
+		title: "Queries Per Minute",
+		limit: config.get("apis.youtube.quotas.perMinute")
 	},
 	{
 		type: "QUERIES_PER_100_SECONDS",
-		limit: 3000000
+		title: "Queries Per 100 Seconds",
+		limit: config.get("apis.youtube.quotas.per100Seconds")
 	}
 ];
 
@@ -199,6 +202,7 @@ class _YouTubeModule extends CoreClass {
 
 						for (const quota of sortedQuotas) {
 							status[quota.type] = {
+								title: quota.title,
 								quotaUsed: 0,
 								limit: quota.limit,
 								quotaExceeded: false

+ 1 - 2
frontend/src/pages/Admin/YouTube.vue

@@ -40,7 +40,7 @@
 					:key="quotaName"
 					class="card quota"
 				>
-					<h5>{{ quotaName.replace(/_/g, " ").toLowerCase() }}</h5>
+					<h5>{{ quotaObject.title }}</h5>
 					<p>
 						<strong>Quota used:</strong> {{ quotaObject.quotaUsed }}
 					</p>
@@ -403,7 +403,6 @@ export default {
 				}
 
 				h5 {
-					text-transform: capitalize;
 					margin-bottom: 5px !important;
 				}
 			}