aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-abuse.ts54
-rw-r--r--server/models/video/video-import.ts1
2 files changed, 53 insertions, 2 deletions
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index 39f0c2cb2..10a191372 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -1,11 +1,30 @@
1import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import {
2 AfterCreate,
3 AllowNull,
4 BelongsTo,
5 Column,
6 CreatedAt,
7 DataType,
8 Default,
9 ForeignKey,
10 Is,
11 Model,
12 Table,
13 UpdatedAt
14} from 'sequelize-typescript'
2import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' 15import { VideoAbuseObject } from '../../../shared/models/activitypub/objects'
3import { VideoAbuse } from '../../../shared/models/videos' 16import { VideoAbuse } from '../../../shared/models/videos'
4import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos' 17import {
18 isVideoAbuseModerationCommentValid,
19 isVideoAbuseReasonValid,
20 isVideoAbuseStateValid
21} from '../../helpers/custom-validators/video-abuses'
5import { Emailer } from '../../lib/emailer' 22import { Emailer } from '../../lib/emailer'
6import { AccountModel } from '../account/account' 23import { AccountModel } from '../account/account'
7import { getSort, throwIfNotValid } from '../utils' 24import { getSort, throwIfNotValid } from '../utils'
8import { VideoModel } from './video' 25import { VideoModel } from './video'
26import { VideoAbuseState } from '../../../shared'
27import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers'
9 28
10@Table({ 29@Table({
11 tableName: 'videoAbuse', 30 tableName: 'videoAbuse',
@@ -25,6 +44,18 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
25 @Column 44 @Column
26 reason: string 45 reason: string
27 46
47 @AllowNull(false)
48 @Default(null)
49 @Is('VideoAbuseState', value => throwIfNotValid(value, isVideoAbuseStateValid, 'state'))
50 @Column
51 state: VideoAbuseState
52
53 @AllowNull(true)
54 @Default(null)
55 @Is('VideoAbuseModerationComment', value => throwIfNotValid(value, isVideoAbuseModerationCommentValid, 'moderationComment'))
56 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_ABUSES.MODERATION_COMMENT.max))
57 moderationComment: string
58
28 @CreatedAt 59 @CreatedAt
29 createdAt: Date 60 createdAt: Date
30 61
@@ -60,6 +91,16 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
60 return Emailer.Instance.addVideoAbuseReportJob(instance.videoId) 91 return Emailer.Instance.addVideoAbuseReportJob(instance.videoId)
61 } 92 }
62 93
94 static loadByIdAndVideoId (id: number, videoId: number) {
95 const query = {
96 where: {
97 id,
98 videoId
99 }
100 }
101 return VideoAbuseModel.findOne(query)
102 }
103
63 static listForApi (start: number, count: number, sort: string) { 104 static listForApi (start: number, count: number, sort: string) {
64 const query = { 105 const query = {
65 offset: start, 106 offset: start,
@@ -88,6 +129,11 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
88 id: this.id, 129 id: this.id,
89 reason: this.reason, 130 reason: this.reason,
90 reporterAccount: this.Account.toFormattedJSON(), 131 reporterAccount: this.Account.toFormattedJSON(),
132 state: {
133 id: this.state,
134 label: VideoAbuseModel.getStateLabel(this.state)
135 },
136 moderationComment: this.moderationComment,
91 video: { 137 video: {
92 id: this.Video.id, 138 id: this.Video.id,
93 uuid: this.Video.uuid, 139 uuid: this.Video.uuid,
@@ -105,4 +151,8 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
105 object: this.Video.url 151 object: this.Video.url
106 } 152 }
107 } 153 }
154
155 private static getStateLabel (id: number) {
156 return VIDEO_ABUSE_STATES[id] || 'Unknown'
157 }
108} 158}
diff --git a/server/models/video/video-import.ts b/server/models/video/video-import.ts
index b794d8324..9d1f783c7 100644
--- a/server/models/video/video-import.ts
+++ b/server/models/video/video-import.ts
@@ -171,6 +171,7 @@ export class VideoImportModel extends Model<VideoImportModel> {
171 video 171 video
172 } 172 }
173 } 173 }
174
174 private static getStateLabel (id: number) { 175 private static getStateLabel (id: number) {
175 return VIDEO_IMPORT_STATES[id] || 'Unknown' 176 return VIDEO_IMPORT_STATES[id] || 'Unknown'
176 } 177 }