mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-05-13 00:37:10 +02:00
feat(requests): check torrent status when user accept a request
This commit is contained in:
@@ -734,6 +734,7 @@
|
||||
FIELD_USER: 'User',
|
||||
BTN_EDIT_DESC: 'Edit Desc',
|
||||
BTN_ACCEPT: 'Accept',
|
||||
WAITING_REVIEW: 'Waiting for review ...',
|
||||
EDIT_SUCCESSFULLY: 'Edit request successfully',
|
||||
EDIT_FAILED: 'Edit request failed',
|
||||
DELETE_CONFIRM_OK: 'Delete',
|
||||
@@ -1391,7 +1392,8 @@
|
||||
ALREADY_FOLLOWING: 'You have already following {{name}}',
|
||||
INVALID_OBJECTID: 'Invalid object id',
|
||||
REQUEST_STATUS_FINISHED: 'Status error! Request already finished.',
|
||||
REQUEST_STATUS_EXPIRED: 'Status error! Request already expired.'
|
||||
REQUEST_STATUS_EXPIRED: 'Status error! Request already expired.',
|
||||
TORRENT_STATUS_ERROR: 'Status error! Torrent status is not reviewed'
|
||||
},
|
||||
|
||||
//server message string, content string support markdown and emoji
|
||||
|
||||
@@ -734,6 +734,7 @@
|
||||
FIELD_USER: '求种用户',
|
||||
BTN_EDIT_DESC: '编辑描述',
|
||||
BTN_ACCEPT: '接受',
|
||||
WAITING_REVIEW: '等特审核 ...',
|
||||
EDIT_SUCCESSFULLY: '请求编辑成功',
|
||||
EDIT_FAILED: '请求编辑失败',
|
||||
DELETE_CONFIRM_OK: '删除',
|
||||
@@ -1391,7 +1392,8 @@
|
||||
ALREADY_FOLLOWING: '您已经关注过 {{name}} 了',
|
||||
INVALID_OBJECTID: '无效的数据记录ID',
|
||||
REQUEST_STATUS_FINISHED: '状态错误! 求种请求已完成.',
|
||||
REQUEST_STATUS_EXPIRED: '状态错误! 求种请求已过期.'
|
||||
REQUEST_STATUS_EXPIRED: '状态错误! 求种请求已过期.',
|
||||
TORRENT_STATUS_ERROR: '状态错误! 种子状态为未审核'
|
||||
},
|
||||
|
||||
//server message string, content string support markdown and emoji
|
||||
|
||||
@@ -148,18 +148,38 @@
|
||||
width: 80px !important;
|
||||
padding: 0 5px;
|
||||
}
|
||||
.div-overlay-accept {
|
||||
position: absolute;
|
||||
background-color: #444;
|
||||
background-color: rgba(128, 128, 128, 0.7);
|
||||
left: 95px;
|
||||
right: 15px;
|
||||
height: 116px;
|
||||
z-index: 5;
|
||||
font-size: 24px;
|
||||
font-weight: 500;
|
||||
color: #eee;
|
||||
padding-top: 35px !important;
|
||||
&:hover {
|
||||
background-color: #444 !important;
|
||||
background-color: rgba(128, 128, 128, 0.5) !important;
|
||||
}
|
||||
span {
|
||||
margin-top: 50%;
|
||||
}
|
||||
}
|
||||
.btn-response-accept {
|
||||
display: none;
|
||||
}
|
||||
.accepted-item {
|
||||
td:not(:first-child) {
|
||||
td:not(:first-child), td:not(:last-child) {
|
||||
background-color: lighten(@brand-success, 30%);
|
||||
}
|
||||
}
|
||||
.tb-v-middle {
|
||||
tbody {
|
||||
tr {
|
||||
td:first-child {
|
||||
td:first-child, td:last-child {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
@@ -179,7 +199,7 @@
|
||||
tbody {
|
||||
tr {
|
||||
td {
|
||||
&:first-child {
|
||||
&:first-child, &:last-child {
|
||||
border-top: none;
|
||||
}
|
||||
}
|
||||
@@ -193,7 +213,7 @@
|
||||
}
|
||||
&:last-child {
|
||||
td {
|
||||
&:first-child {
|
||||
&:first-child, &:last-child {
|
||||
border-bottom: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,8 @@
|
||||
<td class="col-md-1 td-v-middle text-center">
|
||||
{{vm.request.createdAt | life }}
|
||||
<div>
|
||||
<span class="badge badge_danger" ng-if="vm.isExpired(vm.request) && !vm.request.accept">Expired</span>
|
||||
<span class="badge badge_danger"
|
||||
ng-if="vm.isExpired(vm.request) && !vm.request.accept">Expired</span>
|
||||
<span class="badge badge_success" ng-if="vm.request.accept">Finished</span>
|
||||
</div>
|
||||
</td>
|
||||
@@ -128,15 +129,16 @@
|
||||
<tbody>
|
||||
<tr class="torrent-list-info" ng-repeat="item in vm.request.torrents"
|
||||
ng-click="vm.TGI.openTorrentDetailInfo(item._id);"
|
||||
ng-class="{'accepted-item': vm.request.accept == item._id}">
|
||||
ng-class="{'accepted-item': vm.request.accept == item._id}" ng-disabled="true">
|
||||
<td class="td-v-middle">
|
||||
<div class="div-accept">
|
||||
<button class="btn btn-success btn-block btn-response-accept"
|
||||
ng-click="vm.acceptResponse(item); $event.stopPropagation();"
|
||||
ng-if="!vm.request.accept && !vm.isExpired(vm.request)">
|
||||
ng-if="!vm.request.accept && !vm.isExpired(vm.request) && item.torrent_status == 'reviewed'">
|
||||
{{ 'REQUESTS.BTN_ACCEPT' | translate}}
|
||||
</button>
|
||||
<i class="fa fa-lock fa-accept pull-right" aria-hidden="true" ng-if="vm.request.accept == item._id"></i>
|
||||
<i class="fa fa-lock fa-accept pull-right" aria-hidden="true"
|
||||
ng-if="vm.request.accept == item._id"></i>
|
||||
</div>
|
||||
</td>
|
||||
<td class="col-md-7 td-v-middle td-text-overflow">
|
||||
@@ -237,6 +239,13 @@
|
||||
<td class="col-md-1 td-v-middle text-center td-uploader">
|
||||
<span user-info="item.user" info-name></span>
|
||||
</td>
|
||||
|
||||
<td class="td-v-middle text-center"
|
||||
ng-class="{'div-overlay-accept': item.torrent_status != 'reviewed'}"
|
||||
ng-click="$event.stopPropagation();"
|
||||
ng-if="item.torrent_status != 'reviewed'">
|
||||
<p>{{ 'REQUESTS.WAITING_REVIEW' | translate}}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -143,55 +143,61 @@ exports.accept = function (req, res) {
|
||||
if (request.user._id.equals(req.user._id)) {
|
||||
if ((request.createdAt + requestsConfig.requestExpires) >= Date.now()) {
|
||||
if (!request.accept) {
|
||||
var exist = false;
|
||||
request.torrents.forEach(function (r) {
|
||||
if (r._id.equals(torrent._id)) {
|
||||
exist = true;
|
||||
}
|
||||
});
|
||||
if (exist) {
|
||||
if (request.user.score >= request.rewards) {
|
||||
request.acceptedAt = Date.now();
|
||||
request.accept = torrent._id;
|
||||
if (torrent.torrent_status === 'reviewed') {
|
||||
var exist = false;
|
||||
request.torrents.forEach(function (r) {
|
||||
if (r._id.equals(torrent._id)) {
|
||||
exist = true;
|
||||
}
|
||||
});
|
||||
if (exist) {
|
||||
if (request.user.score >= request.rewards) {
|
||||
request.acceptedAt = Date.now();
|
||||
request.accept = torrent._id;
|
||||
|
||||
request.save(function (err) {
|
||||
if (err) {
|
||||
return res.status(422).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
res.json(request);
|
||||
|
||||
//transfer reward score
|
||||
request.user.update({
|
||||
$inc: {score: -request.rewards}
|
||||
}).exec();
|
||||
torrent.user.update({
|
||||
$inc: {score: request.rewards}
|
||||
}).exec();
|
||||
|
||||
//add server message
|
||||
if (serverNoticeConfig.action.RequestTorrentRespond.enable) {
|
||||
serverMessage.addMessage(torrent.user._id, serverNoticeConfig.action.RequestTorrentRespond.title, serverNoticeConfig.action.RequestTorrentRespond.content, {
|
||||
request_title: request.title,
|
||||
request_id: request._id,
|
||||
torrent_file_name: torrent.torrent_filename,
|
||||
torrent_id: torrent._id,
|
||||
by_name: request.user.displayName,
|
||||
by_id: request.user._id,
|
||||
rewards: request.rewards
|
||||
request.save(function (err) {
|
||||
if (err) {
|
||||
return res.status(422).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
res.json(request);
|
||||
|
||||
//transfer reward score
|
||||
request.user.update({
|
||||
$inc: {score: -request.rewards}
|
||||
}).exec();
|
||||
torrent.user.update({
|
||||
$inc: {score: request.rewards}
|
||||
}).exec();
|
||||
|
||||
//add server message
|
||||
if (serverNoticeConfig.action.RequestTorrentRespond.enable) {
|
||||
serverMessage.addMessage(torrent.user._id, serverNoticeConfig.action.RequestTorrentRespond.title, serverNoticeConfig.action.RequestTorrentRespond.content, {
|
||||
request_title: request.title,
|
||||
request_id: request._id,
|
||||
torrent_file_name: torrent.torrent_filename,
|
||||
torrent_id: torrent._id,
|
||||
by_name: request.user.displayName,
|
||||
by_id: request.user._id,
|
||||
rewards: request.rewards
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return res.status(422).send({
|
||||
message: 'SERVER.SCORE_NOT_ENOUGH'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res.status(422).send({
|
||||
message: 'SERVER.SCORE_NOT_ENOUGH'
|
||||
return res.status(403).json({
|
||||
message: 'SERVER.INVALID_OBJECTID'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res.status(403).json({
|
||||
message: 'SERVER.INVALID_OBJECTID'
|
||||
return res.status(422).send({
|
||||
message: 'SERVER.TORRENT_STATUS_ERROR'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user