feat(torrents): resource screenshots image edit function

This commit is contained in:
OldHawk
2018-05-31 01:10:42 +08:00
parent cbe02f1c7d
commit cb4bec0e07
8 changed files with 166 additions and 9 deletions

View File

@@ -384,6 +384,8 @@
TORRENT_RATING_SUCCESSFULLY: 'Rating torrent successfully',
TORRENT_RATING_FAILED: 'Rating torrent failed',
EDIT_THIS_OVERVIEW: 'Edit this overview',
EDIT_THIS_SCREENSHOTS: 'Edit screenshots',
SAVE_THIS_SCREENSHOTS: 'Save screenshots',
VIEW_ORIGINAL_MEDIA_INFO: 'View original media info',
VIEW_FORMATTED_MEDIA_INFO: 'View formatted media info',
EDIT_THIS_MEDIA_INFO: 'Edit media info',

View File

@@ -384,6 +384,8 @@
TORRENT_RATING_SUCCESSFULLY: '為種子投票成功',
TORRENT_RATING_FAILED: '為種子投票失敗',
EDIT_THIS_OVERVIEW: '編輯詳情介紹',
EDIT_THIS_SCREENSHOTS: '編輯資源截圖',
SAVE_THIS_SCREENSHOTS: '保存資源截圖',
VIEW_ORIGINAL_MEDIA_INFO: '查看原始的媒體信息',
VIEW_FORMATTED_MEDIA_INFO: '查看格式化的媒體信息',
EDIT_THIS_MEDIA_INFO: '編輯媒體信息',

View File

@@ -384,6 +384,8 @@
TORRENT_RATING_SUCCESSFULLY: '为种子投票成功',
TORRENT_RATING_FAILED: '为种子投票失败',
EDIT_THIS_OVERVIEW: '编辑详情介绍',
EDIT_THIS_SCREENSHOTS: '编辑资源截图',
SAVE_THIS_SCREENSHOTS: '保存资源截图',
VIEW_ORIGINAL_MEDIA_INFO: '查看原始的媒体信息',
VIEW_FORMATTED_MEDIA_INFO: '查看格式化的媒体信息',
EDIT_THIS_MEDIA_INFO: '编辑媒体信息',

View File

@@ -58,6 +58,7 @@
//define method called from parent scope
//init all variable
scope.$parent.clearResourceImages = function () {
scope.ngModel = [];
initVariable();
};
scope.$parent.$parent.clearResourceImages = scope.$parent.clearResourceImages;
@@ -69,10 +70,9 @@
* initVariable
*/
function initVariable() {
scope.ngModel = [];
scope.uFile = undefined;
scope.uProgress = 0;
scope.uResourceImages = [];
scope.uResourceImages = angular.copy(scope.ngModel);
}
/**

View File

@@ -1483,6 +1483,78 @@
});
};
/**
* beginEditScreenshots
*/
vm.beginEditScreenshots = function () {
vm.isEditScreenshots = true;
var imgDiv = angular.element('.torrent-img-list');
if (imgDiv) {
imgDiv.css('display', 'none');
}
};
/**
* beginSaveScreenshots
*/
vm.beginSaveScreenshots = function () {
TorrentsService.update({
_id: vm.torrentLocalInfo._id,
screenshots_image: vm.torrentLocalInfo.screenshots_image
}, function (response) {
successCallback(response);
}, function (errorResponse) {
errorCallback(errorResponse);
});
function successCallback(res) {
vm.torrentLocalInfo = res;
vm.isEditScreenshots = false;
Notification.success({
message: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TORRENT_UPDATE_SUCCESSFULLY')
});
}
function errorCallback(res) {
vm.error_msg = res.data.message;
vm.isEditScreenshots = false;
Notification.error({
message: res.data.message,
title: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENT_UPDATE_ERROR')
});
}
};
/**
* uploadTorrentScreenshotsImage
* @param ufile
* @param progressback
* @param callback
* @param errback
*/
vm.uploadTorrentScreenshotsImage = function (ufile, progressback, callback, errback) {
Upload.upload({
url: '/api/torrents/uploadTorrentImage',
data: {
newTorrentImageFile: ufile
}
}).then(function (res) {
if (callback) {
callback(res.data.filename);
}
}, function (res) {
if (errback && res.status > 0) {
errback(res);
}
}, function (evt) {
if (progressback) {
progressback(parseInt(100.0 * evt.loaded / evt.total, 10));
}
});
};
/**
* buildPeersPager
*/

