mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-06-18 20:40:57 +02:00
change torrent file upload mode, first save temp folder, when create data ok, then move the file to dest folder,and delete the temp file
This commit is contained in:
1
config/env/default.js
vendored
1
config/env/default.js
vendored
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -39,9 +39,10 @@
|
||||
<dt class="h-line">{{ 'TMDB_FIELDS.RELEASE_DATE' | translate}}:</dt>
|
||||
<dd class="h-line">{{vm.movieTopOne.torrent_release}}</dd>
|
||||
|
||||
<dt class="h-line">{{ 'TMDB_FIELDS.RUNTIME' | translate}}:</dt>
|
||||
<dd class="h-line">{{vm.movieTopOne.torrent_runtime | runtime}}</dd>
|
||||
|
||||
<div ng-hide="vm.movieTopOne.torrent_runtime == 0">
|
||||
<dt class="h-line">{{ 'TMDB_FIELDS.RUNTIME' | translate}}:</dt>
|
||||
<dd class="h-line">{{vm.movieTopOne.torrent_runtime | runtime}}</dd>
|
||||
</div>
|
||||
<div ng-hide="vm.movieTopOne.torrent_budget == 0">
|
||||
<dt class="h-line">{{ 'TMDB_FIELDS.BUDGET' | translate}}:</dt>
|
||||
<dd class="h-line">{{vm.movieTopOne.torrent_budget | dollar:2}}</dd>
|
||||
@@ -58,7 +59,8 @@
|
||||
</dd>
|
||||
|
||||
<dt class="h-line">{{ 'TMDB_FIELDS.OVERVIEW' | translate}}:</dt>
|
||||
<dd class="h-line">{{vm.movieTopOne.torrent_overview}}</dd>
|
||||
<dd class="h-line">{{vm.movieTopOne.torrent_overview | limitTo:300}}<span
|
||||
ng-show="vm.movieTopOne.torrent_overview.length > 300">......</span></dd>
|
||||
</dl>
|
||||
<legend class="xsmall-legend strong-legend" translate="TMDB_FIELDS.CAST"></legend>
|
||||
<div class="row cast-list">
|
||||
|
||||
@@ -46,9 +46,10 @@
|
||||
<dt class="h-line">{{ 'TMDB_FIELDS.RELEASE_DATE' | translate}}:</dt>
|
||||
<dd class="h-line">{{vm.torrentLocalInfo.torrent_release}}</dd>
|
||||
|
||||
<dt class="h-line">{{ 'TMDB_FIELDS.RUNTIME' | translate}}:</dt>
|
||||
<dd class="h-line">{{vm.torrentLocalInfo.torrent_runtime | runtime}}</dd>
|
||||
|
||||
<div ng-hide="vm.torrentLocalInfo.torrent_runtime == 0">
|
||||
<dt class="h-line">{{ 'TMDB_FIELDS.RUNTIME' | translate}}:</dt>
|
||||
<dd class="h-line">{{vm.torrentLocalInfo.torrent_runtime | runtime}}</dd>
|
||||
</div>
|
||||
<div ng-hide="vm.torrentLocalInfo.torrent_budget == 0">
|
||||
<dt class="h-line">{{ 'TMDB_FIELDS.BUDGET' | translate}}:</dt>
|
||||
<dd class="h-line">{{vm.torrentLocalInfo.torrent_budget | dollar:2}}</dd>
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user