diff --git a/apps/controllers/TorrentController.php b/apps/controllers/TorrentController.php index 87d5a4f..a981216 100644 --- a/apps/controllers/TorrentController.php +++ b/apps/controllers/TorrentController.php @@ -44,8 +44,16 @@ public function actionUpload() } } else { + + // FIXME + $categories = app()->redis->get('site:enabled_torrent_category'); + if (false === $categories) { + $categories = app()->pdo->createCommand('SELECT * FROM `torrents_categories` WHERE `enabled` = 1 ORDER BY `parent_id`,`sort_index`,`id`')->queryAll(); + app()->redis->set('site:enabled_torrent_category', $categories, 86400); + } + // TODO Check user can upload - return $this->render('torrent/upload'); + return $this->render('torrent/upload', ['categories' => $categories]); } } diff --git a/apps/models/form/TorrentUploadForm.php b/apps/models/form/TorrentUploadForm.php index 177b96d..6cc489c 100644 --- a/apps/models/form/TorrentUploadForm.php +++ b/apps/models/form/TorrentUploadForm.php @@ -23,6 +23,7 @@ class TorrentUploadForm extends Validator /** @var \Rid\Http\UploadFile */ public $file; + public $category; public $title; public $subtitle = ""; public $descr; @@ -46,6 +47,15 @@ class TorrentUploadForm extends Validator // 规则 public static function inputRules() { + $categories = app()->redis->get('site:enabled_torrent_category'); + if (false === $categories) { + $categories = app()->pdo->createCommand('SELECT * FROM `torrents_categories` WHERE `enabled` = 1 ORDER BY `parent_id`,`sort_index`,`id`')->queryAll(); + app()->redis->set('site:enabled_torrent_category', $categories, 86400); + } + $categories_id_list = array_map(function ($cat) { + return $cat['id']; + }, $categories); + return [ 'title' => 'required', 'file' => [ @@ -54,6 +64,11 @@ public static function inputRules() ['Upload\Extension', ['allowed' => 'torrent']], ['Upload\Size', ['size' => config("torrent.max_file_size") . 'B']] ], + 'category' => [ + ['required'], + ['Integer'], + ['InList', ['list' => $categories_id_list]] + ], 'descr' => 'required', 'uplver' => [ ['InList', ['list' => ['yes', 'no']]] @@ -176,7 +191,7 @@ public function flush() 'status' => $this->status, 'title' => $this->title, 'subtitle' => $this->subtitle, - 'category' => 1, // FIXME add category support + 'category' => $this->category, // FIXME add category support 'filename' => $this->file->getBaseName(), 'torrent_name' => $this->torrent_name, 'torrent_type' => $this->torrent_type, @@ -242,7 +257,8 @@ private function setBuff() * * @return bool|string */ - private function getFileTree() { + private function getFileTree() + { $structure = array_column($this->torrent_list, 'size', 'filename'); if ($this->torrent_type == self::TORRENT_TYPE_MULTI) { $structure = [$this->torrent_name => self::makeFileTree($structure)]; diff --git a/apps/views/torrent/upload.php b/apps/views/torrent/upload.php index e4be528..d933aa4 100644 --- a/apps/views/torrent/upload.php +++ b/apps/views/torrent/upload.php @@ -6,6 +6,7 @@ * Time: 22:05 * * @var League\Plates\Template\Template $this + * @var array $categories * * TODO Add notice for users which can't directly upload torrent (in pending status) */ @@ -21,50 +22,68 @@
- - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - + + + + + +
- You should obey our upload rules. **LINK**
- You should obey our upload rules. **LINK**
- - -
+
+
+
+ +
+
+
+ + +
+ You should obey our upload rules. **LINK** +
+ You should obey our upload rules. **LINK** +
-
-
- user->getClass(true) > config('authority.upload_anonymous') ? '' : ' disabled' ?> - > -
-
- user->getClass(true) > config('authority.upload_anonymous') ? '' : ' disabled' // FIXME ?> - > -
-
+
+ user->getClass(true) > config('authority.upload_anonymous') ? '' : ' disabled' ?> + > +
+
+ user->getClass(true) > config('authority.upload_anonymous') ? '' : ' disabled' // FIXME ?> + > +
+