aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-blacklist.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-13 16:57:13 +0200
committerChocobozzz <me@florianbigard.com>2018-08-14 09:27:18 +0200
commit26b7305a232e547709f433a6edf700bf495935d8 (patch)
treeb5676090c61df72f864735bcc881d5ee256cffbd /server/models/video/video-blacklist.ts
parentefc9e8450a8bbeeef9cd18e3ad6037abc0f815c3 (diff)
downloadPeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.gz
PeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.zst
PeerTube-26b7305a232e547709f433a6edf700bf495935d8.zip
Add blacklist reason field
Diffstat (limited to 'server/models/video/video-blacklist.ts')
-rw-r--r--server/models/video/video-blacklist.ts59
1 files changed, 47 insertions, 12 deletions
diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts
index 26167174a..1b8a338cb 100644
--- a/server/models/video/video-blacklist.ts
+++ b/server/models/video/video-blacklist.ts
@@ -1,7 +1,23 @@
1import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import {
2 AfterCreate,
3 AfterDestroy,
4 AllowNull,
5 BelongsTo,
6 Column,
7 CreatedAt, DataType,
8 ForeignKey,
9 Is,
10 Model,
11 Table,
12 UpdatedAt
13} from 'sequelize-typescript'
2import { SortType } from '../../helpers/utils' 14import { SortType } from '../../helpers/utils'
3import { getSortOnModel } from '../utils' 15import { getSortOnModel, throwIfNotValid } from '../utils'
4import { VideoModel } from './video' 16import { VideoModel } from './video'
17import { isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist'
18import { Emailer } from '../../lib/emailer'
19import { BlacklistedVideo } from '../../../shared/models/videos'
20import { CONSTRAINTS_FIELDS } from '../../initializers'
5 21
6@Table({ 22@Table({
7 tableName: 'videoBlacklist', 23 tableName: 'videoBlacklist',
@@ -14,6 +30,11 @@ import { VideoModel } from './video'
14}) 30})
15export class VideoBlacklistModel extends Model<VideoBlacklistModel> { 31export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
16 32
33 @AllowNull(true)
34 @Is('VideoBlacklistReason', value => throwIfNotValid(value, isVideoBlacklistReasonValid, 'reason'))
35 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_BLACKLIST.REASON.max))
36 reason: string
37
17 @CreatedAt 38 @CreatedAt
18 createdAt: Date 39 createdAt: Date
19 40
@@ -32,6 +53,16 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
32 }) 53 })
33 Video: VideoModel 54 Video: VideoModel
34 55
56 @AfterCreate
57 static sendBlacklistEmailNotification (instance: VideoBlacklistModel) {
58 return Emailer.Instance.addVideoBlacklistReportJob(instance.videoId, instance.reason)
59 }
60
61 @AfterDestroy
62 static sendUnblacklistEmailNotification (instance: VideoBlacklistModel) {
63 return Emailer.Instance.addVideoUnblacklistReportJob(instance.videoId)
64 }
65
35 static listForApi (start: number, count: number, sort: SortType) { 66 static listForApi (start: number, count: number, sort: SortType) {
36 const query = { 67 const query = {
37 offset: start, 68 offset: start,
@@ -59,22 +90,26 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
59 return VideoBlacklistModel.findOne(query) 90 return VideoBlacklistModel.findOne(query)
60 } 91 }
61 92
62 toFormattedJSON () { 93 toFormattedJSON (): BlacklistedVideo {
63 const video = this.Video 94 const video = this.Video
64 95
65 return { 96 return {
66 id: this.id, 97 id: this.id,
67 videoId: this.videoId,
68 createdAt: this.createdAt, 98 createdAt: this.createdAt,
69 updatedAt: this.updatedAt, 99 updatedAt: this.updatedAt,
70 name: video.name, 100 reason: this.reason,
71 uuid: video.uuid, 101
72 description: video.description, 102 video: {
73 duration: video.duration, 103 id: video.id,
74 views: video.views, 104 name: video.name,
75 likes: video.likes, 105 uuid: video.uuid,
76 dislikes: video.dislikes, 106 description: video.description,
77 nsfw: video.nsfw 107 duration: video.duration,
108 views: video.views,
109 likes: video.likes,
110 dislikes: video.dislikes,
111 nsfw: video.nsfw
112 }
78 } 113 }
79 } 114 }
80} 115}