feat(torrents): torrents cover image support crop

This commit is contained in:
OldHawk
2018-01-21 22:01:51 +08:00
parent 66b2166562
commit 861efafd7f
5 changed files with 22 additions and 7 deletions

View File

@@ -73,6 +73,7 @@ module.exports = {
},
cover: {
dest: './modules/torrents/client/uploads/cover/',
crop: './modules/torrents/client/uploads/cover/crop/',
temp: './modules/torrents/client/uploads/temp/',
limits: {
fileSize: 2 * 1024 * 1024 // Max file size in bytes (2 MB)

View File

@@ -959,7 +959,7 @@
message: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TORRENT_DELETE_SUCCESSFULLY')
});
$state.go('torrents.movie');
$state.go($state.previous.state.name || 'torrents.movie');
}
function errorCallback(res) {

View File

@@ -478,7 +478,8 @@
vote_average: 0,
vote_total: 0,
vote_count: 0
vote_count: 0,
cover_crop: false
};
mtDebug.info($scope.uImages);

View File

@@ -110,7 +110,7 @@
result = tmdbConfig.posterListBaseUrl + item.resource_detail_info.poster_path;
break;
default:
result = '/modules/torrents/client/uploads/cover/' + item.resource_detail_info.cover;
result = '/modules/torrents/client/uploads/cover/' + (item.resource_detail_info.cover_crop ? 'crop/' : '') + item.resource_detail_info.cover;
break;
}
}
@@ -132,7 +132,7 @@
result = tmdbConfig.posterImgBaseUrl + item.resource_detail_info.poster_path;
break;
default:
result = '/modules/torrents/client/uploads/cover/' + item.resource_detail_info.cover;
result = '/modules/torrents/client/uploads/cover/' + (item.resource_detail_info.cover_crop ? 'crop/' : '') + item.resource_detail_info.cover;
break;
}
}
@@ -154,7 +154,7 @@
result = tmdbConfig.posterImgBaseUrl + item.resource_detail_info.poster_path;
break;
default:
result = '/modules/torrents/client/uploads/cover/' + item.resource_detail_info.cover;
result = '/modules/torrents/client/uploads/cover/' + (item.resource_detail_info.cover_crop ? 'crop/' : '') + item.resource_detail_info.cover;
break;
}
}

View File

@@ -603,9 +603,22 @@ exports.create = function (req, res) {
var cv = req.body.resource_detail_info.cover;
var oc = config.uploads.torrent.cover.temp + cv;
var nc = config.uploads.torrent.cover.dest + cv;
var cc = config.uploads.torrent.cover.crop + cv;
copy(oc, nc, function (err) {
if (err) {
mtDebug.debugRed(err);
} else {
sharp(nc)
.resize(400)
.toFile(cc, function (err) {
if (err) {
mtDebug.debugError(err);
} else {
torrent.resource_detail_info.cover_crop = true;
torrent.markModified('resource_detail_info');
torrent.save();
}
});
}
if (req.body._uImage.indexOf(cv) < 0) {
@@ -617,7 +630,7 @@ exports.create = function (req, res) {
req.body._uImage.forEach(function (f) {
var oi = config.uploads.torrent.image.temp + f;
var ni = config.uploads.torrent.image.dest + f;
var cr = config.uploads.torrent.image.crop + f;
var ci = config.uploads.torrent.image.crop + f;
move(oi, ni, function (err) {
if (err) {
@@ -625,7 +638,7 @@ exports.create = function (req, res) {
} else {
sharp(ni)
.resize(200)
.toFile(cr, function (err) {
.toFile(ci, function (err) {
if (err) {
mtDebug.debugError(err);
}