feat(torrents): limit to upload torrent if uploader access is limit to maker group

This commit is contained in:
OldHawk
2018-04-24 12:40:40 +08:00
parent ab3d7ac2bb
commit 8301ef9d8e
6 changed files with 128 additions and 84 deletions

View File

@@ -230,7 +230,7 @@ module.exports = {
limitedIp: ['127.0.0.1']
},
upload: {
limitToMakerGroup: false
limitToMakerGroup: true
}
},

View File

@@ -480,6 +480,7 @@
BUTTON_UNSHOW_NEXT_TIME: 'I know, don`t show this next time',
POPUP_UPLOADED_TOOLTIP: 'The torrent is uploaded <strong style="color:#f00">successfully</strong> and is waiting for the administrator to review. The new torrent file with your Passkey will be <strong style="color:#f00">automatically downloaded</strong> after you click the "OK" button, and you can use this new torrent file to start seeding.',
TORRENT_DOWNLOADING_FILENAME: 'Downloading file name: ',
UPLOAD_ACCESS_TOOLTIP: '{{site}} only accepts resource maker group to upload torrents, you can <a href="/about/maker">list and join them</a>!',
SELECT_RESOURCE_TYPE: '2. Please select the resource type',
SELECT_TORRENT_FILE: '1. Please select the torrent file',
@@ -1578,7 +1579,10 @@
EMAIL_ALREADY_REGISTERED: 'This email address has been used by other user',
EMAIL_ALREADY_INVITED: 'This email address has been invited',
INVITE_MAIL_SEND_FAILED: 'Invitation mail send failed (SERVER)',
EMAIL_ADDRESS_IS_NOT_ALLOW: 'The domain of this email address is not allowable from server'
EMAIL_ADDRESS_IS_NOT_ALLOW: 'The domain of this email address is not allowable from server',
INFO_HASH_IS_EMPTY: 'Info hash field of torrent file is empty',
INFO_HASH_ALREADY_EXISTS: 'This info hash value is already exists',
UPLOAD_ACCESS_DENY: 'System only accepts resource maker group to upload torrents'
},
//server message string, content string support markdown and emoji

View File

@@ -480,6 +480,7 @@
BUTTON_UNSHOW_NEXT_TIME: '我知道了,下次不用再提示了!',
POPUP_UPLOADED_TOOLTIP: '种子<strong style="color:#f00">上传成功</strong>并等待管理员的审核,带有您 Passkey 的种子文件会在您点击 "确定" 按钮后被<strong style="color:#f00">自动下载</strong>,然后您就可以使用这个自动下载的种子文件开始做种了。',
TORRENT_DOWNLOADING_FILENAME: '种子文件名: ',
UPLOAD_ACCESS_TOOLTIP: '{{site}} 只接受资源制作小组上传种子,您可以 <a href="/about/maker">查看并加入他们</a>',
SELECT_RESOURCE_TYPE: '2. 请选择上传资源类型',
SELECT_TORRENT_FILE: '1. 请选择种子文件',
@@ -1578,7 +1579,10 @@
EMAIL_ALREADY_REGISTERED: '这个邮件地址已被其它用户注册使用了',
EMAIL_ALREADY_INVITED: '这个邮件地址已经被邀请过了',
INVITE_MAIL_SEND_FAILED: '邀请邮件发送失败(SERVER)',
EMAIL_ADDRESS_IS_NOT_ALLOW: '该邮件地址不允许被邀请或注册'
EMAIL_ADDRESS_IS_NOT_ALLOW: '该邮件地址不允许被邀请或注册',
INFO_HASH_IS_EMPTY: 'Info hash 字段值不能为空',
INFO_HASH_ALREADY_EXISTS: '该 info hash 值已经存在,不能重复提交',
UPLOAD_ACCESS_DENY: '当前系统只接受资源制作小组上传种子'
},
//server message string, content string support markdown and emoji

View File

