Преглед изворни кода

feat: Added reset stored YouTube API requests job

Owen Diffey пре 2 година
родитељ
комит
3dedb5a968
3 измењених фајлова са 49 додато и 7 уклоњено
  1. 18 0
      backend/logic/actions/youtube.js
  2. 11 0
      backend/logic/youtube.js
  3. 20 7
      frontend/src/pages/Admin/YouTube.vue

+ 18 - 0
backend/logic/actions/youtube.js

@@ -121,5 +121,23 @@ export default {
 				);
 				return cb({ status: "error", message: err });
 			});
+	}),
+
+	/**
+	 * Reset stored API requests
+	 *
+	 * @returns {{status: string, data: object}}
+	 */
+	 resetStoredApiRequests: isAdminRequired(function resetStoredApiRequests(session, cb) {
+		YouTubeModule.runJob("RESET_STORED_API_REQUESTS", {}, this)
+			.then(response => {
+				this.log("SUCCESS", "YOUTUBE_RESET_STORED_API_REQUESTS", `Resetting stored API requests was successful.`);
+				return cb({ status: "success", message: "Successfully reset stored YouTube API requests" });
+			})
+			.catch(async err => {
+				err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
+				this.log("ERROR", "YOUTUBE_RESET_STORED_API_REQUESTS", `Resetting stored API requests failed. "${err}"`);
+				return cb({ status: "error", message: err });
+			});
 	})
 };

+ 11 - 0
backend/logic/youtube.js

@@ -956,6 +956,17 @@ class _YouTubeModule extends CoreClass {
 			);
 		});
 	}
+
+	RESET_STORED_API_REQUESTS(payload) {
+		return new Promise((resolve, reject) => {
+			YouTubeModule.youtubeApiRequestModel.deleteMany({}, err => {
+				if (err) reject(new Error("Couldn't reset stored YouTube API requests."));
+				else {
+					resolve();
+				}
+			});
+		});
+	}
 }
 
 export default new _YouTubeModule();

+ 20 - 7
frontend/src/pages/Admin/YouTube.vue

@@ -1,12 +1,17 @@
 <template>
 	<div class="admin-tab container">
 		<page-metadata title="Admin | YouTube" />
-		<div class="card">
-			<h1>YouTube API</h1>
-			<p>
-				Analyze YouTube quota usage and API requests made on this
-				instance
-			</p>
+		<div class="card tab-info">
+			<div class="info-row">
+				<h1>YouTube API</h1>
+				<p>
+					Analyze YouTube quota usage and API requests made on this
+					instance
+				</p>
+			</div>
+			<div class="button-row">
+				<run-job-dropdown :jobs="jobs" />
+			</div>
 		</div>
 		<div class="card charts">
 			<div class="chart">
@@ -103,6 +108,7 @@
 import { mapActions, mapGetters } from "vuex";
 
 import AdvancedTable from "@/components/AdvancedTable.vue";
+import RunJobDropdown from "@/components/RunJobDropdown.vue";
 import LineChart from "@/components/LineChart.vue";
 
 import ws from "@/ws";
@@ -110,6 +116,7 @@ import ws from "@/ws";
 export default {
 	components: {
 		AdvancedTable,
+		RunJobDropdown,
 		LineChart
 	},
 	data() {
@@ -240,7 +247,13 @@ export default {
 						}
 					]
 				}
-			}
+			},
+			jobs: [
+				{
+					name: "Reset stored API requests",
+					socket: "youtube.resetStoredApiRequests"
+				}
+			]
 		};
 	},
 	computed: mapGetters({