From b033851fb54241bb703f86add025229e68cc6f59 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 29 Jul 2021 10:27:24 +0200 Subject: Search channels against handles and not names --- shared/core-utils/index.ts | 1 + shared/core-utils/utils/index.ts | 1 + shared/core-utils/utils/object.ts | 15 +++++++++++++++ shared/extra-utils/moderation/abuses-command.ts | 6 +++--- shared/extra-utils/server/follows-command.ts | 8 +++----- shared/extra-utils/server/jobs-command.ts | 2 +- shared/extra-utils/users/users-command.ts | 3 ++- shared/extra-utils/videos/channels-command.ts | 2 +- shared/extra-utils/videos/playlists-command.ts | 3 ++- shared/extra-utils/videos/videos-command.ts | 3 ++- shared/models/search/video-channels-search-query.model.ts | 2 +- 11 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 shared/core-utils/utils/index.ts create mode 100644 shared/core-utils/utils/object.ts (limited to 'shared') diff --git a/shared/core-utils/index.ts b/shared/core-utils/index.ts index 66d50ef93..2a7d4d982 100644 --- a/shared/core-utils/index.ts +++ b/shared/core-utils/index.ts @@ -4,3 +4,4 @@ export * from './i18n' export * from './plugins' export * from './renderer' export * from './users' +export * from './utils' diff --git a/shared/core-utils/utils/index.ts b/shared/core-utils/utils/index.ts new file mode 100644 index 000000000..a71977d88 --- /dev/null +++ b/shared/core-utils/utils/index.ts @@ -0,0 +1 @@ +export * from './object' diff --git a/shared/core-utils/utils/object.ts b/shared/core-utils/utils/object.ts new file mode 100644 index 000000000..7b2bb81d0 --- /dev/null +++ b/shared/core-utils/utils/object.ts @@ -0,0 +1,15 @@ +function pick (object: T, keys: (keyof T)[]) { + const result: Partial = {} + + for (const key of keys) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + result[key] = object[key] + } + } + + return result +} + +export { + pick +} diff --git a/shared/extra-utils/moderation/abuses-command.ts b/shared/extra-utils/moderation/abuses-command.ts index 7b3abb056..0db32ba46 100644 --- a/shared/extra-utils/moderation/abuses-command.ts +++ b/shared/extra-utils/moderation/abuses-command.ts @@ -1,4 +1,4 @@ -import { pick } from 'lodash' +import { pick } from '@shared/core-utils' import { AbuseFilter, AbuseMessage, @@ -81,7 +81,7 @@ export class AbusesCommand extends AbstractCommand { searchVideo?: string searchVideoChannel?: string } = {}) { - const toPick = [ + const toPick: (keyof typeof options)[] = [ 'count', 'filter', 'id', @@ -121,7 +121,7 @@ export class AbusesCommand extends AbstractCommand { search?: string state?: AbuseState }) { - const toPick = [ + const toPick: (keyof typeof options)[] = [ 'id', 'search', 'state', diff --git a/shared/extra-utils/server/follows-command.ts b/shared/extra-utils/server/follows-command.ts index 2b889cf66..01ef6f179 100644 --- a/shared/extra-utils/server/follows-command.ts +++ b/shared/extra-utils/server/follows-command.ts @@ -1,4 +1,4 @@ -import { pick } from 'lodash' +import { pick } from '@shared/core-utils' import { ActivityPubActorType, ActorFollow, FollowState, HttpStatusCode, ResultList, ServerFollowCreate } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' import { PeerTubeServer } from './server' @@ -15,8 +15,7 @@ export class FollowsCommand extends AbstractCommand { }) { const path = '/api/v1/server/followers' - const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ] - const query = pick(options, toPick) + const query = pick(options, [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]) return this.getRequestBody>({ ...options, @@ -38,8 +37,7 @@ export class FollowsCommand extends AbstractCommand { } = {}) { const path = '/api/v1/server/following' - const toPick = [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ] - const query = pick(options, toPick) + const query = pick(options, [ 'start', 'count', 'sort', 'search', 'state', 'actorType' ]) return this.getRequestBody>({ ...options, diff --git a/shared/extra-utils/server/jobs-command.ts b/shared/extra-utils/server/jobs-command.ts index 09a299e5b..c4eb12dc2 100644 --- a/shared/extra-utils/server/jobs-command.ts +++ b/shared/extra-utils/server/jobs-command.ts @@ -1,4 +1,4 @@ -import { pick } from 'lodash' +import { pick } from '@shared/core-utils' import { HttpStatusCode } from '@shared/models' import { Job, JobState, JobType, ResultList } from '../../models' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/extra-utils/users/users-command.ts b/shared/extra-utils/users/users-command.ts index d66ad15f2..ddd20d041 100644 --- a/shared/extra-utils/users/users-command.ts +++ b/shared/extra-utils/users/users-command.ts @@ -1,4 +1,5 @@ -import { omit, pick } from 'lodash' +import { omit } from 'lodash' +import { pick } from '@shared/core-utils' import { HttpStatusCode, MyUser, diff --git a/shared/extra-utils/videos/channels-command.ts b/shared/extra-utils/videos/channels-command.ts index f8eb3f885..255e1d62d 100644 --- a/shared/extra-utils/videos/channels-command.ts +++ b/shared/extra-utils/videos/channels-command.ts @@ -1,4 +1,4 @@ -import { pick } from 'lodash' +import { pick } from '@shared/core-utils' import { HttpStatusCode, ResultList, VideoChannel, VideoChannelCreateResult } from '@shared/models' import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model' import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model' diff --git a/shared/extra-utils/videos/playlists-command.ts b/shared/extra-utils/videos/playlists-command.ts index 6f329800e..ce23900d3 100644 --- a/shared/extra-utils/videos/playlists-command.ts +++ b/shared/extra-utils/videos/playlists-command.ts @@ -1,4 +1,5 @@ -import { omit, pick } from 'lodash' +import { omit } from 'lodash' +import { pick } from '@shared/core-utils' import { BooleanBothQuery, HttpStatusCode, diff --git a/shared/extra-utils/videos/videos-command.ts b/shared/extra-utils/videos/videos-command.ts index 98465e8f6..33725bfdc 100644 --- a/shared/extra-utils/videos/videos-command.ts +++ b/shared/extra-utils/videos/videos-command.ts @@ -3,10 +3,11 @@ import { expect } from 'chai' import { createReadStream, stat } from 'fs-extra' import got, { Response as GotResponse } from 'got' -import { omit, pick } from 'lodash' +import { omit } from 'lodash' import validator from 'validator' import { buildUUID } from '@server/helpers/uuid' import { loadLanguages } from '@server/initializers/constants' +import { pick } from '@shared/core-utils' import { HttpStatusCode, ResultList, diff --git a/shared/models/search/video-channels-search-query.model.ts b/shared/models/search/video-channels-search-query.model.ts index 50c59d41d..77cea4a59 100644 --- a/shared/models/search/video-channels-search-query.model.ts +++ b/shared/models/search/video-channels-search-query.model.ts @@ -8,5 +8,5 @@ export interface VideoChannelsSearchQuery extends SearchTargetQuery { sort?: string host?: string - names?: string[] + handles?: string[] } -- cgit v1.2.3