diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-06 15:22:51 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | af971e06c620bd46a5aa64c8833364e7022b5e3d (patch) | |
tree | 4288b66b79fe4dd1ab9496e85a3abf7d747ad03a /shared | |
parent | 23a3a8827cb8b862f5cc7ee2819f39918303beca (diff) | |
download | PeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.tar.gz PeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.tar.zst PeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.zip |
Introduce search command
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/index.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/overviews/overviews-command.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/search/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/search/search-command.ts | 101 | ||||
-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 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/videos/videos.ts | 8 |
9 files changed, 110 insertions, 144 deletions
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 38c8c4c1c..067e6fb65 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -11,9 +11,7 @@ export * from './overviews' | |||
11 | export * from './requests/check-api-params' | 11 | export * from './requests/check-api-params' |
12 | export * from './requests/requests' | 12 | export * from './requests/requests' |
13 | 13 | ||
14 | export * from './search/video-channels' | 14 | export * from './search' |
15 | export * from './search/video-playlists' | ||
16 | export * from './search/videos' | ||
17 | 15 | ||
18 | export * from './server/activitypub' | 16 | export * from './server/activitypub' |
19 | export * from './server/clients' | 17 | export * from './server/clients' |
diff --git a/shared/extra-utils/overviews/overviews-command.ts b/shared/extra-utils/overviews/overviews-command.ts index 0ac3cbd33..6f56b0ce4 100644 --- a/shared/extra-utils/overviews/overviews-command.ts +++ b/shared/extra-utils/overviews/overviews-command.ts | |||
@@ -6,7 +6,6 @@ export class OverviewsCommand extends AbstractCommand { | |||
6 | 6 | ||
7 | getVideos (options: OverrideCommandOptions & { | 7 | getVideos (options: OverrideCommandOptions & { |
8 | page: number | 8 | page: number |
9 | token?: string | ||
10 | }) { | 9 | }) { |
11 | const { token, page } = options | 10 | const { token, page } = options |
12 | const path = '/api/v1/overviews/videos' | 11 | const path = '/api/v1/overviews/videos' |
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..d4cfab32b --- /dev/null +++ b/shared/extra-utils/search/search-command.ts | |||
@@ -0,0 +1,101 @@ | |||
1 | import { | ||
2 | ResultList, | ||
3 | Video, | ||
4 | VideoChannel, | ||
5 | VideoChannelsSearchQuery, | ||
6 | VideoPlaylist, | ||
7 | VideoPlaylistsSearchQuery, | ||
8 | VideosSearchQuery | ||
9 | } from '@shared/models' | ||
10 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
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, 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 | } | ||
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 | } | ||
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 70be96cf6..8ccf790fc 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -15,6 +15,7 @@ import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../mi | |||
15 | import { AbusesCommand } from '../moderation' | 15 | import { AbusesCommand } from '../moderation' |
16 | import { OverviewsCommand } from '../overviews' | 16 | import { OverviewsCommand } from '../overviews' |
17 | import { makeGetRequest } from '../requests/requests' | 17 | import { makeGetRequest } from '../requests/requests' |
18 | import { SearchCommand } from '../search' | ||
18 | 19 | ||
19 | interface ServerInfo { | 20 | interface ServerInfo { |
20 | app: ChildProcess | 21 | app: ChildProcess |
@@ -75,6 +76,7 @@ interface ServerInfo { | |||
75 | logsCommand?: LogsCommand | 76 | logsCommand?: LogsCommand |
76 | abusesCommand?: AbusesCommand | 77 | abusesCommand?: AbusesCommand |
77 | overviewsCommand?: OverviewsCommand | 78 | overviewsCommand?: OverviewsCommand |
79 | searchCommand?: SearchCommand | ||
78 | } | 80 | } |
79 | 81 | ||
80 | function parallelTests () { | 82 | function parallelTests () { |
@@ -287,6 +289,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
287 | server.logsCommand = new LogsCommand(server) | 289 | server.logsCommand = new LogsCommand(server) |
288 | server.abusesCommand = new AbusesCommand(server) | 290 | server.abusesCommand = new AbusesCommand(server) |
289 | server.overviewsCommand = new OverviewsCommand(server) | 291 | server.overviewsCommand = new OverviewsCommand(server) |
292 | server.searchCommand = new SearchCommand(server) | ||
290 | 293 | ||
291 | res(server) | 294 | res(server) |
292 | }) | 295 | }) |
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 469ea4d63..a45c0402a 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts | |||
@@ -10,7 +10,7 @@ import validator from 'validator' | |||
10 | import { getLowercaseExtension } from '@server/helpers/core-utils' | 10 | import { getLowercaseExtension } from '@server/helpers/core-utils' |
11 | import { buildUUID } from '@server/helpers/uuid' | 11 | import { buildUUID } from '@server/helpers/uuid' |
12 | import { HttpStatusCode } from '@shared/core-utils' | 12 | import { HttpStatusCode } from '@shared/core-utils' |
13 | import { VideosCommonQuery } from '@shared/models' | 13 | import { BooleanBothQuery, VideosCommonQuery } from '@shared/models' |
14 | import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' | 14 | import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' |
15 | import { VideoDetails, VideoPrivacy } from '../../models/videos' | 15 | import { VideoDetails, VideoPrivacy } from '../../models/videos' |
16 | import { | 16 | import { |
@@ -159,7 +159,7 @@ function getVideosList (url: string) { | |||
159 | .expect('Content-Type', /json/) | 159 | .expect('Content-Type', /json/) |
160 | } | 160 | } |
161 | 161 | ||
162 | function getVideosListWithToken (url: string, token: string, query: { nsfw?: boolean } = {}) { | 162 | function getVideosListWithToken (url: string, token: string, query: { nsfw?: BooleanBothQuery } = {}) { |
163 | const path = '/api/v1/videos' | 163 | const path = '/api/v1/videos' |
164 | 164 | ||
165 | return request(url) | 165 | return request(url) |
@@ -219,7 +219,7 @@ function getAccountVideos ( | |||
219 | count: number, | 219 | count: number, |
220 | sort?: string, | 220 | sort?: string, |
221 | query: { | 221 | query: { |
222 | nsfw?: boolean | 222 | nsfw?: BooleanBothQuery |
223 | search?: string | 223 | search?: string |
224 | } = {} | 224 | } = {} |
225 | ) { | 225 | ) { |
@@ -245,7 +245,7 @@ function getVideoChannelVideos ( | |||
245 | start: number, | 245 | start: number, |
246 | count: number, | 246 | count: number, |
247 | sort?: string, | 247 | sort?: string, |
248 | query: { nsfw?: boolean } = {} | 248 | query: { nsfw?: BooleanBothQuery } = {} |
249 | ) { | 249 | ) { |
250 | const path = '/api/v1/video-channels/' + videoChannelName + '/videos' | 250 | const path = '/api/v1/video-channels/' + videoChannelName + '/videos' |
251 | 251 | ||