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 { getSort, throwIfNotValid } from '../utils'
7 import { VideoModel } from './video'
10 tableName: 'videoAbuse',
16 fields: [ 'reporterAccountId' ]
20 export class VideoAbuseModel extends Model<VideoAbuseModel> {
23 @Is('VideoAbuseReason', value => throwIfNotValid(value, isVideoAbuseReasonValid, 'reason'))
33 @ForeignKey(() => AccountModel)
35 reporterAccountId: number
37 @BelongsTo(() => AccountModel, {
45 @ForeignKey(() => VideoModel)
49 @BelongsTo(() => VideoModel, {
57 static listForApi (start: number, count: number, sort: string) {
61 order: [ getSort(sort) ],
74 return VideoAbuseModel.findAndCountAll(query)
75 .then(({ rows, count }) => {
76 return { total: count, data: rows }
81 let reporterServerHost
83 if (this.Account.Actor.Server) {
84 reporterServerHost = this.Account.Actor.Server.host
86 // It means it's our video
87 reporterServerHost = CONFIG.WEBSERVER.HOST
93 reporterUsername: this.Account.name,
95 videoId: this.Video.id,
96 videoUUID: this.Video.uuid,
97 videoName: this.Video.name,
98 createdAt: this.createdAt
102 toActivityPubObject (): VideoAbuseObject {
104 type: 'Flag' as 'Flag',
105 content: this.reason,
106 object: this.Video.url