]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-channel.ts
Use height instead of width to represent the video resolution
[github/Chocobozzz/PeerTube.git] / server / models / video / video-channel.ts
index a65a03e3807a9772329ec5b928cfa12047f470ad..0273fab13c2958856b6eb5f3718444df2881f83e 100644 (file)
@@ -1,20 +1,34 @@
 import {
-  AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table,
-  UpdatedAt, Default, DataType
+  AllowNull,
+  BeforeDestroy,
+  BelongsTo,
+  Column,
+  CreatedAt,
+  DataType,
+  Default,
+  DefaultScope,
+  ForeignKey,
+  HasMany,
+  Is,
+  Model,
+  Scopes,
+  Table,
+  UpdatedAt
 } from 'sequelize-typescript'
 import { ActivityPubActor } from '../../../shared/models/activitypub'
 import { VideoChannel } from '../../../shared/models/videos'
 import {
-  isVideoChannelDescriptionValid, isVideoChannelNameValid,
+  isVideoChannelDescriptionValid,
+  isVideoChannelNameValid,
   isVideoChannelSupportValid
 } from '../../helpers/custom-validators/video-channels'
-import { logger } from '../../helpers/logger'
 import { sendDeleteActor } from '../../lib/activitypub/send'
 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',
@@ -39,7 +53,13 @@ enum ScopeNames {
         include: [
           {
             model: () => ActorModel.unscoped(),
-            required: true
+            required: true,
+            include: [
+              {
+                model: () => AvatarModel.unscoped(),
+                required: false
+              }
+            ]
           }
         ]
       }
@@ -61,6 +81,9 @@ enum ScopeNames {
   indexes: [
     {
       fields: [ 'accountId' ]
+    },
+    {
+      fields: [ 'actorId' ]
     }
   ]
 })
@@ -130,8 +153,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)
     }
 
@@ -233,6 +254,23 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
       .findById(id, options)
   }
 
+  static loadLocalByName (name: string) {
+    const query = {
+      include: [
+        {
+          model: ActorModel,
+          required: true,
+          where: {
+            preferredUsername: name,
+            serverId: null
+          }
+        }
+      ]
+    }
+
+    return VideoChannelModel.findOne(query)
+  }
+
   toFormattedJSON (): VideoChannel {
     const actor = this.Actor.toFormattedJSON()
     const videoChannel = {
@@ -243,8 +281,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
       isLocal: this.Actor.isOwned(),
       createdAt: this.createdAt,
       updatedAt: this.updatedAt,
-      ownerAccount: undefined,
-      videos: undefined
+      ownerAccount: undefined
     }
 
     if (this.Account) videoChannel.ownerAccount = this.Account.toFormattedJSON()