diff options
Diffstat (limited to 'server/models/video/video-blacklist.ts')
-rw-r--r-- | server/models/video/video-blacklist.ts | 59 |
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 @@ | |||
1 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { |
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' | ||
2 | import { SortType } from '../../helpers/utils' | 14 | import { SortType } from '../../helpers/utils' |
3 | import { getSortOnModel } from '../utils' | 15 | import { getSortOnModel, throwIfNotValid } from '../utils' |
4 | import { VideoModel } from './video' | 16 | import { VideoModel } from './video' |
17 | import { isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist' | ||
18 | import { Emailer } from '../../lib/emailer' | ||
19 | import { BlacklistedVideo } from '../../../shared/models/videos' | ||
20 | import { 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 | }) |
15 | export class VideoBlacklistModel extends Model<VideoBlacklistModel> { | 31 | export 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 | } |