youtube.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import mongoose from "mongoose";
  2. import { isAdminRequired } from "./hooks";
  3. // eslint-disable-next-line
  4. import moduleManager from "../../index";
  5. const UtilsModule = moduleManager.modules.utils;
  6. const YouTubeModule = moduleManager.modules.youtube;
  7. export default {
  8. /**
  9. * Returns details about the YouTube quota usage
  10. *
  11. * @returns {{status: string, data: object}}
  12. */
  13. getQuotaStatus: isAdminRequired(function getQuotaStatus(session, fromDate, cb) {
  14. YouTubeModule.runJob("GET_QUOTA_STATUS", { fromDate }, this)
  15. .then(response => {
  16. this.log("SUCCESS", "YOUTUBE_GET_QUOTA_STATUS", `Getting quota status was successful.`);
  17. return cb({ status: "success", data: { status: response.status } });
  18. })
  19. .catch(async err => {
  20. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  21. this.log("ERROR", "YOUTUBE_GET_QUOTA_STATUS", `Getting quota status failed. "${err}"`);
  22. return cb({ status: "error", message: err });
  23. });
  24. }),
  25. /**
  26. * Returns api requests
  27. *
  28. * @returns {{status: string, data: object}}
  29. */
  30. getApiRequests: isAdminRequired(function getApiRequests(session, fromDate, cb) {
  31. YouTubeModule.runJob("GET_API_REQUESTS", { fromDate }, this)
  32. .then(response => {
  33. this.log("SUCCESS", "YOUTUBE_GET_API_REQUESTS", `Getting api requests was successful.`);
  34. return cb({ status: "success", data: { apiRequests: response.apiRequests } });
  35. })
  36. .catch(async err => {
  37. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  38. this.log("ERROR", "YOUTUBE_GET_API_REQUESTS", `Getting api requests failed. "${err}"`);
  39. return cb({ status: "error", message: err });
  40. });
  41. }),
  42. /**
  43. * Returns a specific api request
  44. *
  45. * @returns {{status: string, data: object}}
  46. */
  47. getApiRequest: isAdminRequired(function getApiRequest(session, apiRequestId, cb) {
  48. if (!mongoose.Types.ObjectId.isValid(apiRequestId))
  49. return cb({ status: "error", message: "Api request id is not a valid ObjectId." });
  50. return YouTubeModule.runJob("GET_API_REQUEST", { apiRequestId }, this)
  51. .then(response => {
  52. this.log(
  53. "SUCCESS",
  54. "YOUTUBE_GET_API_REQUEST",
  55. `Getting api request with id ${apiRequestId} was successful.`
  56. );
  57. return cb({ status: "success", data: { apiRequest: response.apiRequest } });
  58. })
  59. .catch(async err => {
  60. err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
  61. this.log(
  62. "ERROR",
  63. "YOUTUBE_GET_API_REQUEST",
  64. `Getting api request with id ${apiRequestId} failed. "${err}"`
  65. );
  66. return cb({ status: "error", message: err });
  67. });
  68. })
  69. };