aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-06 15:22:51 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commitaf971e06c620bd46a5aa64c8833364e7022b5e3d (patch)
tree4288b66b79fe4dd1ab9496e85a3abf7d747ad03a /shared
parent23a3a8827cb8b862f5cc7ee2819f39918303beca (diff)
downloadPeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.tar.gz
PeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.tar.zst
PeerTube-af971e06c620bd46a5aa64c8833364e7022b5e3d.zip
Introduce search command
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/index.ts4
-rw-r--r--shared/extra-utils/overviews/overviews-command.ts1
-rw-r--r--shared/extra-utils/search/index.ts1
-rw-r--r--shared/extra-utils/search/search-command.ts101
-rw-r--r--shared/extra-utils/search/video-channels.ts36
-rw-r--r--shared/extra-utils/search/video-playlists.ts36
-rw-r--r--shared/extra-utils/search/videos.ts64
-rw-r--r--shared/extra-utils/server/servers.ts3
-rw-r--r--shared/extra-utils/videos/videos.ts8
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'
11export * from './requests/check-api-params' 11export * from './requests/check-api-params'
12export * from './requests/requests' 12export * from './requests/requests'
13 13
14export * from './search/video-channels' 14export * from './search'
15export * from './search/video-playlists'
16export * from './search/videos'
17 15
18export * from './server/activitypub' 16export * from './server/activitypub'
19export * from './server/clients' 17export * 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 @@
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}
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 @@
1import { VideoChannelsSearchQuery } from '@shared/models'
2import { makeGetRequest } from '../requests/requests'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4
5function 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
20function 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
33export {
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 @@
1import { VideoPlaylistsSearchQuery } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { makeGetRequest } from '../requests/requests'
4
5function 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
20function 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
33export {
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
3import * as request from 'supertest'
4import { VideosSearchQuery } from '../../models/search'
5import { immutableAssign } from '../miscs/miscs'
6import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
7
8function 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
21function 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
33function 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
46function 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
59export {
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
15import { AbusesCommand } from '../moderation' 15import { AbusesCommand } from '../moderation'
16import { OverviewsCommand } from '../overviews' 16import { OverviewsCommand } from '../overviews'
17import { makeGetRequest } from '../requests/requests' 17import { makeGetRequest } from '../requests/requests'
18import { SearchCommand } from '../search'
18 19
19interface ServerInfo { 20interface 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
80function parallelTests () { 82function 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'
10import { getLowercaseExtension } from '@server/helpers/core-utils' 10import { getLowercaseExtension } from '@server/helpers/core-utils'
11import { buildUUID } from '@server/helpers/uuid' 11import { buildUUID } from '@server/helpers/uuid'
12import { HttpStatusCode } from '@shared/core-utils' 12import { HttpStatusCode } from '@shared/core-utils'
13import { VideosCommonQuery } from '@shared/models' 13import { BooleanBothQuery, VideosCommonQuery } from '@shared/models'
14import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants' 14import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
15import { VideoDetails, VideoPrivacy } from '../../models/videos' 15import { VideoDetails, VideoPrivacy } from '../../models/videos'
16import { 16import {
@@ -159,7 +159,7 @@ function getVideosList (url: string) {
159 .expect('Content-Type', /json/) 159 .expect('Content-Type', /json/)
160} 160}
161 161
162function getVideosListWithToken (url: string, token: string, query: { nsfw?: boolean } = {}) { 162function 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