upload torrent files is ok.

This commit is contained in:
OldHawk
2017-03-29 13:41:47 +08:00
parent f8144d9434
commit 95d856a07f
7 changed files with 145 additions and 18 deletions

View File

@@ -29,7 +29,7 @@
transConfig.$inject = ['$translateProvider'];
function transConfig($translateProvider) {
$translateProvider.useSanitizeValueStrategy('escape');
//$translateProvider.useSanitizeValueStrategy('escape');
$translateProvider.preferredLanguage('en');
//$translateProvider.fallbackLanguage('cn');
}

View File

@@ -46,13 +46,22 @@
UPLOADS_RULES: '上传规则:',
UPLOADS_RULES_COUNT: '6',
UPLOADS_RULES_CONTENT: [
'种子文件的Tracker地址必须为<mark><strong>{{url}}</strong></mark>',
'种子文件的 TMDB_ID 必须是 The Movie DB 相对应的资源ID号<strong><a href="https://www.themoviedb.org/">您可以从这里找到ID号</a></strong>',
'资源的详细信息,系统会自动载入,如无误可直接提交',
'请为资源选择匹配的一个或多个标签,它会在您的搜索结果中发挥重大作用',
'种子文件提交后,可能会由后台管理人员进行审批,不符合规则的种子会被直接删除',
'如需其它帮助,请与我们的管理员联系:<strong><a href="mailto:#">{{admin}}</a></strong>'
]
'种子文件的Tracker地址必须为<mark><strong>{{url}}</strong></mark>.',
'种子文件的 TMDB_ID 必须是 The Movie DB 相对应的资源ID号<strong><a href="https://www.themoviedb.org/">您可以从这里找到ID号</a></strong>.',
'资源的详细信息,系统会自动载入,如无误可直接提交.',
'请为资源选择匹配的一个或多个标签,它会在您的搜索结果中发挥重大作用.',
'种子文件提交后,可能会由后台管理人员进行审批,不符合规则的种子会被直接删除.',
'如需其它帮助,请与我们的管理员联系:<strong><a href="mailto:#">{{admin}}</a></strong>.'
],
//TorrentsUploadsController
TORRENTS_UPLOAD_SUCCESSFULLY: '文件上传成功',
TORRENTS_UPLOAD_FAILED: '文件上传失败',
TORRENTS_NO_FILE_SELECTED: '请选择种子文件后再做尝试',
SELECT_TORRENT_FILE: '请选择种子文件',
SELECT_FILE: '选择文件',
DO_UPLOADS: '上传'
};
// **************************************************

View File

@@ -42,17 +42,26 @@
CHANGE_PASSWORD: 'Change Password',
MANAGE_SOCIAL_ACCOUNTS: 'Manage Social Accounts',
//发种规则
//Uploads rules
UPLOADS_RULES: 'Uploads Rules:',
UPLOADS_RULES_COUNT: '6',
UPLOADS_RULES_CONTENT: [
'The torrent file`s Tracker URL must be: <mark><strong>{{url}}</strong></mark>',
'The torrent file`s TMDB_ID must be TheMovieDB resources ID, <strong><a href="https://www.themoviedb.org/">you can find the ID from here</a></strong>',
'The resources detail info can be autoload, if it`s fine, then you can submit it',
'Select one or more tags that match the resources, which will play a significant role in your search results',
'After the submission of documents, may be approved by the management, the rules do not meet the seeds will be deleted directly',
'For additional assistance, please contact our administrator: <strong><a href="mailto:#">{{admin}}</a></strong>'
]
'The torrent file`s Tracker URL must be: <mark><strong>{{url}}</strong></mark>.',
'The torrent file`s TMDB_ID must be TheMovieDB resources ID, <strong><a href="https://www.themoviedb.org/">you can find the ID from here</a></strong>.',
'The resources detail info can be autoload, if it`s fine, then you can submit it.',
'Select one or more tags that match the resources, which will play a significant role in your search results.',
'After the submission of documents, may be approved by the management, the rules do not meet the seeds will be deleted directly.',
'For additional assistance, please contact our administrator: <strong><a href="mailto:#">{{admin}}</a></strong>.'
],
//TorrentsUploadsController & views
TORRENTS_UPLOAD_SUCCESSFULLY: 'Successfully uploads file',
TORRENTS_UPLOAD_FAILED: 'Failed to uploads file',
TORRENTS_NO_FILE_SELECTED: 'No file selected',
SELECT_TORRENT_FILE: 'Please select the torrent file',
SELECT_FILE: 'Select file',
DO_UPLOADS: 'Uploads'
};
// **************************************************

