aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-04 20:59:23 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-04 21:05:13 +0100
commit55fa55a9be566cca2ba95322f2ae23b434aed62a (patch)
treef51ef35c120ce8a928917a659418079538cdb8dc /server/models
parenta6fd2b30bf717eec14972a2175354781f5f43e77 (diff)
downloadPeerTube-55fa55a9be566cca2ba95322f2ae23b434aed62a.tar.gz
PeerTube-55fa55a9be566cca2ba95322f2ae23b434aed62a.tar.zst
PeerTube-55fa55a9be566cca2ba95322f2ae23b434aed62a.zip
Server: add video abuse support
Diffstat (limited to 'server/models')
-rw-r--r--server/models/request-to-pod.js (renamed from server/models/requestToPod.js)0
-rw-r--r--server/models/video-abuse.js113
-rw-r--r--server/models/video-tag.js (renamed from server/models/videoTag.js)0
-rw-r--r--server/models/video.js8
4 files changed, 121 insertions, 0 deletions
diff --git a/server/models/requestToPod.js b/server/models/request-to-pod.js
index f42a53458..f42a53458 100644
--- a/server/models/requestToPod.js
+++ b/server/models/request-to-pod.js
diff --git a/server/models/video-abuse.js b/server/models/video-abuse.js
new file mode 100644
index 000000000..766a7568d
--- /dev/null
+++ b/server/models/video-abuse.js
@@ -0,0 +1,113 @@
1'use strict'
2
3const constants = require('../initializers/constants')
4const modelUtils = require('./utils')
5const customVideosValidators = require('../helpers/custom-validators').videos
6
7module.exports = function (sequelize, DataTypes) {
8 const VideoAbuse = sequelize.define('VideoAbuse',
9 {
10 reporterUsername: {
11 type: DataTypes.STRING,
12 allowNull: false,
13 validate: {
14 reporterUsernameValid: function (value) {
15 const res = customVideosValidators.isVideoAbuseReporterUsernameValid(value)
16 if (res === false) throw new Error('Video abuse reporter username is not valid.')
17 }
18 }
19 },
20 reason: {
21 type: DataTypes.STRING,
22 allowNull: false,
23 validate: {
24 reasonValid: function (value) {
25 const res = customVideosValidators.isVideoAbuseReasonValid(value)
26 if (res === false) throw new Error('Video abuse reason is not valid.')
27 }
28 }
29 }
30 },
31 {
32 indexes: [
33 {
34 fields: [ 'videoId' ]
35 },
36 {
37 fields: [ 'reporterPodId' ]
38 }
39 ],
40 classMethods: {
41 associate,
42
43 listForApi
44 },
45 instanceMethods: {
46 toFormatedJSON
47 }
48 }
49 )
50
51 return VideoAbuse
52}
53
54// ---------------------------------------------------------------------------
55
56function associate (models) {
57 this.belongsTo(models.Pod, {
58 foreignKey: {
59 name: 'reporterPodId',
60 allowNull: true
61 },
62 onDelete: 'cascade'
63 })
64
65 this.belongsTo(models.Video, {
66 foreignKey: {
67 name: 'videoId',
68 allowNull: false
69 },
70 onDelete: 'cascade'
71 })
72}
73
74function listForApi (start, count, sort, callback) {
75 const query = {
76 offset: start,
77 limit: count,
78 order: [ modelUtils.getSort(sort) ],
79 include: [
80 {
81 model: this.sequelize.models.Pod,
82 required: false
83 }
84 ]
85 }
86
87 return this.findAndCountAll(query).asCallback(function (err, result) {
88 if (err) return callback(err)
89
90 return callback(null, result.rows, result.count)
91 })
92}
93
94function toFormatedJSON () {
95 let reporterPodHost
96
97 if (this.Pod) {
98 reporterPodHost = this.Pod.host
99 } else {
100 // It means it's our video
101 reporterPodHost = constants.CONFIG.WEBSERVER.HOST
102 }
103
104 const json = {
105 id: this.id,
106 reporterPodHost,
107 reason: this.reason,
108 reporterUsername: this.reporterUsername,
109 videoId: this.videoId
110 }
111
112 return json
113}
diff --git a/server/models/videoTag.js b/server/models/video-tag.js
index cd9277a6e..cd9277a6e 100644
--- a/server/models/videoTag.js
+++ b/server/models/video-tag.js
diff --git a/server/models/video.js b/server/models/video.js
index 3fe8368c7..4c197a835 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -248,6 +248,14 @@ function associate (models) {
248 through: models.VideoTag, 248 through: models.VideoTag,
249 onDelete: 'cascade' 249 onDelete: 'cascade'
250 }) 250 })
251
252 this.hasMany(models.VideoAbuse, {
253 foreignKey: {
254 name: 'videoId',
255 allowNull: false
256 },
257 onDelete: 'cascade'
258 })
251} 259}
252 260
253function generateMagnetUri () { 261function generateMagnetUri () {