]> 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 33a19f0ff224706503bbde130c56aa22fb651f2c..0273fab13c2958856b6eb5f3718444df2881f83e 100644 (file)
@@ -22,6 +22,7 @@ import {
   isVideoChannelNameValid,
   isVideoChannelSupportValid
 } from '../../helpers/custom-validators/video-channels'
+import { sendDeleteActor } from '../../lib/activitypub/send'
 import { AccountModel } from '../account/account'
 import { ActorModel } from '../activitypub/actor'
 import { getSort, throwIfNotValid } from '../utils'
@@ -151,7 +152,11 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
       instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
     }
 
-    return instance.Actor.destroy({ transaction: options.transaction })
+    if (instance.Actor.isOwned()) {
+      return sendDeleteActor(instance.Actor, options.transaction)
+    }
+
+    return undefined
   }
 
   static countByAccount (accountId: number) {
@@ -249,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 = {
@@ -259,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()