View File

@@ -41,3 +41,7 @@ a:hover .header-profile-image {
.has-error .help-inline.error-text {
display: inline;
}
.small-legend{
font-size: 18px;
}

View File

@@ -5,12 +5,15 @@
.module('torrents')
.controller('TorrentsUploadsController', TorrentsUploadsController);
TorrentsUploadsController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'AnnounceConfig'];
TorrentsUploadsController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', 'AnnounceConfig', 'Upload', 'Notification'];
function TorrentsUploadsController($scope, $state, $translate, Authentication, AnnounceConfig) {
function TorrentsUploadsController($scope, $state, $translate, $timeout, Authentication, AnnounceConfig, Upload, Notification) {
var vm = this;
vm.announce = AnnounceConfig.announce;
vm.rule_items = [];
vm.user = Authentication.user;
vm.progress = 0;
vm.successfully = undefined;
for (var i = 0; i < $translate.instant('UPLOADS_RULES_COUNT'); i++) {
vm.rule_items[i] = i;
@@ -21,5 +24,56 @@
$state.go('authentication.signin');
}
//begin upload
vm.upload = function (dataUrl) {
console.log(dataUrl);
if(dataUrl===null){
vm.fileSelected = false;
// Show success message
Notification.success({
message: '<i class="glyphicon glyphicon-remove"></i> ' + $translate.instant('TORRENTS_NO_FILE_SELECTED')
});
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);
});
};
// Called after the user has successfully uploaded a new picture
function onSuccessItem(response) {
vm.fileSelected = false;
vm.successfully = true;
// Show success message
Notification.success({
message: '<i class="glyphicon glyphicon-ok"></i> ' + $translate.instant('TORRENTS_UPLOAD_SUCCESSFULLY')
});
}
// Called after the user has failed to upload a new picture
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')
});
}
}
}());

View File

@@ -0,0 +1,20 @@
(function () {
'use strict';
// Users service used for communicating with the users REST endpoint
angular
.module('torrents.services')
.factory('TorrentsService', TorrentsService);
TorrentsService.$inject = ['$resource'];
function TorrentsService($resource) {
var Torrents = $resource('/api/torrents', {}, {
update: {
method: 'POST'
}
});
return Torrents;
}
}());

View File

@@ -10,4 +10,35 @@
</div>
</div>
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-xs-12">
<legend class="small-legend" translate="SELECT_TORRENT_FILE"></legend>
<div class="col-md-8 col-sm-8 col-xs-12">
<div class="input-group">
<input type="text" class="form-control" ng-model="tFile.name" disabled>
<div class="input-group-btn">
<button class="btn btn-primary btn-file" ngf-select="vm.fileSelected = true; vm.successfully = undefined; vm.progress = 0;"
ng-model="tFile"
ngf-resize="{width: 400}"
ngf-resize-if="$width > 400 || $height > 400"
ng-disabled="vm.successfully">{{ 'SELECT_FILE' | translate}}
</button>
</div>
</div>
</div>
<div ng-show="vm.fileSelected" class="col-md-4 col-sm-4 col-xs-12">
<button class="btn btn-success" ng-click="vm.upload(tFile)">{{ 'DO_UPLOADS' | translate}} ({{vm.progress}}%)</button>
</div>
<div ng-show="vm.successfully == true" class="col-md-4 col-sm-4 col-xs-12" style="margin-top: 8px">
<label class="text-success control-label" translate="TORRENTS_UPLOAD_SUCCESSFULLY"></label>
</div>
<div ng-show="vm.successfully == false" class="col-md-4 col-sm-4 col-xs-12" style="margin-top: 8px">
<label class="text-danger control-label" translate="TORRENTS_UPLOAD_FAILED"></label>
</div>
</div>
</div>
</section>