]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-channel.ts
Handle .srt subtitles
[github/Chocobozzz/PeerTube.git] / server / models / video / video-channel.ts
index 289775a0f93312d42e3149bf1c965983ebad04cb..4251afce994d00ab7999b2fb92420b36b8d7bec1 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
+              }
+            ]
           }
         ]
       }
@@ -73,13 +81,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
@@ -108,7 +116,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
     foreignKey: {
       allowNull: false
     },
-    onDelete: 'CASCADE'
+    hooks: true
   })
   Account: AccountModel
 
@@ -151,7 +159,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
     const query = {
       offset: start,
       limit: count,
-      order: [ getSort(sort) ]
+      order: getSort(sort)
     }
 
     return VideoChannelModel
@@ -164,7 +172,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
 
   static listByAccount (accountId: number) {
     const query = {
-      order: [ getSort('createdAt') ],
+      order: getSort('createdAt'),
       include: [
         {
           model: AccountModel,
@@ -234,17 +242,21 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
 
   toFormattedJSON (): VideoChannel {
     const actor = this.Actor.toFormattedJSON()
-    const account = {
+    const videoChannel = {
       id: this.id,
-      displayName: this.name,
+      displayName: this.getDisplayName(),
       description: this.description,
       support: this.support,
       isLocal: this.Actor.isOwned(),
       createdAt: this.createdAt,
-      updatedAt: this.updatedAt
+      updatedAt: this.updatedAt,
+      ownerAccount: undefined,
+      videos: undefined
     }
 
-    return Object.assign(actor, account)
+    if (this.Account) videoChannel.ownerAccount = this.Account.toFormattedJSON()
+
+    return Object.assign(actor, videoChannel)
   }
 
   toActivityPubObject (): ActivityPubActor {
@@ -261,4 +273,8 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
       ]
     })
   }
+
+  getDisplayName () {
+    return this.name
+  }
 }