]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-channel.ts
Import torrents with webtorrent
[github/Chocobozzz/PeerTube.git] / server / models / video / video-channel.ts
index 4a50af265fae906a65f0e060688ef7f1b70ffb7c..d0dba18d5ac16c034b500d96c1a265286b2c0867 100644 (file)
@@ -1,6 +1,6 @@
 import {
   AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table,
-  UpdatedAt, Default
+  UpdatedAt, Default, DataType
 } from 'sequelize-typescript'
 import { ActivityPubActor } from '../../../shared/models/activitypub'
 import { VideoChannel } from '../../../shared/models/videos'
@@ -14,6 +14,8 @@ import { AccountModel } from '../account/account'
 import { ActorModel } from '../activitypub/actor'
 import { getSort, throwIfNotValid } from '../utils'
 import { VideoModel } from './video'
+import { CONSTRAINTS_FIELDS } from '../../initializers'
+import { AvatarModel } from '../avatar/avatar'
 
 enum ScopeNames {
   WITH_ACCOUNT = 'WITH_ACCOUNT',
@@ -33,12 +35,18 @@ enum ScopeNames {
   [ScopeNames.WITH_ACCOUNT]: {
     include: [
       {
-        model: () => AccountModel,
+        model: () => AccountModel.unscoped(),
         required: true,
         include: [
           {
-            model: () => ActorModel,
-            required: true
+            model: () => ActorModel.unscoped(),
+            required: true,
+            include: [
+              {
+                model: () => AvatarModel.unscoped(),
+                required: false
+              }
+            ]
           }
         ]
       }
@@ -60,6 +68,9 @@ enum ScopeNames {
   indexes: [
     {
       fields: [ 'accountId' ]
+    },
+    {
+      fields: [ 'actorId' ]
     }
   ]
 })
@@ -73,13 +84,13 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
   @AllowNull(true)
   @Default(null)
   @Is('VideoChannelDescription', value => throwIfNotValid(value, isVideoChannelDescriptionValid, 'description'))
-  @Column
+  @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_CHANNELS.DESCRIPTION.max))
   description: string
 
   @AllowNull(true)
   @Default(null)
   @Is('VideoChannelSupport', value => throwIfNotValid(value, isVideoChannelSupportValid, 'support'))
-  @Column
+  @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_CHANNELS.SUPPORT.max))
   support: string
 
   @CreatedAt
@@ -129,8 +140,6 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
     }
 
     if (instance.Actor.isOwned()) {
-      logger.debug('Sending delete of actor of video channel %s.', instance.Actor.url)
-
       return sendDeleteActor(instance.Actor, options.transaction)
     }
 
@@ -236,7 +245,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
     const actor = this.Actor.toFormattedJSON()
     const videoChannel = {
       id: this.id,
-      displayName: this.name,
+      displayName: this.getDisplayName(),
       description: this.description,
       support: this.support,
       isLocal: this.Actor.isOwned(),
@@ -246,12 +255,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
       videos: undefined
     }
 
-    if (this.Account) {
-      videoChannel.ownerAccount = {
-        id: this.Account.id,
-        uuid: this.Account.Actor.uuid
-      }
-    }
+    if (this.Account) videoChannel.ownerAccount = this.Account.toFormattedJSON()
 
     return Object.assign(actor, videoChannel)
   }
@@ -270,4 +274,8 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
       ]
     })
   }
+
+  getDisplayName () {
+    return this.name
+  }
 }