X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-channel.ts;h=9f04a57c64025f11baa6e9d02fee6f4ef1208141;hb=9c9a236b541a286e165d67341e4ddd6ea2fabdf1;hp=327f493048f742fc070eafc6621be70d0cb069f0;hpb=fbd67e7f386504e50f2504cb6386700a58906f16;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 327f49304..9f04a57c6 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -18,7 +18,7 @@ import { UpdatedAt } from 'sequelize-typescript' import { MAccountActor } from '@server/types/models' -import { AttributesOnly } from '@shared/core-utils' +import { AttributesOnly, pick } from '@shared/core-utils' import { ActivityPubActor } from '../../../shared/models/activitypub' import { VideoChannel, VideoChannelSummary } from '../../../shared/models/videos' import { @@ -59,7 +59,7 @@ type AvailableForListOptions = { actorId: number search?: string host?: string - names?: string[] + handles?: string[] } type AvailableWithStatsOptions = { @@ -114,15 +114,33 @@ export type SummaryOptions = { }) } - if (options.names) { - whereActorAnd.push({ - preferredUsername: { - [Op.in]: options.names + let rootWhere: WhereOptions + if (options.handles) { + const or: WhereOptions[] = [] + + for (const handle of options.handles || []) { + const [ preferredUsername, host ] = handle.split('@') + + if (!host) { + or.push({ + '$Actor.preferredUsername$': preferredUsername, + '$Actor.serverId$': null + }) + } else { + or.push({ + '$Actor.preferredUsername$': preferredUsername, + '$Actor.Server.host$': host + }) } - }) + } + + rootWhere = { + [Op.or]: or + } } return { + where: rootWhere, include: [ { attributes: { @@ -420,30 +438,6 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` } } - static listForApi (parameters: { - actorId: number - start: number - count: number - sort: string - }) { - const { actorId } = parameters - - const query = { - offset: parameters.start, - limit: parameters.count, - order: getSort(parameters.sort) - } - - return VideoChannelModel - .scope({ - method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ] - }) - .findAndCountAll(query) - .then(({ rows, count }) => { - return { total: count, data: rows } - }) - } - static listLocalsForSitemap (sort: string): Promise { const query = { attributes: [ ], @@ -465,15 +459,33 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` .findAll(query) } - static searchForApi (options: { - actorId: number - search?: string + static listForApi (parameters: Pick & { start: number count: number sort: string + }) { + const { actorId } = parameters + + const query = { + offset: parameters.start, + limit: parameters.count, + order: getSort(parameters.sort) + } + + return VideoChannelModel + .scope({ + method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ] + }) + .findAndCountAll(query) + .then(({ rows, count }) => { + return { total: count, data: rows } + }) + } - host?: string - names?: string[] + static searchForApi (options: Pick & { + start: number + count: number + sort: string }) { let attributesInclude: any[] = [ literal('0 as similarity') ] let where: WhereOptions @@ -507,7 +519,7 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` return VideoChannelModel .scope({ - method: [ ScopeNames.FOR_API, { actorId: options.actorId, host: options.host, names: options.names } as AvailableForListOptions ] + method: [ ScopeNames.FOR_API, pick(options, [ 'actorId', 'host', 'handles' ]) as AvailableForListOptions ] }) .findAndCountAll(query) .then(({ rows, count }) => {