fix(torrents): move image files when create new torrent

This commit is contained in:
OldHawk
2017-10-11 17:17:58 +08:00
parent a1a29eb750
commit 752ea28bde
2 changed files with 30 additions and 9 deletions

View File

@@ -199,6 +199,10 @@
vm.tvinfo = undefined;
vm.tmdb_id = undefined;
vm.tags = [];
vm.videoNfo = '';
vm.customTorrent = {};
vm.showVideoNfo = false;
vm.showAgreeAndSubmit = false;
};
@@ -441,9 +445,7 @@
var uimg = [];
angular.forEach($scope.uImages, function (f) {
mtDebug.info(f);
uimg.push({
filename: f.name
});
uimg.push(f.name);
});
var torrent = new TorrentsService({

View File

@@ -526,18 +526,24 @@ exports.create = function (req, res) {
} else {
//move temp cover image file to dest directory
var cv = req.body.resource_detail_info.cover;
var o = config.uploads.torrent.cover.temp + cv;
var n = config.uploads.torrent.cover.dest + cv;
move(o, n, function (err) {
var oc = config.uploads.torrent.cover.temp + cv;
var nc = config.uploads.torrent.cover.dest + cv;
copy(oc, nc, function (err) {
if (err) {
mtDebug.debugRed(err);
}
if (req.body._uImage.indexOf(cv) < 0) {
fs.unlink(oc);
}
});
//move temp torrent image file to dest directory
req.body._uImage.forEach(function (f) {
o = config.uploads.torrent.image.temp + f.filename;
n = config.uploads.torrent.image.dest + f.filename;
move(o, n, function (err) {
var oi = config.uploads.torrent.image.temp + f;
var ni = config.uploads.torrent.image.dest + f;
move(oi, ni, function (err) {
if (err) {
mtDebug.debugRed(err);
}
@@ -568,6 +574,19 @@ exports.create = function (req, res) {
}
});
function copy(oldPath, newPath, callback) {
var readStream = fs.createReadStream(oldPath);
var writeStream = fs.createWriteStream(newPath);
readStream.on('error', callback);
writeStream.on('error', callback);
readStream.on('close', function () {
callback();
});
readStream.pipe(writeStream);
}
function move(oldPath, newPath, callback) {
fs.rename(oldPath, newPath, function (err) {
if (err) {