aboutsummaryrefslogtreecommitdiffhomepage
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/pods.js2
-rw-r--r--models/poolRequests.js19
-rw-r--r--models/videos.js20
3 files changed, 24 insertions, 17 deletions
diff --git a/models/pods.js b/models/pods.js
index 395b1e0b1..04fd042c3 100644
--- a/models/pods.js
+++ b/models/pods.js
@@ -61,7 +61,7 @@
61 function list (callback) { 61 function list (callback) {
62 PodsDB.find(function (err, pods_list) { 62 PodsDB.find(function (err, pods_list) {
63 if (err) { 63 if (err) {
64 logger.error('Cannot get the list of the pods.', { error: err }) 64 logger.error('Cannot get the list of the pods.')
65 return callback(err) 65 return callback(err)
66 } 66 }
67 67
diff --git a/models/poolRequests.js b/models/poolRequests.js
index 0f488ef04..962e75e6a 100644
--- a/models/poolRequests.js
+++ b/models/poolRequests.js
@@ -26,21 +26,28 @@
26 logger.debug('Add request to the pool requests.', { id: id, type: type, request: request }) 26 logger.debug('Add request to the pool requests.', { id: id, type: type, request: request })
27 27
28 PoolRequestsDB.findOne({ id: id }, function (err, entity) { 28 PoolRequestsDB.findOne({ id: id }, function (err, entity) {
29 if (err) logger.error(err) 29 if (err) {
30 logger.error('Cannot find one pool request.', { error: err })
31 return // Abort
32 }
30 33
31 if (entity) { 34 if (entity) {
32 if (entity.type === type) { 35 if (entity.type === type) {
33 logger.error(new Error('Cannot insert two same requests.')) 36 logger.error('Cannot insert two same requests.')
34 return 37 return // Abort
35 } 38 }
36 39
37 // Remove the request of the other type 40 // Remove the request of the other type
38 PoolRequestsDB.remove({ id: id }, function (err) { 41 PoolRequestsDB.remove({ id: id }, function (err) {
39 if (err) logger.error(err) 42 if (err) {
43 logger.error('Cannot remove a pool request.', { error: err })
44 return // Abort
45 }
40 }) 46 })
41 } else { 47 } else {
42 PoolRequestsDB.create({ id: id, type: type, request: request }, function (err) { 48 PoolRequestsDB.create({ id: id, type: type, request: request }, function (err) {
43 if (err) logger.error(err) 49 logger.error('Cannot create a pool request.', { error: err })
50 return // Abort
44 }) 51 })
45 } 52 }
46 }) 53 })
@@ -54,7 +61,7 @@
54 PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) { 61 PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) {
55 if (err) { 62 if (err) {
56 logger.error('Cannot remove requests from the pool requests database.', { error: err }) 63 logger.error('Cannot remove requests from the pool requests database.', { error: err })
57 return 64 return // Abort
58 } 65 }
59 66
60 logger.info('Pool requests flushed.') 67 logger.info('Pool requests flushed.')
diff --git a/models/videos.js b/models/videos.js
index 10abee6e7..6ea628373 100644
--- a/models/videos.js
+++ b/models/videos.js
@@ -50,7 +50,7 @@
50 50
51 VideosDB.create(params, function (err, video) { 51 VideosDB.create(params, function (err, video) {
52 if (err) { 52 if (err) {
53 logger.error('Cannot insert this video into database.', { error: err }) 53 logger.error('Cannot insert this video into database.')
54 return callback(err) 54 return callback(err)
55 } 55 }
56 56
@@ -82,7 +82,7 @@
82 }, function () { 82 }, function () {
83 VideosDB.create(to_add, function (err, videos) { 83 VideosDB.create(to_add, function (err, videos) {
84 if (err) { 84 if (err) {
85 logger.error('Cannot insert this remote video.', { error: err }) 85 logger.error('Cannot insert this remote video.')
86 return callback(err) 86 return callback(err)
87 } 87 }
88 88
@@ -94,7 +94,7 @@
94 function get (id, callback) { 94 function get (id, callback) {
95 VideosDB.findById(id, function (err, video) { 95 VideosDB.findById(id, function (err, video) {
96 if (err) { 96 if (err) {
97 logger.error('Cannot get this video.', { error: err }) 97 logger.error('Cannot get this video.')
98 return callback(err) 98 return callback(err)
99 } 99 }
100 100
@@ -120,14 +120,14 @@
120 VideosDB.findById(id, function (err, video) { 120 VideosDB.findById(id, function (err, video) {
121 if (err || !video) { 121 if (err || !video) {
122 if (!err) err = new Error('Cannot find this video.') 122 if (!err) err = new Error('Cannot find this video.')
123 logger.error('Cannot find this video.', { error: err }) 123 logger.error('Cannot find this video.')
124 return callback(err) 124 return callback(err)
125 } 125 }
126 126
127 if (video.namePath === null) { 127 if (video.namePath === null) {
128 var error_string = 'Cannot remove the video of another pod.' 128 var error_string = 'Cannot remove the video of another pod.'
129 logger.error(error_string) 129 logger.error(error_string)
130 return callback(null, false, video) 130 return callback(new Error(error_string), false, video)
131 } 131 }
132 132
133 callback(null, true, video) 133 callback(null, true, video)
@@ -137,7 +137,7 @@
137 function list (callback) { 137 function list (callback) {
138 VideosDB.find(function (err, videos_list) { 138 VideosDB.find(function (err, videos_list) {
139 if (err) { 139 if (err) {
140 logger.error('Cannot get list of the videos.', { error: err }) 140 logger.error('Cannot get the list of the videos.')
141 return callback(err) 141 return callback(err)
142 } 142 }
143 143
@@ -149,7 +149,7 @@
149 // If namePath is not null this is *our* video 149 // If namePath is not null this is *our* video
150 VideosDB.find({ namePath: { $ne: null } }, function (err, videos_list) { 150 VideosDB.find({ namePath: { $ne: null } }, function (err, videos_list) {
151 if (err) { 151 if (err) {
152 logger.error('Cannot get list of the videos.', { error: err }) 152 logger.error('Cannot get the list of owned videos.')
153 return callback(err) 153 return callback(err)
154 } 154 }
155 155
@@ -160,13 +160,13 @@
160 function removeOwned (id, callback) { 160 function removeOwned (id, callback) {
161 VideosDB.findByIdAndRemove(id, function (err, video) { 161 VideosDB.findByIdAndRemove(id, function (err, video) {
162 if (err) { 162 if (err) {
163 logger.error('Cannot remove the torrent.', { error: err }) 163 logger.error('Cannot remove the torrent.')
164 return callback(err) 164 return callback(err)
165 } 165 }
166 166
167 fs.unlink(uploadDir + video.namePath, function (err) { 167 fs.unlink(uploadDir + video.namePath, function (err) {
168 if (err) { 168 if (err) {
169 logger.error('Cannot remove this video file.', { error: err }) 169 logger.error('Cannot remove this video file.')
170 return callback(err) 170 return callback(err)
171 } 171 }
172 172
@@ -222,7 +222,7 @@
222 function search (name, callback) { 222 function search (name, callback) {
223 VideosDB.find({ name: new RegExp(name) }, function (err, videos) { 223 VideosDB.find({ name: new RegExp(name) }, function (err, videos) {
224 if (err) { 224 if (err) {
225 logger.error('Cannot search the videos.', { error: err }) 225 logger.error('Cannot search the videos.')
226 return callback(err) 226 return callback(err)
227 } 227 }
228 228