diff --git a/config/env/default.js b/config/env/default.js index 218d6b9c..3cd89628 100644 --- a/config/env/default.js +++ b/config/env/default.js @@ -57,6 +57,7 @@ module.exports = { torrent: { file: { dest: './modules/torrents/client/uploads/', + temp: './modules/torrents/client/uploads/temp/', limits: { fileSize: 1 * 1024 * 1024 // Max file size in bytes (1 MB) } diff --git a/config/lib/multer.js b/config/lib/multer.js index b00bc172..81f32fc5 100644 --- a/config/lib/multer.js +++ b/config/lib/multer.js @@ -37,6 +37,10 @@ module.exports.createUploadFilename = function (req, file, cb) { var regex = new RegExp(',', 'g'); var filename = file.originalname.replace(regex, ' '); + if (fs.existsSync(config.uploads.torrent.file.temp + filename)) { + fs.unlinkSync(config.uploads.torrent.file.temp + filename); + } + if (fs.existsSync(config.uploads.torrent.file.dest + filename)) { var err = new Error(); err.code = 'FILE_ALREADY_EXISTS'; @@ -47,7 +51,7 @@ module.exports.createUploadFilename = function (req, file, cb) { }; module.exports.getUploadDestination = function (req, file, cb) { - cb(null, config.uploads.torrent.file.dest); + cb(null, config.uploads.torrent.file.temp); }; module.exports.createUploadSubtitleFilename = function (req, file, cb) { diff --git a/gulpfile.js b/gulpfile.js index 530f99a1..b98ccaf5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -260,6 +260,11 @@ gulp.task('makeUploadsDir', function () { console.error(err); } }); + fs.mkdir('modules/torrents/client/uploads/temp', function (err) { + if (err && err.code !== 'EEXIST') { + console.error(err); + } + }); fs.mkdir('modules/torrents/client/uploads/subtitles', function (err) { if (err && err.code !== 'EEXIST') { console.error(err); diff --git a/modules/core/client/less/mt.less b/modules/core/client/less/mt.less index a8f17c0d..a3c638b3 100644 --- a/modules/core/client/less/mt.less +++ b/modules/core/client/less/mt.less @@ -31,7 +31,7 @@ body { background-color: rgba(0, 0, 0, .7); //opacity: 0.5; padding-top: 30px; - padding-bottom: 30px; + padding-bottom: 20px; } .loading { color: #ccc; @@ -44,6 +44,7 @@ body { } legend { color: lighten(@gray-light, 8%); + margin-bottom: 10px; } img { opacity: 0; @@ -61,7 +62,7 @@ body { } } .genres-item { - color: #fff; + color: #ccc; } .img-circle { &:hover { @@ -87,6 +88,9 @@ body { .img-thumbnail { padding: 1px !important; } + p { + margin: 0; + } } .torrent-post-info { diff --git a/modules/core/client/views/home.client.view.html b/modules/core/client/views/home.client.view.html index 1eb8ff32..2dada828 100644 --- a/modules/core/client/views/home.client.view.html +++ b/modules/core/client/views/home.client.view.html @@ -39,9 +39,10 @@
{{ 'TMDB_FIELDS.RELEASE_DATE' | translate}}:
{{vm.movieTopOne.torrent_release}}
-
{{ 'TMDB_FIELDS.RUNTIME' | translate}}:
-
{{vm.movieTopOne.torrent_runtime | runtime}}
- +
+
{{ 'TMDB_FIELDS.RUNTIME' | translate}}:
+
{{vm.movieTopOne.torrent_runtime | runtime}}
+
{{ 'TMDB_FIELDS.BUDGET' | translate}}:
{{vm.movieTopOne.torrent_budget | dollar:2}}
@@ -58,7 +59,8 @@
{{ 'TMDB_FIELDS.OVERVIEW' | translate}}:
-
{{vm.movieTopOne.torrent_overview}}
+
{{vm.movieTopOne.torrent_overview | limitTo:300}}......
diff --git a/modules/torrents/client/views/view-torrent.client.view.html b/modules/torrents/client/views/view-torrent.client.view.html index 7e43eda5..51ad295c 100644 --- a/modules/torrents/client/views/view-torrent.client.view.html +++ b/modules/torrents/client/views/view-torrent.client.view.html @@ -46,9 +46,10 @@
{{ 'TMDB_FIELDS.RELEASE_DATE' | translate}}:
{{vm.torrentLocalInfo.torrent_release}}
-
{{ 'TMDB_FIELDS.RUNTIME' | translate}}:
-
{{vm.torrentLocalInfo.torrent_runtime | runtime}}
- +
+
{{ 'TMDB_FIELDS.RUNTIME' | translate}}:
+
{{vm.torrentLocalInfo.torrent_runtime | runtime}}
+
{{ 'TMDB_FIELDS.BUDGET' | translate}}:
{{vm.torrentLocalInfo.torrent_budget | dollar:2}}
diff --git a/modules/torrents/server/controllers/torrents.server.controller.js b/modules/torrents/server/controllers/torrents.server.controller.js index eab5ddcd..97f94611 100644 --- a/modules/torrents/server/controllers/torrents.server.controller.js +++ b/modules/torrents/server/controllers/torrents.server.controller.js @@ -71,6 +71,15 @@ exports.upload = function (req, res) { }) .catch(function (err) { res.status(422).send(err); + + if (req.file && req.file.filename) { + var newfile = config.uploads.torrent.file.temp + req.file.filename; + if (fs.existsSync(newfile)) { + console.log(err); + console.log('ERROR: DELETE TEMP TORRENT FILE: ' + newfile); + fs.unlinkSync(newfile); + } + } }); } else { res.status(401).send({ @@ -88,7 +97,6 @@ exports.upload = function (req, res) { message = 'Torrent file too large. Maximum size allowed is ' + (config.uploads.torrent.file.limits.fileSize / (1024 * 1024)).toFixed(2) + ' Mb files.'; } - //reject(errorHandler.getErrorMessage(uploadError)); reject(message); } else { resolve(); @@ -100,7 +108,7 @@ exports.upload = function (req, res) { function checkAnnounce() { return new Promise(function (resolve, reject) { console.log(req.file.filename); - var newfile = config.uploads.torrent.file.dest + req.file.filename; + var newfile = config.uploads.torrent.file.temp + req.file.filename; nt.read(newfile, function (err, torrent) { var message = ''; @@ -113,13 +121,6 @@ exports.upload = function (req, res) { console.log(torrent.metadata.announce); message = 'ANNOUNCE_URL_ERROR'; - fs.unlink(newfile, function (unlinkError) { - if (unlinkError) { - console.log(unlinkError); - message = 'Error occurred while deleting torrent file'; - reject(message); - } - }); reject(message); } } @@ -134,7 +135,6 @@ exports.upload = function (req, res) { function checkHash() { return new Promise(function (resolve, reject) { - var newfile = config.uploads.torrent.file.dest + req.file.filename; var message = ''; if (torrentinfo.info_hash === '' || !torrentinfo.info_hash) { @@ -150,14 +150,6 @@ exports.upload = function (req, res) { if (torrent) { message = 'INFO_HASH_ALREADY_EXISTS'; - fs.unlink(newfile, function (unlinkError) { - if (unlinkError) { - console.log(unlinkError); - message = 'Error occurred while deleting torrent file'; - reject(message); - } - }); - reject(message); } else { resolve(); @@ -249,15 +241,53 @@ exports.create = function (req, res) { //console.log(torrent); - torrent.save(function (err) { + //move temp torrent file to dest directory + var oldPath = config.uploads.torrent.file.temp + req.body.torrent_filename; + var newPath = config.uploads.torrent.file.dest + req.body.torrent_filename; + move(oldPath, newPath, function (err) { if (err) { return res.status(422).send({ - message: errorHandler.getErrorMessage(err) + message: 'MOVE_TORRENT_FILE_ERROR' }); } else { - res.json(torrent); + torrent.save(function (err) { + if (err) { + return res.status(422).send({ + message: errorHandler.getErrorMessage(err) + }); + } else { + res.json(torrent); + } + }); } }); + + function move(oldPath, newPath, callback) { + fs.rename(oldPath, newPath, function (err) { + if (err) { + if (err.code === 'EXDEV') { + copy(); + } else { + callback(err); + } + return; + } + callback(); + }); + + function copy() { + var readStream = fs.createReadStream(oldPath); + var writeStream = fs.createWriteStream(newPath); + + readStream.on('error', callback); + writeStream.on('error', callback); + + readStream.on('close', function () { + fs.unlink(oldPath, callback); + }); + readStream.pipe(writeStream); + } + } }; /** @@ -404,6 +434,10 @@ exports.setReviewedStatus = function (req, res) { exports.delete = function (req, res) { var torrent = req.torrent; + //DELETE the torrent file + var tfile = config.uploads.torrent.file.dest + req.torrent.torrent_filename; + fs.unlinkSync(tfile); + torrent.remove(function (err) { if (err) { return res.status(422).send({