X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-playlist.ts;h=1a05f8d4256d39db2ba246ed7c824038448fc2a5;hb=20a206c3d12ad285c31411cd506cede791958322;hp=49a406608ff63d43f7526f9f92b77fd288eb25a0;hpb=a35a22797c99f17924347da9a226068c3dbe4787;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 49a406608..1a05f8d42 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts @@ -18,7 +18,9 @@ import { UpdatedAt } from 'sequelize-typescript' import { v4 as uuidv4 } from 'uuid' +import { setAsUpdated } from '@server/helpers/database-utils' import { MAccountId, MChannelId } from '@server/types/models' +import { AttributesOnly } from '@shared/core-utils' import { ActivityIconObject } from '../../../shared/models/activitypub/objects' import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' @@ -50,6 +52,7 @@ import { MVideoPlaylistIdWithElements } from '../../types/models/video/video-playlist' import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions } from '../account/account' +import { ActorModel } from '../actor/actor' import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getPlaylistSort, isOutdated, throwIfNotValid } from '../utils' import { ThumbnailModel } from './thumbnail' import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from './video-channel' @@ -65,7 +68,7 @@ enum ScopeNames { } type AvailableForListOptions = { - followerActorId: number + followerActorId?: number type?: VideoPlaylistType accountId?: number videoChannelId?: number @@ -134,20 +137,26 @@ type AvailableForListOptions = { privacy: VideoPlaylistPrivacy.PUBLIC }) - // Only list local playlists OR playlists that are on an instance followed by actorId - const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId) + // Only list local playlists + const whereActorOr: WhereOptions[] = [ + { + serverId: null + } + ] - whereActor = { - [Op.or]: [ - { - serverId: null - }, - { - serverId: { - [Op.in]: literal(inQueryInstanceFollow) - } + // … OR playlists that are on an instance followed by actorId + if (options.followerActorId) { + const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId) + + whereActorOr.push({ + serverId: { + [Op.in]: literal(inQueryInstanceFollow) } - ] + }) + } + + whereActor = { + [Op.or]: whereActorOr } } @@ -214,7 +223,7 @@ type AvailableForListOptions = { } ] }) -export class VideoPlaylistModel extends Model { +export class VideoPlaylistModel extends Model>> { @CreatedAt createdAt: Date @@ -488,17 +497,42 @@ export class VideoPlaylistModel extends Model { } getWatchUrl () { - return WEBSERVER.URL + '/videos/watch/playlist/' + this.uuid + return WEBSERVER.URL + '/w/p/' + this.uuid } getEmbedStaticPath () { return '/video-playlists/embed/' + this.uuid } - setAsRefreshed () { - this.changed('updatedAt', true) + static async getStats () { + const totalLocalPlaylists = await VideoPlaylistModel.count({ + include: [ + { + model: AccountModel, + required: true, + include: [ + { + model: ActorModel, + required: true, + where: { + serverId: null + } + } + ] + } + ], + where: { + privacy: VideoPlaylistPrivacy.PUBLIC + } + }) + + return { + totalLocalPlaylists + } + } - return this.save() + setAsRefreshed () { + return setAsUpdated('videoPlaylist', this.id) } isOwned () {