From 38018a507ee10b5f9ced284b89012f1dae6e975e Mon Sep 17 00:00:00 2001 From: OldHawk Date: Thu, 28 Sep 2017 18:31:49 +0800 Subject: [PATCH] feat(torrents): create music torrents --- modules/core/client/app/trans-string-en.js | 9 ++ modules/core/client/app/trans-string-zh.js | 9 ++ .../mt-markdown-editor.client.directive.js | 25 +++- .../forums-topic.client.controller.js | 2 + .../forums/client/views/post.client.view.html | 4 +- .../client/views/topic.client.view.html | 1 + .../controllers/uploads.client.controller.js | 135 +++++++++++++++++- .../torrent-download.client.service.js | 4 +- .../views/uploads-torrents.client.view.html | 118 ++++++++++++++- .../controllers/torrents.server.controller.js | 44 ++++-- 10 files changed, 328 insertions(+), 23 deletions(-) diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index 00c4a5a9..bbce2561 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -358,6 +358,15 @@ AGREE_RULES: 'I agree and already read all the rules, read here', DOWNLOAD_TORRENT: 'Download Torrent', + ENTER_MUSIC_TITLE: '3. Please enter the music/album title', + MUSIC_TITLE: 'title', + MUSIC_SUB_TITLE: 'short desc', + SELECT_MUSIC_IMAGE: '3.1 Please select music/album cover image', + MUSIC_COVER_UPLOAD_SUCCESSFULLY: 'Successfully upload music cover', + MUSIC_COVER_UPLOAD_FAILED: 'Failed to upload music cover', + ENTER_MUSIC_DETAIL_INFO: '4. Please enter the music/album detail info', + ERROR_ONLY_IMAGE: 'Only image files support(gif, png, bmp, jpg, jpeg)', + //ranking view PAGE_HEADER_RANKING_UPLOAD: 'Uploaded Ranking', PAGE_HEADER_RANKING_DOWNLOAD: 'Downloaded Ranking', diff --git a/modules/core/client/app/trans-string-zh.js b/modules/core/client/app/trans-string-zh.js index cc3f8252..837619db 100644 --- a/modules/core/client/app/trans-string-zh.js +++ b/modules/core/client/app/trans-string-zh.js @@ -358,6 +358,15 @@ AGREE_RULES: '我已阅读并同意站内所有协议条款,协议条款', DOWNLOAD_TORRENT: '下载种子', + ENTER_MUSIC_TITLE: '3. 请输入音乐/专辑标题', + MUSIC_TITLE: '标题', + MUSIC_SUB_TITLE: '短描述', + SELECT_MUSIC_IMAGE: '3.1 请选择音乐/专辑封面图片', + MUSIC_COVER_UPLOAD_SUCCESSFULLY: '封面图片上传成功', + MUSIC_COVER_UPLOAD_FAILED: '封面图片上传失败', + ENTER_MUSIC_DETAIL_INFO: '4. 请输入音乐/专辑详细信息', + ERROR_ONLY_IMAGE: '此处只支持图片文件上传(gif, png, bmp, jpg, jpeg)', + //ranking view PAGE_HEADER_RANKING_UPLOAD: '上传量排行榜', PAGE_HEADER_RANKING_DOWNLOAD: '下载量排行榜', diff --git a/modules/core/client/directives/mt-markdown-editor.client.directive.js b/modules/core/client/directives/mt-markdown-editor.client.directive.js index fd54f36a..a642a8c2 100644 --- a/modules/core/client/directives/mt-markdown-editor.client.directive.js +++ b/modules/core/client/directives/mt-markdown-editor.client.directive.js @@ -4,9 +4,9 @@ angular.module('core') .directive('mtMarkdownEditor', mtMarkdownEditor); - mtMarkdownEditor.$inject = ['localStorageService', '$compile', 'NotifycationService', '$timeout']; + mtMarkdownEditor.$inject = ['localStorageService', '$compile', 'NotifycationService', '$translate', 'DebugConsoleService', '$timeout']; - function mtMarkdownEditor(localStorageService, $compile, NotifycationService, $timeout) { + function mtMarkdownEditor(localStorageService, $compile, NotifycationService, $translate, mtDebug, $timeout) { var directive = { restrict: 'A', require: 'ngModel', @@ -32,6 +32,7 @@ scope.uProgress = 0; scope.uFiles = []; scope.uImages = []; + scope.$parent.uImages = []; var eleUploadTip = angular.element('
{{\'FORUMS.ATTACH_UPLOAD_TOOLTIP1\' | translate}}{{\'FORUMS.ATTACH_UPLOAD_TOOLTIP2\' | translate}}{{\'FORUMS.ATTACH_UPLOAD_TOOLTIP3\' | translate}}
'); var eleUploadBegin = angular.element('
{{\'FORUMS.ATTACH_UPLOADING\' | translate}}: {{uFile.name}}
'); @@ -71,10 +72,27 @@ }); function doUpload(sFile) { + if (!sFile) { + return; + } + + if (attrs.uploadOnlyImage) { + if (sFile.type !== 'image/png' && sFile.type !== 'image/jpg' && sFile.type !== 'image/jpeg' && sFile.type !== 'image/gif' && sFile.type !== 'image/bmp') { + NotifycationService.showErrorNotify($translate.instant('ERROR_ONLY_IMAGE'), 'ERROR'); + console.error($translate.instant('ERROR_ONLY_IMAGE')); + return; + } + } + if (attrs.uploadMethod) { scope.uFile = sFile; scope.uProgress = 0; + if (!attrs.uploadDir) { + console.error('uploadMethod must has a uploadDir attr!'); + return; + } + scope.$eval(attrs.uploadMethod, { editor: e, ufile: scope.uFile, @@ -89,10 +107,11 @@ var status = ''; var ext = uFile.name.replace(/^.+\./, '').toLowerCase(); if (ext === 'jpg' || ext === 'jpeg' || ext === 'bmp' || ext === 'gif' || ext === 'png') { - status = '\n![' + uFile.name + '](/modules/forums/client/attach/temp/' + uFile.name + ')\n'; + status = '\n![' + uFile.name + '](' + attrs.uploadDir + uFile.name + ')\n'; e.replaceSelection(status); ngModel.$setViewValue($('#' + attrs.mtMarkdownEditor)[0].value); scope.uImages.push(uFile); + scope.$parent.uImages.push(uFile); } else { scope.uFiles.push(uFile); } diff --git a/modules/forums/client/controllers/forums-topic.client.controller.js b/modules/forums/client/controllers/forums-topic.client.controller.js index 2ab397a8..9791243a 100644 --- a/modules/forums/client/controllers/forums-topic.client.controller.js +++ b/modules/forums/client/controllers/forums-topic.client.controller.js @@ -408,6 +408,7 @@ return false; } + mtDebug.info($scope.uFiles); var uf = []; angular.forEach($scope.uFiles, function (f) { uf.push({ @@ -416,6 +417,7 @@ }); }); + mtDebug.info($scope.uImages); var uimg = []; angular.forEach($scope.uImages, function (f) { uimg.push({ diff --git a/modules/forums/client/views/post.client.view.html b/modules/forums/client/views/post.client.view.html index 8f847436..dfcea329 100644 --- a/modules/forums/client/views/post.client.view.html +++ b/modules/forums/client/views/post.client.view.html @@ -30,7 +30,9 @@
+ mt-markdown-editor="postContent" + upload-dir="/modules/forums/client/attach/temp/" + upload-method="vm.uploadAttach(editor, ufile, progressback, callback, errback);" required>

{{ 'FORUMS.PC_REQUIRED' | translate}}

diff --git a/modules/forums/client/views/topic.client.view.html b/modules/forums/client/views/topic.client.view.html index bca798e4..57301332 100644 --- a/modules/forums/client/views/topic.client.view.html +++ b/modules/forums/client/views/topic.client.view.html @@ -256,6 +256,7 @@
diff --git a/modules/torrents/client/controllers/uploads.client.controller.js b/modules/torrents/client/controllers/uploads.client.controller.js index d0e334a5..2ead6bb2 100644 --- a/modules/torrents/client/controllers/uploads.client.controller.js +++ b/modules/torrents/client/controllers/uploads.client.controller.js @@ -6,10 +6,10 @@ .controller('TorrentsUploadController', TorrentsUploadController); TorrentsUploadController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', 'MeanTorrentConfig', 'Upload', 'Notification', - 'TorrentsService', 'getStorageLangService', '$filter', 'DownloadService', 'DebugConsoleService']; + 'TorrentsService', 'getStorageLangService', '$filter', 'DownloadService', 'DebugConsoleService', 'NotifycationService']; function TorrentsUploadController($scope, $state, $translate, $timeout, Authentication, MeanTorrentConfig, Upload, Notification, - TorrentsService, getStorageLangService, $filter, DownloadService, mtDebug) { + TorrentsService, getStorageLangService, $filter, DownloadService, mtDebug, NotifycationService) { var vm = this; vm.announceConfig = MeanTorrentConfig.meanTorrentConfig.announce; vm.tmdbConfig = MeanTorrentConfig.meanTorrentConfig.tmdbConfig; @@ -22,6 +22,7 @@ vm.torrentInfo = null; vm.tags = []; vm.videoNfo = ''; + vm.music = {}; // If user is not signed in then redirect back home if (!Authentication.user) { @@ -90,6 +91,79 @@ }); } + /** + * uploadMusicCover + * @param dataUrl + */ + vm.uploadMusicCover = function (dataUrl) { + mtDebug.info(dataUrl); + + if (dataUrl === null || dataUrl === undefined) { + vm.music.fileSelected = false; + Notification.info({ + message: ' ' + $translate.instant('TORRENTS_NO_FILE_SELECTED') + }); + return; + } + + Upload.upload({ + url: '/api/torrents/uploadTorrentCover', + data: { + newTorrentCoverFile: dataUrl + } + }).then(function (response) { + vm.music.fileSelected = false; + vm.music.successfully = true; + mtDebug.info(response); + vm.music.coverFileName = response.data.filename; + Notification.success({ + message: ' ' + $translate.instant('MUSIC_COVER_UPLOAD_SUCCESSFULLY') + }); + }, function (response) { + mtDebug.info(response); + if (response.status > 0) { + vm.music.fileSelected = false; + vm.music.successfully = false; + vm.music.coverFile = undefined; + Notification.error({ + message: response.data, + title: ' ' + $translate.instant('MUSIC_COVER_UPLOAD_FAILED') + }); + } + }, function (evt) { + vm.music.progress = parseInt(100.0 * evt.loaded / evt.total, 10); + }); + }; + + /** + * uploadTorrentImage + * @param editor + * @param ufile + * @param progressback + * @param callback + * @param errback + */ + vm.uploadTorrentImage = function (editor, 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)); + } + }); + }; + /** * onTMDBIDKeyDown * @param evt @@ -347,6 +421,63 @@ } }; + /** + * createMusicTorrent + */ + vm.createMusicTorrent = function () { + var l = vm.getTorrentSize(); + var t = vm.getResourceTag(); + + var detail_info = { + title: vm.music.title, + subtitle: vm.music.subtitle, + cover: vm.music.coverFileName, + detail: vm.music.detail + }; + + mtDebug.info($scope.uImages); + var uimg = []; + angular.forEach($scope.uImages, function (f) { + mtDebug.info(f); + uimg.push({ + filename: f.name + }); + }); + + var torrent = new TorrentsService({ + info_hash: vm.torrentInfo.info_hash, + torrent_filename: vm.torrentInfo.filename, + torrent_type: 'music', + torrent_tags: t, + torrent_nfo: vm.videoNfo, + torrent_announce: vm.torrentInfo.announce, + torrent_size: l, + + resource_detail_info: detail_info, + _uImage: uimg + }); + + + torrent.$save(function (response) { + successCallback(response); + }, function (errorResponse) { + errorCallback(errorResponse); + }); + + function successCallback(res) { + vm.downloadTorrent(res._id); + Notification.success({message: ' Torrent created successfully!'}); + + $state.reload('torrents.uploads'); + document.body.scrollTop = document.documentElement.scrollTop = 0; + } + + function errorCallback(res) { + vm.error_msg = res.data.message; + Notification.error({message: res.data.message, title: ' Torrent created error!'}); + } + }; + /** * getTorrentSize * @returns {number} diff --git a/modules/torrents/client/services/torrent-download.client.service.js b/modules/torrents/client/services/torrent-download.client.service.js index b49da845..cfdc5f30 100644 --- a/modules/torrents/client/services/torrent-download.client.service.js +++ b/modules/torrents/client/services/torrent-download.client.service.js @@ -24,9 +24,9 @@ var fileName = decodeURI(contentDisposition.substr(contentDisposition.indexOf('filename=') + 9)); FileSaver.saveAs(response.data, fileName); - successcb(response.status); + if (successcb) successcb(response.status); }, function errorCallback(response) { - errorcb(response); + if (errorcb) errorcb(response); }); } } diff --git a/modules/torrents/client/views/uploads-torrents.client.view.html b/modules/torrents/client/views/uploads-torrents.client.view.html index 1d975e95..7d68fd05 100644 --- a/modules/torrents/client/views/uploads-torrents.client.view.html +++ b/modules/torrents/client/views/uploads-torrents.client.view.html @@ -46,15 +46,17 @@
-
+
-
+
@@ -85,7 +87,7 @@
-
-