X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo.js;h=1c06e477cc195c7a842799ff8c70af1d39c72a7a;hb=5f698b82c7055df763f3830882ac5bad1397db23;hp=8b14e9b35a1a02e695ea9d2b04e513552fd651e6;hpb=aaf61f3810e6d57c5130af959bd2860df32775e7;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video.js b/server/models/video.js index 8b14e9b35..1c06e477c 100644 --- a/server/models/video.js +++ b/server/models/video.js @@ -8,7 +8,7 @@ const pathUtils = require('path') const mongoose = require('mongoose') const constants = require('../initializers/constants') -const customValidators = require('../helpers/customValidators') +const customValidators = require('../helpers/custom-validators') const logger = require('../helpers/logger') const utils = require('../helpers/utils') const webtorrent = require('../lib/webtorrent') @@ -24,7 +24,7 @@ const thumbnailsDir = pathUtils.join(__dirname, '..', '..', config.get('storage. // TODO: add indexes on searchable columns const VideoSchema = mongoose.Schema({ name: String, - namePath: String, + filename: String, description: String, magnetUri: String, podUrl: String, @@ -98,7 +98,7 @@ VideoSchema.pre('save', function (next) { const tasks = [] if (video.isOwned()) { - const videoPath = pathUtils.join(uploadsDir, video.namePath) + const videoPath = pathUtils.join(uploadsDir, video.filename) this.podUrl = http + '://' + host + ':' + port tasks.push( @@ -134,7 +134,7 @@ mongoose.model('Video', VideoSchema) // ------------------------------ METHODS ------------------------------ function isOwned () { - return this.namePath !== null + return this.filename !== null } function toFormatedJSON () { @@ -169,7 +169,7 @@ function toRemoteJSON (callback) { name: self.name, description: self.description, magnetUri: self.magnetUri, - namePath: null, + filename: null, author: self.author, duration: self.duration, thumbnailBase64: new Buffer(thumbnailData).toString('base64'), @@ -206,12 +206,12 @@ function listByUrls (fromUrls, callback) { } function listOwned (callback) { - // If namePath is not null this is *our* video - this.find({ namePath: { $ne: null } }, callback) + // If filename is not null this is *our* video + this.find({ filename: { $ne: null } }, callback) } function listRemotes (callback) { - this.find({ namePath: null }, callback) + this.find({ filename: null }, callback) } function load (id, callback) { @@ -230,9 +230,15 @@ function search (value, field, start, count, sort, callback) { findWithCount.call(this, query, start, count, sort, callback) } -// TODO -function seedAllExisting () { +function seedAllExisting (callback) { + listOwned.call(this, function (err, videos) { + if (err) return callback(err) + async.each(videos, function (video, callbackEach) { + const videoPath = pathUtils.join(uploadsDir, video.filename) + seed(videoPath, callbackEach) + }, callback) + }) } // --------------------------------------------------------------------------- @@ -261,7 +267,7 @@ function removeThumbnail (video, callback) { } function removeFile (video, callback) { - fs.unlink(uploadsDir + video.namePath, callback) + fs.unlink(uploadsDir + video.filename, callback) } // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process