From cb4bec0e07cdf080caa53651115323fcd9189b4c Mon Sep 17 00:00:00 2001 From: OldHawk Date: Thu, 31 May 2018 01:10:42 +0800 Subject: [PATCH] feat(torrents): resource screenshots image edit function --- modules/core/client/app/trans-string-en.js | 2 + modules/core/client/app/trans-string-zh-tw.js | 2 + modules/core/client/app/trans-string-zh.js | 2 + .../mt-images-uploader.client.directive.js | 4 +- .../torrent-info.client.controller.js | 72 +++++++++++++++++++ modules/torrents/client/less/torrents.less | 6 +- .../views/view-torrent.client.view.html | 27 ++++++- .../controllers/torrents.server.controller.js | 60 +++++++++++++++- 8 files changed, 166 insertions(+), 9 deletions(-) diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index 70a3f958..f377704b 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -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', diff --git a/modules/core/client/app/trans-string-zh-tw.js b/modules/core/client/app/trans-string-zh-tw.js index bfc8d591..450cb1d5 100644 --- a/modules/core/client/app/trans-string-zh-tw.js +++ b/modules/core/client/app/trans-string-zh-tw.js @@ -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: '編輯媒體信息', diff --git a/modules/core/client/app/trans-string-zh.js b/modules/core/client/app/trans-string-zh.js index 61eacd9c..b161637e 100644 --- a/modules/core/client/app/trans-string-zh.js +++ b/modules/core/client/app/trans-string-zh.js @@ -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: '编辑媒体信息', diff --git a/modules/core/client/directives/mt-images-uploader.client.directive.js b/modules/core/client/directives/mt-images-uploader.client.directive.js index c05855fb..07cc07b6 100644 --- a/modules/core/client/directives/mt-images-uploader.client.directive.js +++ b/modules/core/client/directives/mt-images-uploader.client.directive.js @@ -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); } /** diff --git a/modules/torrents/client/controllers/torrent-info.client.controller.js b/modules/torrents/client/controllers/torrent-info.client.controller.js index a0effe67..4f44be70 100644 --- a/modules/torrents/client/controllers/torrent-info.client.controller.js +++ b/modules/torrents/client/controllers/torrent-info.client.controller.js @@ -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: ' ' + $translate.instant('TORRENT_UPDATE_SUCCESSFULLY') + }); + } + + function errorCallback(res) { + vm.error_msg = res.data.message; + vm.isEditScreenshots = false; + Notification.error({ + message: res.data.message, + title: ' ' + $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 */ diff --git a/modules/torrents/client/less/torrents.less b/modules/torrents/client/less/torrents.less index e32c3906..5bb6cebc 100644 --- a/modules/torrents/client/less/torrents.less +++ b/modules/torrents/client/less/torrents.less @@ -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; diff --git a/modules/torrents/client/views/view-torrent.client.view.html b/modules/torrents/client/views/view-torrent.client.view.html index b0ffc44a..25a387eb 100644 --- a/modules/torrents/client/views/view-torrent.client.view.html +++ b/modules/torrents/client/views/view-torrent.client.view.html @@ -215,9 +215,30 @@ -
- +
+
+ +
+
+
+
+ +
diff --git a/modules/torrents/server/controllers/torrents.server.controller.js b/modules/torrents/server/controllers/torrents.server.controller.js index cd8bb0ba..db672c34 100644 --- a/modules/torrents/server/controllers/torrents.server.controller.js +++ b/modules/torrents/server/controllers/torrents.server.controller.js @@ -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); + } + } }; /**