Files
meanTorrent/modules/torrents/client/controllers/uploads.client.controller.js

245 lines
6.9 KiB
JavaScript
Raw Normal View History

2017-03-27 15:54:17 +08:00
(function () {
'use strict';
angular
.module('torrents')
.controller('TorrentsUploadsController', TorrentsUploadsController);
TorrentsUploadsController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', 'MeanTorrentConfig', 'Upload', 'Notification',
'TorrentsService'];
2017-03-27 15:54:17 +08:00
function TorrentsUploadsController($scope, $state, $translate, $timeout, Authentication, MeanTorrentConfig, Upload, Notification,
TorrentsService) {
2017-03-27 15:54:17 +08:00
var vm = this;
vm.announce = MeanTorrentConfig.meanTorrentConfig.announce;
vm.tmdbConfig = MeanTorrentConfig.meanTorrentConfig.tmdbConfig;
2017-04-12 22:14:38 +08:00
vm.imdbConfig = MeanTorrentConfig.meanTorrentConfig.imdbConfig;
vm.resourcesTags = MeanTorrentConfig.meanTorrentConfig.resourcesTags;
2017-03-27 15:54:17 +08:00
vm.rule_items = [];
2017-03-29 13:41:47 +08:00
vm.user = Authentication.user;
vm.progress = 0;
vm.successfully = undefined;
2017-03-31 13:24:36 +08:00
vm.tmdb_info_ok = undefined;
2017-04-02 18:06:28 +08:00
vm.torrentInfo = null;
vm.tags = [];
2017-04-09 16:13:01 +08:00
vm.videoNfo = '';
2017-03-27 15:54:17 +08:00
for (var i = 0; i < $translate.instant('UPLOADS_RULES_COUNT'); i++) {
vm.rule_items[i] = i;
}
// If user is not signed in then redirect back home
if (!Authentication.user) {
$state.go('authentication.signin');
}
/**
* upload
* @param dataUrl
*/
2017-03-29 13:41:47 +08:00
vm.upload = function (dataUrl) {
//console.log(dataUrl);
2017-03-29 13:41:47 +08:00
2017-03-29 19:02:28 +08:00
if (dataUrl === null || dataUrl === undefined) {
2017-03-29 13:41:47 +08:00
vm.fileSelected = false;
// Show success message
2017-03-29 19:02:28 +08:00
Notification.info({
message: '<i class="glyphicon glyphicon-info-sign"></i> ' + $translate.instant('TORRENTS_NO_FILE_SELECTED')
2017-03-29 13:41:47 +08:00
});
return;
}
Upload.upload({
url: '/api/torrents/upload',
data: {
newTorrentFile: dataUrl
}
}).then(function (response) {
$timeout(function () {
onSuccessItem(response);
});
}, function (response) {
console.log(response);
if (response.status > 0) onErrorItem(response);
}, function (evt) {
vm.progress = parseInt(100.0 * evt.loaded / evt.total, 10);
});
};
/**
* onSuccessItem
* @param response
*/
2017-03-29 13:41:47 +08:00
function onSuccessItem(response) {
vm.fileSelected = false;
vm.successfully = true;
// Show success message
console.log(response);
2017-04-02 18:06:28 +08:00
vm.torrentInfo = response.data;
2017-03-29 13:41:47 +08:00
Notification.success({
message: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TORRENTS_UPLOAD_SUCCESSFULLY')
});
}
/**
* onErrorItem
* @param response
*/
2017-03-29 13:41:47 +08:00
function onErrorItem(response) {
vm.fileSelected = false;
vm.successfully = false;
vm.tFile = undefined;
// Show error message
Notification.error({
message: response.data,
title: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENTS_UPLOAD_FAILED')
});
}
2017-03-29 19:02:28 +08:00
/**
* onTMDBIDKeyDown
* @param evt
*/
vm.onTMDBIDKeyDown = function (evt) {
if (evt.keyCode === 13) {
2017-04-02 18:06:28 +08:00
vm.getInfo(vm.tmdb_id);
}
};
/**
* onTextClick
* @param $event
*/
2017-03-29 19:02:28 +08:00
vm.onTextClick = function ($event) {
$event.target.select();
};
/**
* getInfo
* @param tmdbid
*/
2017-03-29 19:02:28 +08:00
vm.getInfo = function (tmdbid) {
console.log(tmdbid);
if (tmdbid === null || tmdbid === undefined) {
Notification.info({
message: '<i class="glyphicon glyphicon-info-sign"></i> ' + $translate.instant('TMDB_ID_REQUIRED')
});
angular.element('#tmdbid').focus();
return;
}
2017-03-31 13:24:36 +08:00
vm.tmdb_isloading = true;
2017-03-29 19:02:28 +08:00
TorrentsService.getTMDBInfo({
tmdbid: tmdbid,
2017-03-31 13:24:36 +08:00
language: 'en'
2017-03-29 19:02:28 +08:00
}, function (res) {
2017-03-31 13:24:36 +08:00
vm.tmdb_info_ok = true;
vm.tmdb_isloading = false;
2017-03-29 19:02:28 +08:00
Notification.success({
message: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TMDB_ID_OK')
});
console.log(res);
vm.movieinfo = res;
}, function (err) {
2017-03-31 13:24:36 +08:00
vm.tmdb_info_ok = false;
vm.tmdb_isloading = false;
2017-03-29 19:02:28 +08:00
Notification.error({
message: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TMDB_ID_ERROR')
});
angular.element('#tmdbid').focus();
});
};
/**
* create
*/
2017-04-02 18:06:28 +08:00
vm.create = function () {
var d = new Date(vm.movieinfo.release_date);
var l = 0;
//console.log(vm.torrentInfo);
if (vm.torrentInfo.length !== undefined) {
l = vm.torrentInfo.length;
} else {
angular.forEach(vm.torrentInfo.info.files, function (item) {
l = l + item.length;
});
}
2017-04-02 18:06:28 +08:00
var t = [];
angular.forEach(vm.resourcesTags.movie.radio, function (item) {
if (vm.tags['tag_' + item.name]) {
t.push(vm.tags['tag_' + item.name]);
}
});
angular.forEach(vm.resourcesTags.movie.checkbox, function (item) {
angular.forEach(item.value, function (sitem) {
if (vm.tags['tag_' + item.name + '_' + sitem.name]) {
t.push(sitem.name);
}
});
});
2017-04-05 17:40:58 +08:00
var g = [];
angular.forEach(vm.movieinfo.genres, function (item) {
g.push(item.name);
});
2017-04-02 18:06:28 +08:00
var torrent = new TorrentsService({
info_hash: vm.torrentInfo.info_hash,
torrent_filename: vm.torrentInfo.filename,
2017-04-02 18:06:28 +08:00
torrent_tmdb_id: vm.tmdb_id,
torrent_imdb_id: vm.movieinfo.imdb_id,
torrent_title: vm.movieinfo.title,
2017-04-06 16:11:01 +08:00
torrent_original_title: vm.movieinfo.original_title,
2017-04-02 18:06:28 +08:00
torrent_type: 'movie',
2017-04-05 17:40:58 +08:00
torrent_genres: g,
2017-04-02 18:06:28 +08:00
torrent_tags: t,
2017-04-09 16:13:01 +08:00
torrent_nfo: vm.videoNfo,
2017-04-02 18:06:28 +08:00
torrent_announce: vm.torrentInfo.announce,
torrent_imdb_votes: vm.movieinfo.vote_average,
torrent_size: l,
torrent_img: vm.movieinfo.poster_path,
2017-04-09 01:35:09 +08:00
torrent_backdrop_img: vm.movieinfo.backdrop_path,
2017-04-02 18:06:28 +08:00
torrent_release: d.getFullYear()
});
console.log(torrent);
torrent.$save(function (response) {
successCallback(response);
}, function (errorResponse) {
errorCallback(errorResponse);
});
function successCallback(res) {
$state.reload('torrents.uploads');
document.body.scrollTop = document.documentElement.scrollTop = 0;
Notification.success({message: '<i class="glyphicon glyphicon-ok"></i> Torrent created successfully!'});
}
function errorCallback(res) {
vm.error_msg = res.data.message;
Notification.error({message: res.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Torrent created error!'});
}
};
/**
* cancel
*/
2017-04-02 18:06:28 +08:00
vm.cancel = function () {
$state.reload('torrents.uploads');
document.body.scrollTop = document.documentElement.scrollTop = 0;
};
/**
* clearAllCondition
*/
vm.clearAllCondition = function () {
vm.tags = [];
};
2017-03-27 15:54:17 +08:00
}
}());