@@ -82,6 +82,18 @@
}
});
/**
* getAccessUploader
* @returns {boolean}
*/
vm.getAccessUploader = function () {
if (!vm.accessConfig.upload.limitToMakerGroup) {
return true;
} else {
return vm.user.makers.length > 0;
}
};
/**
* getTemplateFileContent
* @param file

View File

@@ -8,92 +8,100 @@
</div>
</div>
<div class="row margin-bottom-40">
<div class="col-xs-12">
<legend class="small-legend" translate="SELECT_TORRENT_FILE"></legend>
<div class="col-sm-7">
<div class="input-group">
<input type="text" class="form-control" ng-model="vm.tFile.name" disabled>
<div ng-if="!vm.getAccessUploader()">
<div class="alert alert-warning text-center" role="alert" style="padding: 30px 50px 20px 50px;">
<h4 translate="UPLOAD_ACCESS_TOOLTIP" translate-values="{site: vm.appConfig.name}"></h4>
</div>
</div>
<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="vm.tFile"
accept="application/x-bittorrent"
ng-disabled="vm.successfully">{{ 'SELECT_FILE' | translate}}
</button>
<div ng-if="vm.getAccessUploader()">
<div class="row margin-bottom-40">
<div class="col-xs-12">
<legend class="small-legend" translate="SELECT_TORRENT_FILE"></legend>
<div class="col-sm-7">
<div class="input-group">
<input type="text" class="form-control" ng-model="vm.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="vm.tFile"
accept="application/x-bittorrent"
ng-disabled="vm.successfully">{{ 'SELECT_FILE' | translate}}
</button>
</div>
</div>
</div>
<div ng-show="vm.fileSelected" class="col-sm-5">
<button class="btn btn-success" ng-click="vm.upload(vm.tFile)">{{ 'DO_UPLOAD' | translate}} ({{vm.progress}}%)</button>
</div>
<div ng-show="vm.successfully == true" class="col-sm-5" style="margin-top: 7px">
<label class="text-success control-label" translate="TORRENTS_UPLOAD_SUCCESSFULLY"></label>
</div>
<div ng-show="vm.successfully == false" class="col-sm-5" style="margin-top: 7px">
<label class="text-danger control-label" translate="TORRENTS_UPLOAD_FAILED"></label>
</div>
</div>
</div>
<div class="row margin-bottom-40" ng-show="vm.successfully == true">
<div class="col-xs-12">
<legend class="small-legend" translate="SELECT_RESOURCE_TYPE"></legend>
<div class="col-xs-12 col-sm-6 col-md-4">
<select class="form-control" ng-model="vm.selectedType" ng-change="vm.onTorrentTypeChanged();">
<option ng-repeat="t in vm.torrentType.value | filter:{enable: true}"
ng-if="t.role=='user' || (t.role=='vip' && (vm.user.isVip || vm.user.isOper))"
value="{{t.value}}">{{'MENU_TORRENTS_SUB.'+t.name | translate}}
</option>
</select>
</div>
</div>
</div>
<div ng-show="vm.selectedType" ng-include="vm.getIncludeUploadTemplateID(vm.selectedType);"></div>
<div class="row margin-bottom-40 margin-top-50" ng-show="vm.showAgreeAndSubmit || vm.customTorrent.detail">
<div class="col-xs-12">
<legend class="small-legend" translate="SELECT_MAKER_GROUP"></legend>
<div class="col-xs-12 col-sm-6 col-md-4">
<label class="radio-inline">
<input type="radio" name="maker_NULL" ng-model="vm.maker"
id="maker_NULL"
value="NULL"> {{'MAKER_NULL' | translate}}
</label>
<label class="radio-inline" ng-repeat="m in vm.user.makers">
<input type="radio" name="maker_{{m.name}}" ng-model="vm.maker"
id="maker_{{m.name}}"
value="{{m._id}}"> {{m.name}}
</label>
</div>
<div class="col-xs-12">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="vm.anonymous"> {{'UPLOADER_ANONYMOUS' | translate}}
</label>
</div>
</div>
</div>
<div ng-show="vm.fileSelected" class="col-sm-5">
<button class="btn btn-success" ng-click="vm.upload(vm.tFile)">{{ 'DO_UPLOAD' | translate}} ({{vm.progress}}%)</button>
</div>
<div ng-show="vm.successfully == true" class="col-sm-5" style="margin-top: 7px">
<label class="text-success control-label" translate="TORRENTS_UPLOAD_SUCCESSFULLY"></label>
</div>
<div ng-show="vm.successfully == false" class="col-sm-5" style="margin-top: 7px">
<label class="text-danger control-label" translate="TORRENTS_UPLOAD_FAILED"></label>
</div>
</div>
</div>
<div class="row margin-bottom-40" ng-show="vm.successfully == true">
<div class="col-xs-12">
<legend class="small-legend" translate="SELECT_RESOURCE_TYPE"></legend>
<div class="col-xs-12 col-sm-6 col-md-4">
<select class="form-control" ng-model="vm.selectedType" ng-change="vm.onTorrentTypeChanged();">
<option ng-repeat="t in vm.torrentType.value | filter:{enable: true}"
ng-if="t.role=='user' || (t.role=='vip' && (vm.user.isVip || vm.user.isOper))"
value="{{t.value}}">{{'MENU_TORRENTS_SUB.'+t.name | translate}}
</option>
</select>
</div>
</div>
</div>
<div ng-show="vm.selectedType" ng-include="vm.getIncludeUploadTemplateID(vm.selectedType);"></div>
<div class="row margin-bottom-40 margin-top-50" ng-show="vm.showAgreeAndSubmit || vm.customTorrent.detail">
<div class="col-xs-12">
<legend class="small-legend" translate="SELECT_MAKER_GROUP"></legend>
<div class="col-xs-12 col-sm-6 col-md-4">
<label class="radio-inline">
<input type="radio" name="maker_NULL" ng-model="vm.maker"
id="maker_NULL"
value="NULL"> {{'MAKER_NULL' | translate}}
</label>
<label class="radio-inline" ng-repeat="m in vm.user.makers">
<input type="radio" name="maker_{{m.name}}" ng-model="vm.maker"
id="maker_{{m.name}}"
value="{{m._id}}"> {{m.name}}
</label>
</div>
<div class="col-xs-12">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="vm.anonymous"> {{'UPLOADER_ANONYMOUS' | translate}}
<div class="col-md-12 col-sm-12 col-xs-12 margin-top-50">
<legend class="small-legend" translate="TORRENTS_SUBMIT_UPLOAD"></legend>
<div class="col-sm-6 col-sm-offset-3 text-center">
<label class="checkbox text-uppercase">
<input type="checkbox" id="agreeCheckbox" ng-model="vm.agreeRules">
<span translate="AGREE_RULES"></span>
</label>
</div>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12 margin-top-50">
<legend class="small-legend" translate="TORRENTS_SUBMIT_UPLOAD"></legend>
<div class="col-sm-6 col-sm-offset-3 text-center">
<label class="checkbox text-uppercase">
<input type="checkbox" id="agreeCheckbox" ng-model="vm.agreeRules">
<span translate="AGREE_RULES"></span>
</label>
</div>
<div class="col-sm-4 col-sm-offset-4">
<button class="btn btn-lg btn-block btn-success" ng-click="vm.create()"
ng-disabled="!vm.agreeRules">{{ 'SUBMIT_BUTTON' | translate}}
</button>
<button class="btn btn-lg btn-block btn-warning" ng-click="vm.cancel()">{{ 'CANCEL_BUTTON' | translate}}
</button>
</div>
<div class="col-sm-10 text-center">
<span class="error-text" ng-show="vm.error_msg">{{vm.error_msg}}</span>
<div class="col-sm-4 col-sm-offset-4">
<button class="btn btn-lg btn-block btn-success" ng-click="vm.create()"
ng-disabled="!vm.agreeRules">{{ 'SUBMIT_BUTTON' | translate}}
</button>
<button class="btn btn-lg btn-block btn-warning" ng-click="vm.cancel()">{{ 'CANCEL_BUTTON' | translate}}
</button>
</div>
<div class="col-sm-10 text-center">
<span class="error-text" ng-show="vm.error_msg">{{vm.error_msg}}</span>
</div>
</div>
</div>
</div>

View File

@@ -44,6 +44,7 @@ var serverNoticeConfig = config.meanTorrentConfig.serverNotice;
var announceConfig = config.meanTorrentConfig.announce;
var appConfig = config.meanTorrentConfig.app;
var tmdbConfig = config.meanTorrentConfig.tmdbConfig;
var accessConfig = config.meanTorrentConfig.access;
const PEERSTATE_SEEDER = 'seeder';
const PEERSTATE_LEECHER = 'leecher';
@@ -153,6 +154,7 @@ exports.upload = function (req, res) {
uploadFile()
.then(checkAnnounce)
.then(checkHash)
.then(checkCanUpload)
.then(function () {
res.status(200).send(torrentinfo);
})
@@ -241,7 +243,7 @@ exports.upload = function (req, res) {
var message = '';
if (torrentinfo.info_hash === '' || !torrentinfo.info_hash) {
message = 'INFO_HASH_IS_EMPTY';
message = 'SERVER.INFO_HASH_IS_EMPTY';
reject(message);
} else {
Torrent.findOne({
@@ -251,7 +253,7 @@ exports.upload = function (req, res) {
reject(err);
} else {
if (torrent) {
message = 'INFO_HASH_ALREADY_EXISTS';
message = 'SERVER.INFO_HASH_ALREADY_EXISTS';
reject(message);
} else {
@@ -262,6 +264,20 @@ exports.upload = function (req, res) {
}
});
}
function checkCanUpload() {
return new Promise(function (resolve, reject) {
if (!accessConfig.upload.limitToMakerGroup) {
resolve();
} else {
if (req.user.makers.length > 0) {
resolve();
} else {
reject('SERVER.UPLOAD_ACCESS_DENY');
}
}
});
}
};
/**