diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /shared/extra-utils/search | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'shared/extra-utils/search')
-rw-r--r-- | shared/extra-utils/search/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/search/search-command.ts | 98 | ||||
-rw-r--r-- | shared/extra-utils/search/video-channels.ts | 36 | ||||
-rw-r--r-- | shared/extra-utils/search/video-playlists.ts | 36 | ||||
-rw-r--r-- | shared/extra-utils/search/videos.ts | 64 |
5 files changed, 99 insertions, 136 deletions
diff --git a/shared/extra-utils/search/index.ts b/shared/extra-utils/search/index.ts new file mode 100644 index 000000000..48dbe8ae9 --- /dev/null +++ b/shared/extra-utils/search/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './search-command' | |||
diff --git a/shared/extra-utils/search/search-command.ts b/shared/extra-utils/search/search-command.ts new file mode 100644 index 000000000..0fbbcd6ef --- /dev/null +++ b/shared/extra-utils/search/search-command.ts | |||
@@ -0,0 +1,98 @@ | |||
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 | |||
13 | export 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 } = options | ||
29 | const path = '/api/v1/search/video-channels' | ||
30 | |||
31 | return this.getRequestBody<ResultList<VideoChannel>>({ | ||
32 | ...options, | ||
33 | |||
34 | path, | ||
35 | query: search, | ||
36 | implicitToken: false, | ||
37 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
38 | }) | ||
39 | } | ||
40 | |||
41 | searchPlaylists (options: OverrideCommandOptions & { | ||
42 | search: string | ||
43 | }) { | ||
44 | return this.advancedPlaylistSearch({ | ||
45 | ...options, | ||
46 | |||
47 | search: { search: options.search } | ||
48 | }) | ||
49 | } | ||
50 | |||
51 | advancedPlaylistSearch (options: OverrideCommandOptions & { | ||
52 | search: VideoPlaylistsSearchQuery | ||
53 | }) { | ||
54 | const { search } = options | ||
55 | const path = '/api/v1/search/video-playlists' | ||
56 | |||
57 | return this.getRequestBody<ResultList<VideoPlaylist>>({ | ||
58 | ...options, | ||
59 | |||
60 | path, | ||
61 | query: search, | ||
62 | implicitToken: false, | ||
63 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
64 | }) | ||
65 | } | ||
66 | |||
67 | searchVideos (options: OverrideCommandOptions & { | ||
68 | search: string | ||
69 | sort?: string | ||
70 | }) { | ||
71 | const { search, sort } = options | ||
72 | |||
73 | return this.advancedVideoSearch({ | ||
74 | ...options, | ||
75 | |||
76 | search: { | ||
77 | search: search, | ||
78 | sort: sort ?? '-publishedAt' | ||
79 | } | ||
80 | }) | ||
81 | } | ||
82 | |||
83 | advancedVideoSearch (options: OverrideCommandOptions & { | ||
84 | search: VideosSearchQuery | ||
85 | }) { | ||
86 | const { search } = options | ||
87 | const path = '/api/v1/search/videos' | ||
88 | |||
89 | return this.getRequestBody<ResultList<Video>>({ | ||
90 | ...options, | ||
91 | |||
92 | path, | ||
93 | query: search, | ||
94 | implicitToken: false, | ||
95 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
96 | }) | ||
97 | } | ||
98 | } | ||
diff --git a/shared/extra-utils/search/video-channels.ts b/shared/extra-utils/search/video-channels.ts deleted file mode 100644 index 8e0f42578..000000000 --- a/shared/extra-utils/search/video-channels.ts +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | import { VideoChannelsSearchQuery } from '@shared/models' | ||
2 | import { makeGetRequest } from '../requests/requests' | ||
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
4 | |||
5 | function searchVideoChannel (url: string, search: string, token?: string, statusCodeExpected = HttpStatusCode.OK_200) { | ||
6 | const path = '/api/v1/search/video-channels' | ||
7 | |||
8 | return makeGetRequest({ | ||
9 | url, | ||
10 | path, | ||
11 | query: { | ||
12 | sort: '-createdAt', | ||
13 | search | ||
14 | }, | ||
15 | token, | ||
16 | statusCodeExpected | ||
17 | }) | ||
18 | } | ||
19 | |||
20 | function advancedVideoChannelSearch (url: string, search: VideoChannelsSearchQuery) { | ||
21 | const path = '/api/v1/search/video-channels' | ||
22 | |||
23 | return makeGetRequest({ | ||
24 | url, | ||
25 | path, | ||
26 | query: search, | ||
27 | statusCodeExpected: HttpStatusCode.OK_200 | ||
28 | }) | ||
29 | } | ||
30 | |||
31 | // --------------------------------------------------------------------------- | ||
32 | |||
33 | export { | ||
34 | searchVideoChannel, | ||
35 | advancedVideoChannelSearch | ||
36 | } | ||
diff --git a/shared/extra-utils/search/video-playlists.ts b/shared/extra-utils/search/video-playlists.ts deleted file mode 100644 index c22831df7..000000000 --- a/shared/extra-utils/search/video-playlists.ts +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | import { VideoPlaylistsSearchQuery } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { makeGetRequest } from '../requests/requests' | ||
4 | |||
5 | function searchVideoPlaylists (url: string, search: string, token?: string, statusCodeExpected = HttpStatusCode.OK_200) { | ||
6 | const path = '/api/v1/search/video-playlists' | ||
7 | |||
8 | return makeGetRequest({ | ||
9 | url, | ||
10 | path, | ||
11 | query: { | ||
12 | sort: '-createdAt', | ||
13 | search | ||
14 | }, | ||
15 | token, | ||
16 | statusCodeExpected | ||
17 | }) | ||
18 | } | ||
19 | |||
20 | function advancedVideoPlaylistSearch (url: string, search: VideoPlaylistsSearchQuery) { | ||
21 | const path = '/api/v1/search/video-playlists' | ||
22 | |||
23 | return makeGetRequest({ | ||
24 | url, | ||
25 | path, | ||
26 | query: search, | ||
27 | statusCodeExpected: HttpStatusCode.OK_200 | ||
28 | }) | ||
29 | } | ||
30 | |||
31 | // --------------------------------------------------------------------------- | ||
32 | |||
33 | export { | ||
34 | searchVideoPlaylists, | ||
35 | advancedVideoPlaylistSearch | ||
36 | } | ||
diff --git a/shared/extra-utils/search/videos.ts b/shared/extra-utils/search/videos.ts deleted file mode 100644 index db6edbd58..000000000 --- a/shared/extra-utils/search/videos.ts +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import * as request from 'supertest' | ||
4 | import { VideosSearchQuery } from '../../models/search' | ||
5 | import { immutableAssign } from '../miscs/miscs' | ||
6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
7 | |||
8 | function searchVideo (url: string, search: string, sort = '-publishedAt') { | ||
9 | const path = '/api/v1/search/videos' | ||
10 | |||
11 | const query = { sort, search: search } | ||
12 | const req = request(url) | ||
13 | .get(path) | ||
14 | .query(query) | ||
15 | .set('Accept', 'application/json') | ||
16 | |||
17 | return req.expect(HttpStatusCode.OK_200) | ||
18 | .expect('Content-Type', /json/) | ||
19 | } | ||
20 | |||
21 | function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) { | ||
22 | const path = '/api/v1/search/videos' | ||
23 | const req = request(url) | ||
24 | .get(path) | ||
25 | .set('Authorization', 'Bearer ' + token) | ||
26 | .query(immutableAssign(query, { sort: '-publishedAt', search })) | ||
27 | .set('Accept', 'application/json') | ||
28 | |||
29 | return req.expect(HttpStatusCode.OK_200) | ||
30 | .expect('Content-Type', /json/) | ||
31 | } | ||
32 | |||
33 | function searchVideoWithSort (url: string, search: string, sort: string) { | ||
34 | const path = '/api/v1/search/videos' | ||
35 | |||
36 | const query = { search, sort } | ||
37 | |||
38 | return request(url) | ||
39 | .get(path) | ||
40 | .query(query) | ||
41 | .set('Accept', 'application/json') | ||
42 | .expect(HttpStatusCode.OK_200) | ||
43 | .expect('Content-Type', /json/) | ||
44 | } | ||
45 | |||
46 | function advancedVideosSearch (url: string, options: VideosSearchQuery) { | ||
47 | const path = '/api/v1/search/videos' | ||
48 | |||
49 | return request(url) | ||
50 | .get(path) | ||
51 | .query(options) | ||
52 | .set('Accept', 'application/json') | ||
53 | .expect(HttpStatusCode.OK_200) | ||
54 | .expect('Content-Type', /json/) | ||
55 | } | ||
56 | |||
57 | // --------------------------------------------------------------------------- | ||
58 | |||
59 | export { | ||
60 | searchVideo, | ||
61 | advancedVideosSearch, | ||
62 | searchVideoWithToken, | ||
63 | searchVideoWithSort | ||
64 | } | ||