View File

@@ -150,7 +150,7 @@
color: #666;
background-color: #fafafa;
border-top: 1px dashed #ddd;
overflow-x: scroll;
overflow-x: auto;
.image-item {
position: relative;
display: table-cell;
@@ -211,8 +211,8 @@
.film-strip {
border-top: solid 26px;
border-bottom: solid 26px;
border-left: none;
border-right: none;
border-left: solid 0 transparent;
border-right: solid 0 transparent;
border-image: url("/modules/torrents/client/img/film-strip-back.png") 42 30;
border-image-repeat: repeat;
background-color: #2a2a2a;

View File

@@ -215,9 +215,30 @@
</div>
</div>
<div torrent-image-list="true" id="img_container_{{vm.torrentLocalInfo._id}}" class="img-container"
img-click-event="vm.onImageClick(event)" imgs="vm.torrentLocalInfo.screenshots_image">
<legend class="xsmall-legend strong-legend" translate="TMDB_FIELDS.IMAGE_OVERVIEW"></legend>
<div class="img-container"
ng-if="vm.torrentLocalInfo.screenshots_image.length>0 || (vm.isOwner(vm.torrentLocalInfo) || vm.user.isOper)">
<div torrent-image-list="true" id="img_container_{{vm.torrentLocalInfo._id}}"
img-click-event="vm.onImageClick(event)" imgs="vm.torrentLocalInfo.screenshots_image">
<legend class="xsmall-legend strong-legend" translate="TMDB_FIELDS.IMAGE_OVERVIEW"></legend>
</div>
<div ng-if="vm.isEditScreenshots">
<div class="resourceScreenshots" id="defaultScreenshots" name="defaultScreenshots"
mt-images-uploader="defaultScreenshots" ng-model="vm.torrentLocalInfo.screenshots_image"
upload-dir="/modules/torrents/client/uploads/temp/"
upload-method="vm.uploadTorrentScreenshotsImage(ufile, progressback, callback, errback);"></div>
</div>
<button class="btn btn-xs btn-mt-o margin-top-15" mouse-enter-toggle-class="btn-mt-o-light"
base-class="btn-mt-o-primary"
ng-if="!vm.isEditScreenshots && (vm.isOwner(vm.torrentLocalInfo) || vm.user.isOper)"
ng-click="vm.beginEditScreenshots()">
{{'EDIT_THIS_SCREENSHOTS' | translate}}
</button>
<button class="btn btn-xs btn-mt-o margin-top-15" mouse-enter-toggle-class="btn-mt-o-light"
base-class="btn-mt-o-primary"
ng-if="vm.isEditScreenshots && (vm.isOwner(vm.torrentLocalInfo) || vm.user.isOper)"
ng-click="vm.beginSaveScreenshots()">
{{'SAVE_THIS_SCREENSHOTS' | translate}}
</button>
</div>
</div>
</div>

View File

@@ -680,7 +680,7 @@ exports.create = function (req, res) {
});
}
if (req.body._uImage.indexOf(cv) < 0) {
if (req.body._uImage.indexOf(cv) < 0 && req.body.screenshots_image.indexOf(cv) < 0) {
fs.unlinkSync(oc);
}
});
@@ -893,6 +893,37 @@ exports.update = function (req, res) {
torrent.resource_detail_info.custom_subtitle = req.body.custom_subtitle;
torrent.markModified('resource_detail_info');
}
if (req.body.hasOwnProperty('screenshots_image')) {
torrent.screenshots_image = req.body.screenshots_image;
if (req.body.screenshots_image && req.body.screenshots_image.length > 0) {
var dst = config.uploads.torrent.image.dest.substr(1);
req.body.screenshots_image.forEach(function (f, key) {
var os = config.uploads.torrent.image.temp + f;
var ns = config.uploads.torrent.image.dest + f;
var cs = config.uploads.torrent.image.crop + f;
if (!f.startsWith(dst)) {
torrent.screenshots_image[key] = dst + f;
move(os, ns, function (err) {
if (err) {
mtDebug.debugRed(err);
} else {
sharp(ns)
.resize(200)
.toFile(cs, function (err) {
if (err) {
mtDebug.debugError(err);
}
});
}
});
}
});
}
}
torrent.save(function (err) {
if (err) {
@@ -903,6 +934,33 @@ exports.update = function (req, res) {
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);
}
}
};
/**