1 import { 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 { AccountModel } from '../account/account'
6 import { ServerModel } from '../server/server'
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, {
58 static listForApi (start: number, count: number, sort: string) {
62 order: [ getSort(sort) ],
81 return VideoAbuseModel.findAndCountAll(query)
82 .then(({ rows, count }) => {
83 return { total: count, data: rows }
88 let reporterServerHost
90 if (this.Account.Server) {
91 reporterServerHost = this.Account.Server.host
93 // It means it's our video
94 reporterServerHost = CONFIG.WEBSERVER.HOST
100 reporterUsername: this.Account.name,
102 videoId: this.Video.id,
103 videoUUID: this.Video.uuid,
104 videoName: this.Video.name,
105 createdAt: this.createdAt
109 toActivityPubObject (): VideoAbuseObject {
111 type: 'Flag' as 'Flag',
112 content: this.reason,
113 object: this.Video.url