From 6b738c7a31591a83fdcd9c78b6b1f98e543c378b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 25 Apr 2018 10:21:38 +0200 Subject: Video channel API routes refractor --- server/models/video/video-channel.ts | 17 +++++++++++++---- server/models/video/video.ts | 11 ++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'server/models') diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 40f3be7fe..4a50af265 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -108,7 +108,7 @@ export class VideoChannelModel extends Model { foreignKey: { allowNull: false }, - onDelete: 'CASCADE' + hooks: true }) Account: AccountModel @@ -234,17 +234,26 @@ export class VideoChannelModel extends Model { toFormattedJSON (): VideoChannel { const actor = this.Actor.toFormattedJSON() - const account = { + const videoChannel = { id: this.id, displayName: this.name, description: this.description, support: this.support, isLocal: this.Actor.isOwned(), createdAt: this.createdAt, - updatedAt: this.updatedAt + updatedAt: this.updatedAt, + ownerAccount: undefined, + videos: undefined + } + + if (this.Account) { + videoChannel.ownerAccount = { + id: this.Account.id, + uuid: this.Account.Actor.uuid + } } - return Object.assign(actor, account) + return Object.assign(actor, videoChannel) } toActivityPubObject (): ActivityPubActor { diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 7ababbf23..f23fac2ab 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -430,7 +430,7 @@ export class VideoModel extends Model { foreignKey: { allowNull: true }, - onDelete: 'cascade' + hooks: true }) VideoChannel: VideoChannelModel @@ -510,10 +510,12 @@ export class VideoModel extends Model { return undefined } - @AfterDestroy + @BeforeDestroy static async removeFilesAndSendDelete (instance: VideoModel) { const tasks: Promise[] = [] + logger.debug('Removing files of video %s.', instance.url) + tasks.push(instance.removeThumbnail()) if (instance.isOwned()) { @@ -530,10 +532,13 @@ export class VideoModel extends Model { }) } - return Promise.all(tasks) + // Do not wait video deletion because we could be in a transaction + Promise.all(tasks) .catch(err => { logger.error('Some errors when removing files of video %s in after destroy hook.', instance.uuid, { err }) }) + + return undefined } static list () { -- cgit v1.2.3