search-command.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import {
  2. HttpStatusCode,
  3. ResultList,
  4. Video,
  5. VideoChannel,
  6. VideoChannelsSearchQuery,
  7. VideoPlaylist,
  8. VideoPlaylistsSearchQuery,
  9. VideosSearchQuery
  10. } from '@shared/models'
  11. import { AbstractCommand, OverrideCommandOptions } from '../shared'
  12. export class SearchCommand extends AbstractCommand {
  13. searchChannels (options: OverrideCommandOptions & {
  14. search: string
  15. }) {
  16. return this.advancedChannelSearch({
  17. ...options,
  18. search: { search: options.search }
  19. })
  20. }
  21. advancedChannelSearch (options: OverrideCommandOptions & {
  22. search: VideoChannelsSearchQuery
  23. }) {
  24. const { search } = options
  25. const path = '/api/v1/search/video-channels'
  26. return this.getRequestBody<ResultList<VideoChannel>>({
  27. ...options,
  28. path,
  29. query: search,
  30. implicitToken: false,
  31. defaultExpectedStatus: HttpStatusCode.OK_200
  32. })
  33. }
  34. searchPlaylists (options: OverrideCommandOptions & {
  35. search: string
  36. }) {
  37. return this.advancedPlaylistSearch({
  38. ...options,
  39. search: { search: options.search }
  40. })
  41. }
  42. advancedPlaylistSearch (options: OverrideCommandOptions & {
  43. search: VideoPlaylistsSearchQuery
  44. }) {
  45. const { search } = options
  46. const path = '/api/v1/search/video-playlists'
  47. return this.getRequestBody<ResultList<VideoPlaylist>>({
  48. ...options,
  49. path,
  50. query: search,
  51. implicitToken: false,
  52. defaultExpectedStatus: HttpStatusCode.OK_200
  53. })
  54. }
  55. searchVideos (options: OverrideCommandOptions & {
  56. search: string
  57. sort?: string
  58. }) {
  59. const { search, sort } = options
  60. return this.advancedVideoSearch({
  61. ...options,
  62. search: {
  63. search,
  64. sort: sort ?? '-publishedAt'
  65. }
  66. })
  67. }
  68. advancedVideoSearch (options: OverrideCommandOptions & {
  69. search: VideosSearchQuery
  70. }) {
  71. const { search } = options
  72. const path = '/api/v1/search/videos'
  73. return this.getRequestBody<ResultList<Video>>({
  74. ...options,
  75. path,
  76. query: search,
  77. implicitToken: false,
  78. defaultExpectedStatus: HttpStatusCode.OK_200
  79. })
  80. }
  81. }