From 86521a67b2edb06a139b095e489c205457eaba8f Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 17 Apr 2020 10:47:22 +0200 Subject: Add video channel and video thumbnail, rework video appearance in row --- server/lib/emailer.ts | 2 +- server/models/video/video-abuse.ts | 54 +++++++++++++++++++++++------- server/models/video/video.ts | 2 +- server/typings/models/video/video-abuse.ts | 9 ++--- 4 files changed, 49 insertions(+), 18 deletions(-) (limited to 'server') diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 2c0641f3a..5a99edc7f 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts @@ -292,7 +292,7 @@ class Emailer { const videoUrl = WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() const text = 'Hi,\n\n' + - `${WEBSERVER.HOST} received an abuse for the following video ${videoUrl}\n\n` + + `${WEBSERVER.HOST} received an abuse for the following video: ${videoUrl}\n\n` + 'Cheers,\n' + `${CONFIG.EMAIL.BODY.SIGNATURE}` diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index ea9856213..ea943ffdf 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -1,4 +1,6 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { + AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt, DefaultScope +} from 'sequelize-typescript' import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' import { VideoAbuse } from '../../../shared/models/videos' import { @@ -14,7 +16,40 @@ import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/const import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models' import * as Bluebird from 'bluebird' import { literal, Op } from 'sequelize' +import { ThumbnailModel } from './thumbnail' +import { VideoChannelModel } from './video-channel' +import { ActorModel } from '../activitypub/actor' +import { VideoBlacklistModel } from './video-blacklist' +@DefaultScope(() => ({ + include: [ + { + model: AccountModel, + required: true + }, + { + model: VideoModel, + required: false, + include: [ + { + model: ThumbnailModel + }, + { + model: VideoChannelModel.unscoped(), + include: [ + { + model: ActorModel + } + ] + }, + { + attributes: [ 'id', 'reason', 'unfederated' ], + model: VideoBlacklistModel + } + ] + } + ] +})) @Table({ tableName: 'videoAbuse', indexes: [ @@ -114,16 +149,8 @@ export class VideoAbuseModel extends Model { [Op.notIn]: literal('(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')') } }, - include: [ - { - model: AccountModel, - required: true - }, - { - model: VideoModel, - required: false - } - ] + col: 'VideoAbuseModel.id', + distinct: true } return VideoAbuseModel.findAndCountAll(query) @@ -151,7 +178,10 @@ export class VideoAbuseModel extends Model { uuid: video.uuid, name: video.name, nsfw: video.nsfw, - deleted: !this.Video + deleted: !this.Video, + blacklisted: this.Video && this.Video.isBlacklisted(), + thumbnailPath: this.Video?.getMiniatureStaticPath(), + channel: this.Video?.VideoChannel.toFormattedSummaryJSON() || this.deletedVideo?.channel }, createdAt: this.createdAt } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 2636ebd8e..f32216e90 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -810,7 +810,7 @@ export class VideoModel extends Model { if (instance.VideoAbuses.length === 0) return undefined } - const details = instance.toFormattedJSON() + const details = instance.toFormattedDetailsJSON() for (const abuse of instance.VideoAbuses) { tasks.push((_ => { diff --git a/server/typings/models/video/video-abuse.ts b/server/typings/models/video/video-abuse.ts index 49bd1ff2e..54acccdf5 100644 --- a/server/typings/models/video/video-abuse.ts +++ b/server/typings/models/video/video-abuse.ts @@ -1,6 +1,6 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse' import { PickWith } from '../../utils' -import { MVideo } from './video' +import { MVideoAccountLightBlacklistAllFiles } from './video' import { MAccountDefault, MAccountFormattable } from '../account' type Use = PickWith @@ -16,12 +16,12 @@ export type MVideoAbuseId = Pick export type MVideoAbuseVideo = MVideoAbuse & Pick & - Use<'Video', MVideo> + Use<'Video', MVideoAccountLightBlacklistAllFiles> export type MVideoAbuseAccountVideo = MVideoAbuse & Pick & - Use<'Video', MVideo> & + Use<'Video', MVideoAccountLightBlacklistAllFiles> & Use<'Account', MAccountDefault> // ############################################################################ @@ -31,4 +31,5 @@ export type MVideoAbuseAccountVideo = export type MVideoAbuseFormattable = MVideoAbuse & Use<'Account', MAccountFormattable> & - Use<'Video', Pick> + Use<'Video', Pick> -- cgit v1.2.3