From af971e06c620bd46a5aa64c8833364e7022b5e3d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 15:22:51 +0200 Subject: Introduce search command --- shared/extra-utils/search/index.ts | 1 + shared/extra-utils/search/search-command.ts | 101 +++++++++++++++++++++++++++ shared/extra-utils/search/video-channels.ts | 36 ---------- shared/extra-utils/search/video-playlists.ts | 36 ---------- shared/extra-utils/search/videos.ts | 64 ----------------- 5 files changed, 102 insertions(+), 136 deletions(-) create mode 100644 shared/extra-utils/search/index.ts create mode 100644 shared/extra-utils/search/search-command.ts delete mode 100644 shared/extra-utils/search/video-channels.ts delete mode 100644 shared/extra-utils/search/video-playlists.ts delete mode 100644 shared/extra-utils/search/videos.ts (limited to 'shared/extra-utils/search') 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 @@ +import { + ResultList, + Video, + VideoChannel, + VideoChannelsSearchQuery, + VideoPlaylist, + VideoPlaylistsSearchQuery, + VideosSearchQuery +} from '@shared/models' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class SearchCommand extends AbstractCommand { + + searchChannels (options: OverrideCommandOptions & { + search: string + }) { + return this.advancedChannelSearch({ + ...options, + + search: { search: options.search } + }) + } + + advancedChannelSearch (options: OverrideCommandOptions & { + search: VideoChannelsSearchQuery + }) { + const { search, token } = options + const path = '/api/v1/search/video-channels' + + return this.getRequestBody>({ + ...options, + + token: token || null, + + path, + query: search, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + searchPlaylists (options: OverrideCommandOptions & { + search: string + }) { + return this.advancedPlaylistSearch({ + ...options, + + search: { search: options.search } + }) + } + + advancedPlaylistSearch (options: OverrideCommandOptions & { + search: VideoPlaylistsSearchQuery + }) { + const { search, token } = options + const path = '/api/v1/search/video-playlists' + + return this.getRequestBody>({ + ...options, + + token: token || null, + + path, + query: search, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + searchVideos (options: OverrideCommandOptions & { + search: string + sort?: string + }) { + const { search, sort } = options + + return this.advancedVideoSearch({ + ...options, + + search: { + search: search, + sort: sort ?? '-publishedAt' + } + }) + } + + advancedVideoSearch (options: OverrideCommandOptions & { + search: VideosSearchQuery + }) { + const { search, token } = options + const path = '/api/v1/search/videos' + + return this.getRequestBody>({ + ...options, + + token: token || null, + + path, + query: search, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } +} 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 @@ -import { VideoChannelsSearchQuery } from '@shared/models' -import { makeGetRequest } from '../requests/requests' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function searchVideoChannel (url: string, search: string, token?: string, statusCodeExpected = HttpStatusCode.OK_200) { - const path = '/api/v1/search/video-channels' - - return makeGetRequest({ - url, - path, - query: { - sort: '-createdAt', - search - }, - token, - statusCodeExpected - }) -} - -function advancedVideoChannelSearch (url: string, search: VideoChannelsSearchQuery) { - const path = '/api/v1/search/video-channels' - - return makeGetRequest({ - url, - path, - query: search, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -// --------------------------------------------------------------------------- - -export { - searchVideoChannel, - advancedVideoChannelSearch -} 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 @@ -import { VideoPlaylistsSearchQuery } from '@shared/models' -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' -import { makeGetRequest } from '../requests/requests' - -function searchVideoPlaylists (url: string, search: string, token?: string, statusCodeExpected = HttpStatusCode.OK_200) { - const path = '/api/v1/search/video-playlists' - - return makeGetRequest({ - url, - path, - query: { - sort: '-createdAt', - search - }, - token, - statusCodeExpected - }) -} - -function advancedVideoPlaylistSearch (url: string, search: VideoPlaylistsSearchQuery) { - const path = '/api/v1/search/video-playlists' - - return makeGetRequest({ - url, - path, - query: search, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -// --------------------------------------------------------------------------- - -export { - searchVideoPlaylists, - advancedVideoPlaylistSearch -} 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 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import * as request from 'supertest' -import { VideosSearchQuery } from '../../models/search' -import { immutableAssign } from '../miscs/miscs' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function searchVideo (url: string, search: string, sort = '-publishedAt') { - const path = '/api/v1/search/videos' - - const query = { sort, search: search } - const req = request(url) - .get(path) - .query(query) - .set('Accept', 'application/json') - - return req.expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function searchVideoWithToken (url: string, search: string, token: string, query: { nsfw?: boolean } = {}) { - const path = '/api/v1/search/videos' - const req = request(url) - .get(path) - .set('Authorization', 'Bearer ' + token) - .query(immutableAssign(query, { sort: '-publishedAt', search })) - .set('Accept', 'application/json') - - return req.expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function searchVideoWithSort (url: string, search: string, sort: string) { - const path = '/api/v1/search/videos' - - const query = { search, sort } - - return request(url) - .get(path) - .query(query) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -function advancedVideosSearch (url: string, options: VideosSearchQuery) { - const path = '/api/v1/search/videos' - - return request(url) - .get(path) - .query(options) - .set('Accept', 'application/json') - .expect(HttpStatusCode.OK_200) - .expect('Content-Type', /json/) -} - -// --------------------------------------------------------------------------- - -export { - searchVideo, - advancedVideosSearch, - searchVideoWithToken, - searchVideoWithSort -} -- cgit v1.2.3 From a1637fa1e25b60a88f7cfe50aac8953f50d55761 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 10:55:16 +0200 Subject: Specify if we want to fallback to the server token --- shared/extra-utils/search/search-command.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'shared/extra-utils/search') diff --git a/shared/extra-utils/search/search-command.ts b/shared/extra-utils/search/search-command.ts index d4cfab32b..7539a21ec 100644 --- a/shared/extra-utils/search/search-command.ts +++ b/shared/extra-utils/search/search-command.ts @@ -25,16 +25,15 @@ export class SearchCommand extends AbstractCommand { advancedChannelSearch (options: OverrideCommandOptions & { search: VideoChannelsSearchQuery }) { - const { search, token } = options + const { search } = options const path = '/api/v1/search/video-channels' return this.getRequestBody>({ ...options, - token: token || null, - path, query: search, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -52,16 +51,15 @@ export class SearchCommand extends AbstractCommand { advancedPlaylistSearch (options: OverrideCommandOptions & { search: VideoPlaylistsSearchQuery }) { - const { search, token } = options + const { search } = options const path = '/api/v1/search/video-playlists' return this.getRequestBody>({ ...options, - token: token || null, - path, query: search, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } @@ -85,16 +83,15 @@ export class SearchCommand extends AbstractCommand { advancedVideoSearch (options: OverrideCommandOptions & { search: VideosSearchQuery }) { - const { search, token } = options + const { search } = options const path = '/api/v1/search/videos' return this.getRequestBody>({ ...options, - token: token || null, - path, query: search, + implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) } -- cgit v1.2.3 From dd0ebb715123dfa126a82d4e4fe3a04064ae77b8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 16:23:01 +0200 Subject: Introduce notifications command --- shared/extra-utils/search/search-command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared/extra-utils/search') diff --git a/shared/extra-utils/search/search-command.ts b/shared/extra-utils/search/search-command.ts index 7539a21ec..b6054f093 100644 --- a/shared/extra-utils/search/search-command.ts +++ b/shared/extra-utils/search/search-command.ts @@ -90,7 +90,7 @@ export class SearchCommand extends AbstractCommand { ...options, path, - query: search, + query: { sort: '-publishedAt', ...search }, implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) -- cgit v1.2.3 From 5e2fea3ab9357c228b5d21166092f9a2368e258e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 12 Jul 2021 16:06:57 +0200 Subject: Fix search tests --- shared/extra-utils/search/search-command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared/extra-utils/search') diff --git a/shared/extra-utils/search/search-command.ts b/shared/extra-utils/search/search-command.ts index b6054f093..7539a21ec 100644 --- a/shared/extra-utils/search/search-command.ts +++ b/shared/extra-utils/search/search-command.ts @@ -90,7 +90,7 @@ export class SearchCommand extends AbstractCommand { ...options, path, - query: { sort: '-publishedAt', ...search }, + query: search, implicitToken: false, defaultExpectedStatus: HttpStatusCode.OK_200 }) -- cgit v1.2.3 From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- shared/extra-utils/search/search-command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared/extra-utils/search') diff --git a/shared/extra-utils/search/search-command.ts b/shared/extra-utils/search/search-command.ts index 7539a21ec..09f5d3f1d 100644 --- a/shared/extra-utils/search/search-command.ts +++ b/shared/extra-utils/search/search-command.ts @@ -7,7 +7,7 @@ import { VideoPlaylistsSearchQuery, VideosSearchQuery } from '@shared/models' -import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class SearchCommand extends AbstractCommand { -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- shared/extra-utils/search/search-command.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'shared/extra-utils/search') diff --git a/shared/extra-utils/search/search-command.ts b/shared/extra-utils/search/search-command.ts index 09f5d3f1d..0fbbcd6ef 100644 --- a/shared/extra-utils/search/search-command.ts +++ b/shared/extra-utils/search/search-command.ts @@ -1,4 +1,5 @@ import { + HttpStatusCode, ResultList, Video, VideoChannel, @@ -7,7 +8,6 @@ import { VideoPlaylistsSearchQuery, VideosSearchQuery } from '@shared/models' -import { HttpStatusCode } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class SearchCommand extends AbstractCommand { -- cgit v1.2.3