diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-01-23 18:31:58 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-01-23 18:31:58 +0100 |
commit | 45239549bf2659998dcf9196d86974b0b625912e (patch) | |
tree | 823d324db097400a7b5ae59a03deff54c5fd86ef /src/videos.js | |
parent | 2cc8ebf134b66047cd639ee7324e1ecfd5c5fd18 (diff) | |
download | PeerTube-45239549bf2659998dcf9196d86974b0b625912e.tar.gz PeerTube-45239549bf2659998dcf9196d86974b0b625912e.tar.zst PeerTube-45239549bf2659998dcf9196d86974b0b625912e.zip |
Finalise the join in a network and add the ability to quit it
Diffstat (limited to 'src/videos.js')
-rw-r--r-- | src/videos.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/videos.js b/src/videos.js index 32f26abe7..90821fdf6 100644 --- a/src/videos.js +++ b/src/videos.js | |||
@@ -43,6 +43,18 @@ | |||
43 | }) | 43 | }) |
44 | } | 44 | } |
45 | 45 | ||
46 | videos.listOwned = function (callback) { | ||
47 | // If namePath is not null this is *our* video | ||
48 | VideosDB.find({ namePath: { $ne: null } }, function (err, videos_list) { | ||
49 | if (err) { | ||
50 | logger.error('Cannot get list of the videos.', { error: err }) | ||
51 | return callback(err) | ||
52 | } | ||
53 | |||
54 | return callback(null, videos_list) | ||
55 | }) | ||
56 | } | ||
57 | |||
46 | videos.add = function (data, callback) { | 58 | videos.add = function (data, callback) { |
47 | var video_file = data.video | 59 | var video_file = data.video |
48 | var video_data = data.data | 60 | var video_data = data.data |
@@ -131,6 +143,8 @@ | |||
131 | 143 | ||
132 | // Use the magnet Uri because the _id field is not the same on different servers | 144 | // Use the magnet Uri because the _id field is not the same on different servers |
133 | videos.removeRemotes = function (fromUrl, magnetUris, callback) { | 145 | videos.removeRemotes = function (fromUrl, magnetUris, callback) { |
146 | if (callback === undefined) callback = function () {} | ||
147 | |||
134 | VideosDB.find({ magnetUri: { $in: magnetUris } }, function (err, videos) { | 148 | VideosDB.find({ magnetUri: { $in: magnetUris } }, function (err, videos) { |
135 | if (err || !videos) { | 149 | if (err || !videos) { |
136 | logger.error('Cannot find the torrent URI of these remote videos.') | 150 | logger.error('Cannot find the torrent URI of these remote videos.') |
@@ -155,14 +169,34 @@ | |||
155 | return callback(err) | 169 | return callback(err) |
156 | } | 170 | } |
157 | 171 | ||
172 | logger.info('Removed remote videos from %s.', fromUrl) | ||
158 | callback(null) | 173 | callback(null) |
159 | }) | 174 | }) |
160 | }) | 175 | }) |
161 | }) | 176 | }) |
162 | } | 177 | } |
163 | 178 | ||
179 | videos.removeAllRemotes = function (callback) { | ||
180 | VideosDB.remove({ namePath: null }, function (err) { | ||
181 | if (err) return callback(err) | ||
182 | |||
183 | callback(null) | ||
184 | }) | ||
185 | } | ||
186 | |||
187 | videos.removeAllRemotesOf = function (fromUrl, callback) { | ||
188 | VideosDB.remove({ podUrl: fromUrl }, function (err) { | ||
189 | if (err) return callback(err) | ||
190 | |||
191 | callback(null) | ||
192 | }) | ||
193 | } | ||
194 | |||
164 | // { name, magnetUri, podUrl } | 195 | // { name, magnetUri, podUrl } |
196 | // TODO: avoid doublons | ||
165 | videos.addRemotes = function (videos, callback) { | 197 | videos.addRemotes = function (videos, callback) { |
198 | if (callback === undefined) callback = function () {} | ||
199 | |||
166 | var to_add = [] | 200 | var to_add = [] |
167 | 201 | ||
168 | async.each(videos, function (video, callback_each) { | 202 | async.each(videos, function (video, callback_each) { |