Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
feat(Torrent/Download): Add user download pos check
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Aug 13, 2019
1 parent c5d3378 commit db6d5ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
24 changes: 19 additions & 5 deletions apps/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class User
private $last_access_ip;
private $last_tracker_ip;

private $uploadpos;
private $downloadpos;

private $uploaded;
private $true_uploaded;
private $downloaded;
Expand Down Expand Up @@ -204,11 +207,22 @@ public function getClass(): int
return $this->class;
}

/** TODO use gravatar
* @param array $opts
* @return mixed
*/
public function getAvatar($opts = [])
public function getPasskey(): string
{
return $this->passkey;
}

public function getUploadpos(): bool
{
return (bool)$this->uploadpos;
}

public function getDownloadpos(): bool
{
return (bool)$this->downloadpos;
}

public function getAvatar(array $opts = []): string
{
if (config('user.avatar_provider') === 'gravatar') {
/** Get a Gravatar URL for a specified email address.
Expand Down
10 changes: 8 additions & 2 deletions apps/models/form/Torrent/DownloadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class DownloadForm extends StructureForm
public static function inputRules()
{
return [
'id' => 'required | Integer',
'id' => 'required | Integer', // torrent_id
//'passkey' // TODO add support
];
}

public static function callbackRules()
{
return ['isExistTorrent', 'rateLimitCheck'];
return ['checkDownloadPos', 'isExistTorrent', 'rateLimitCheck'];
}

protected function getSendFileName(): string
Expand All @@ -45,6 +45,12 @@ protected function getRateLimitRules(): array
];
}

protected function checkDownloadPos()
{
if (!app()->auth->getCurUser()->getDownloadpos())
$this->buildCallbackFailMsg('pos','your download pos is disabled');
}

public function getSendFileContent()
{
$dict = $this->getTorrentFileContentDict();
Expand Down

0 comments on commit db6d5ff

Please sign in to comment.