From db6d5ff7352754e5e5196ce9fb1ef32b6a9bd000 Mon Sep 17 00:00:00 2001 From: Rhilip Date: Tue, 13 Aug 2019 11:21:54 +0800 Subject: [PATCH] feat(Torrent/Download): Add user download pos check --- apps/models/User.php | 24 ++++++++++++++++++----- apps/models/form/Torrent/DownloadForm.php | 10 ++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/apps/models/User.php b/apps/models/User.php index a54a20f..89327ba 100644 --- a/apps/models/User.php +++ b/apps/models/User.php @@ -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; @@ -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. diff --git a/apps/models/form/Torrent/DownloadForm.php b/apps/models/form/Torrent/DownloadForm.php index 1762fae..efcd027 100644 --- a/apps/models/form/Torrent/DownloadForm.php +++ b/apps/models/form/Torrent/DownloadForm.php @@ -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 @@ -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();