youtube.js 2.4 KB

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