Table,
UpdatedAt
} from 'sequelize-typescript'
+import { v4 as uuidv4 } from 'uuid'
import { MAccountId, MChannelId } from '@server/types/models'
import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object'
import { ThumbnailModel } from './thumbnail'
import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from './video-channel'
import { VideoPlaylistElementModel } from './video-playlist-element'
+import { ActorModel } from '../activitypub/actor'
enum ScopeNames {
AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
}
type AvailableForListOptions = {
- followerActorId: number
+ followerActorId?: number
type?: VideoPlaylistType
accountId?: number
videoChannelId?: number
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
}
}
generateThumbnailName () {
const extension = '.jpg'
- return 'playlist-' + this.uuid + extension
+ return 'playlist-' + uuidv4() + extension
}
getThumbnailUrl () {
return '/video-playlists/embed/' + this.uuid
}
+ 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
+ }
+ }
+
setAsRefreshed () {
this.changed('updatedAt', true)