1 import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2 import { VideoAbuseObject } from '../../../shared/models/activitypub/objects'
3 import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos'
4 import { CONFIG } from '../../initializers'
5 import { Emailer } from '../../lib/emailer'
6 import { AccountModel } from '../account/account'
7 import { getSort, throwIfNotValid } from '../utils'
8 import { VideoModel } from './video'
11 tableName: 'videoAbuse',
17 fields: [ 'reporterAccountId' ]
21 export class VideoAbuseModel extends Model<VideoAbuseModel> {
24 @Is('VideoAbuseReason', value => throwIfNotValid(value, isVideoAbuseReasonValid, 'reason'))
34 @ForeignKey(() => AccountModel)
36 reporterAccountId: number
38 @BelongsTo(() => AccountModel, {
46 @ForeignKey(() => VideoModel)
50 @BelongsTo(() => VideoModel, {
59 static sendEmailNotification (instance: VideoAbuseModel) {
60 return Emailer.Instance.addVideoAbuseReport(instance.videoId)
63 static listForApi (start: number, count: number, sort: string) {
67 order: [ getSort(sort) ],
80 return VideoAbuseModel.findAndCountAll(query)
81 .then(({ rows, count }) => {
82 return { total: count, data: rows }
87 let reporterServerHost
89 if (this.Account.Actor.Server) {
90 reporterServerHost = this.Account.Actor.Server.host
92 // It means it's our video
93 reporterServerHost = CONFIG.WEBSERVER.HOST
99 reporterUsername: this.Account.name,
101 videoId: this.Video.id,
102 videoUUID: this.Video.uuid,
103 videoName: this.Video.name,
104 createdAt: this.createdAt
108 toActivityPubObject (): VideoAbuseObject {
110 type: 'Flag' as 'Flag',
111 content: this.reason,
112 object: this.Video.url