2
1

video-history.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
  2. import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
  3. function userWatchVideo (
  4. url: string,
  5. token: string,
  6. videoId: number | string,
  7. currentTime: number,
  8. statusCodeExpected = HttpStatusCode.NO_CONTENT_204
  9. ) {
  10. const path = '/api/v1/videos/' + videoId + '/watching'
  11. const fields = { currentTime }
  12. return makePutBodyRequest({ url, path, token, fields, statusCodeExpected })
  13. }
  14. function listMyVideosHistory (url: string, token: string, search?: string) {
  15. const path = '/api/v1/users/me/history/videos'
  16. return makeGetRequest({
  17. url,
  18. path,
  19. token,
  20. query: {
  21. search
  22. },
  23. statusCodeExpected: HttpStatusCode.OK_200
  24. })
  25. }
  26. function removeMyVideosHistory (url: string, token: string, beforeDate?: string) {
  27. const path = '/api/v1/users/me/history/videos/remove'
  28. return makePostBodyRequest({
  29. url,
  30. path,
  31. token,
  32. fields: beforeDate ? { beforeDate } : {},
  33. statusCodeExpected: HttpStatusCode.NO_CONTENT_204
  34. })
  35. }
  36. // ---------------------------------------------------------------------------
  37. export {
  38. userWatchVideo,
  39. listMyVideosHistory,
  40. removeMyVideosHistory
  41. }