X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-channel.ts;h=2c6669bcba9262ef9700502b0b186c47f597b0f3;hb=57a9b61a4aeead74e8800bbfad82ef433313b204;hp=9f04a57c64025f11baa6e9d02fee6f4ef1208141;hpb=9e8789497377cac5554a622da605f5b89587aa9c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 9f04a57c6..2c6669bcb 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -17,13 +17,15 @@ import { Table, UpdatedAt } from 'sequelize-typescript' +import { CONFIG } from '@server/initializers/config' import { MAccountActor } from '@server/types/models' -import { AttributesOnly, pick } from '@shared/core-utils' +import { pick } from '@shared/core-utils' +import { AttributesOnly } from '@shared/typescript-utils' import { ActivityPubActor } from '../../../shared/models/activitypub' import { VideoChannel, VideoChannelSummary } from '../../../shared/models/videos' import { isVideoChannelDescriptionValid, - isVideoChannelNameValid, + isVideoChannelDisplayNameValid, isVideoChannelSupportValid } from '../../helpers/custom-validators/video-channels' import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' @@ -121,7 +123,7 @@ export type SummaryOptions = { for (const handle of options.handles || []) { const [ preferredUsername, host ] = handle.split('@') - if (!host) { + if (!host || host === WEBSERVER.HOST) { or.push({ '$Actor.preferredUsername$': preferredUsername, '$Actor.serverId$': null @@ -308,7 +310,7 @@ export type SummaryOptions = { export class VideoChannelModel extends Model>> { @AllowNull(false) - @Is('VideoChannelName', value => throwIfNotValid(value, isVideoChannelNameValid, 'name')) + @Is('VideoChannelName', value => throwIfNotValid(value, isVideoChannelDisplayNameValid, 'name')) @Column name: string @@ -527,7 +529,7 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` }) } - static listByAccount (options: { + static listByAccountForAPI (options: { accountId: number start: number count: number @@ -582,6 +584,24 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` }) } + static listAllByAccount (accountId: number) { + const query = { + limit: CONFIG.VIDEO_CHANNELS.MAX_PER_USER, + include: [ + { + attributes: [], + model: AccountModel, + where: { + id: accountId + }, + required: true + } + ] + } + + return VideoChannelModel.findAll(query) + } + static loadAndPopulateAccount (id: number, transaction?: Transaction): Promise { return VideoChannelModel.unscoped() .scope([ ScopeNames.WITH_ACTOR_BANNER, ScopeNames.WITH_ACCOUNT ]) @@ -753,7 +773,7 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` return this.Actor.isOutdated() } - setAsUpdated (transaction: Transaction) { + setAsUpdated (transaction?: Transaction) { return setAsUpdated('videoChannel', this.id, transaction) } }