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

Commit

Permalink
feat(Category): Add Categories Support when upload torrent
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jul 17, 2019
1 parent 77aba91 commit db9b99c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 45 deletions.
10 changes: 9 additions & 1 deletion apps/controllers/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

}
Expand Down
20 changes: 18 additions & 2 deletions apps/models/form/TorrentUploadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class TorrentUploadForm extends Validator
/** @var \Rid\Http\UploadFile */
public $file;

public $category;
public $title;
public $subtitle = "";
public $descr;
Expand All @@ -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' => [
Expand All @@ -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']]]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)];
Expand Down
103 changes: 61 additions & 42 deletions apps/views/torrent/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand All @@ -21,50 +22,68 @@
<form id="torrent_upload" class="form form-horizontal" method="post" enctype="multipart/form-data">
<table id="torrent_upload_table" class="table table-bordered table-striped">
<tbody>
<tr>
<td class="nowrap"><label for="title" class="required">Title</td>
<td><input id="title" name="title" class="form-control" type="text"
placeholder="The main title of Your upload torrent"
required="required">
<small>You should obey our upload rules. **LINK**</small></td> <!-- FIXME link url -->
</tr>
<tr>
<td class="nowrap"><label for="subtitle">Sub Title</label></td>
<td><input id="subtitle" name="subtitle" class="form-control" type="text"
placeholder="The subtitle of Your upload torrent">
<small>You should obey our upload rules. **LINK**</small></td> <!-- FIXME link url -->
</tr>
<tr>
<td class="nowrap"><label for="file" class="required">Torrent File</label></td>
<td>
<input id="torrent_file" name="file" class="form-control" type="file"
accept=".torrent" required="required"
data-toggle="tooltip"
data-original-title="可直接上传从其它PT站下载的torrent文件"> <!-- FIXME original-title -->
<span id="torrent_file_name"></span>
</tr>
<tr>
<td class="nowrap"><label for="descr" class="required">Description</label></td>
<td>
<tr>
<td class="nowrap"><label for="category" class="required">Category</label></td>
<td>
<div class="row">
<div class="col-md-3">
<select id="category" name="category" class="form-control">
<option value="0" selected>Please choose one Category</option>
<?php foreach ($categories as $category) : ?>
<option value="<?= $category['id'] ?>"><?= $category['full_path'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</td>
</tr>
<tr>
<td class="nowrap"><label for="file" class="required">Torrent File</label></td>
<td>
<input id="torrent_file" name="file" class="form-control" type="file"
accept=".torrent" required="required"
data-toggle="tooltip"
data-original-title="可直接上传从其它PT站下载的torrent文件"> <!-- FIXME original-title -->
<span id="torrent_file_name"></span>
</tr>
<tr>
<td class="nowrap"><label for="title" class="required">Title</td>
<td><input id="title" name="title" class="form-control" type="text"
placeholder="The main title of Your upload torrent"
required="required">
<small>You should obey our upload rules. **LINK**</small>
</td> <!-- FIXME link url -->
</tr>
<tr>
<td class="nowrap"><label for="subtitle">Sub Title</label></td>
<td><input id="subtitle" name="subtitle" class="form-control" type="text"
placeholder="The subtitle of Your upload torrent">
<small>You should obey our upload rules. **LINK**</small>
</td> <!-- FIXME link url -->
</tr>

<tr>
<td class="nowrap"><label for="descr" class="required">Description</label></td>
<td>
<textarea id="descr" name="descr" class="form-control" style="width: 99%"
cols="100" rows="10" required="required"></textarea>
</td>
</tr>
<tr>
<td class="nowrap"><label for="descr">Other</label></td>
<td>
<div class="checkbox-primary">
<input type="checkbox" id="uplver" name="uplver" value="yes"
<?= app()->user->getClass(true) > config('authority.upload_anonymous') ? '' : ' disabled' ?>
><label for="uplver">Anonymous Upload</label>
</div>
<div class="checkbox-primary">
<input type="checkbox" id="hr" name="hr" value="yes"
<?= app()->user->getClass(true) > config('authority.upload_anonymous') ? '' : ' disabled' // FIXME ?>
><label for="hr">H&R</label>
</div>
</td>
</tr>
</td>
</tr>
<tr>
<td class="nowrap"><label for="descr">Other</label></td>
<td>
<div class="checkbox-primary">
<input type="checkbox" id="uplver" name="uplver" value="yes"
<?= app()->user->getClass(true) > config('authority.upload_anonymous') ? '' : ' disabled' ?>
><label for="uplver">Anonymous Upload</label>
</div>
<div class="checkbox-primary">
<input type="checkbox" id="hr" name="hr" value="yes"
<?= app()->user->getClass(true) > config('authority.upload_anonymous') ? '' : ' disabled' // FIXME ?>
><label for="hr">H&R</label>
</div>
</td>
</tr>
</tbody>
</table>
<div class="text-center" style="margin-bottom:30px;">
Expand Down

0 comments on commit db9b99c

Please sign in to comment.