aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/search/search-command.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/search/search-command.ts')
-rw-r--r--shared/extra-utils/search/search-command.ts101
1 files changed, 101 insertions, 0 deletions
diff --git a/shared/extra-utils/search/search-command.ts b/shared/extra-utils/search/search-command.ts
new file mode 100644
index 000000000..d4cfab32b
--- /dev/null
+++ b/shared/extra-utils/search/search-command.ts
@@ -0,0 +1,101 @@
1import {
2 ResultList,
3 Video,
4 VideoChannel,
5 VideoChannelsSearchQuery,
6 VideoPlaylist,
7 VideoPlaylistsSearchQuery,
8 VideosSearchQuery
9} from '@shared/models'
10import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
11import { AbstractCommand, OverrideCommandOptions } from '../shared'
12
13export class SearchCommand extends AbstractCommand {
14
15 searchChannels (options: OverrideCommandOptions & {
16 search: string
17 }) {
18 return this.advancedChannelSearch({
19 ...options,
20
21 search: { search: options.search }
22 })
23 }
24
25 advancedChannelSearch (options: OverrideCommandOptions & {
26 search: VideoChannelsSearchQuery
27 }) {
28 const { search, token } = options
29 const path = '/api/v1/search/video-channels'
30
31 return this.getRequestBody<ResultList<VideoChannel>>({
32 ...options,
33
34 token: token || null,
35
36 path,
37 query: search,
38 defaultExpectedStatus: HttpStatusCode.OK_200
39 })
40 }
41
42 searchPlaylists (options: OverrideCommandOptions & {
43 search: string
44 }) {
45 return this.advancedPlaylistSearch({
46 ...options,
47
48 search: { search: options.search }
49 })
50 }
51
52 advancedPlaylistSearch (options: OverrideCommandOptions & {
53 search: VideoPlaylistsSearchQuery
54 }) {
55 const { search, token } = options
56 const path = '/api/v1/search/video-playlists'
57
58 return this.getRequestBody<ResultList<VideoPlaylist>>({
59 ...options,
60
61 token: token || null,
62
63 path,
64 query: search,
65 defaultExpectedStatus: HttpStatusCode.OK_200
66 })
67 }
68
69 searchVideos (options: OverrideCommandOptions & {
70 search: string
71 sort?: string
72 }) {
73 const { search, sort } = options
74
75 return this.advancedVideoSearch({
76 ...options,
77
78 search: {
79 search: search,
80 sort: sort ?? '-publishedAt'
81 }
82 })
83 }
84
85 advancedVideoSearch (options: OverrideCommandOptions & {
86 search: VideosSearchQuery
87 }) {
88 const { search, token } = options
89 const path = '/api/v1/search/videos'
90
91 return this.getRequestBody<ResultList<Video>>({
92 ...options,
93
94 token: token || null,
95
96 path,
97 query: search,
98 defaultExpectedStatus: HttpStatusCode.OK_200
99 })
100 }
101}