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

Commit

Permalink
feat(torrent/upload): Add nfo,hr support
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Table `torrents` structure change
  • Loading branch information
Rhilip committed Jul 19, 2019
1 parent c327d0e commit a3eb839
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
43 changes: 26 additions & 17 deletions apps/models/form/TorrentUploadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ class TorrentUploadForm extends Validator

/** @var \Rid\Http\UploadFile */
public $file;
//public $nfo;

public $category;
public $title;
public $subtitle = '';
public $descr;
public $uplver = 'no'; // If user upload this torrent Anonymous
public $hr = 'no'; // TODO This torrent require hr check
public $uplver = 0; // If user upload this torrent Anonymous
public $hr = 0; // TODO This torrent require hr check

// Quality
public $audio = 0; /* 0 is default value. */
Expand Down Expand Up @@ -106,15 +107,22 @@ public static function inputRules()
['required'],
['Upload\Required'],
['Upload\Extension', ['allowed' => 'torrent']],
['Upload\Size', ['size' => config("torrent.max_file_size") . 'B']]
['Upload\Size', ['size' => config('torrent.max_file_size') . 'B']]
],
'nfo' => [
['Upload\Extension', ['allowed' => ['nfo', 'txt']]],
['Upload\Size', ['size' => config('torrent.max_nfo_size') . 'B']]
],
'category' => [
['required'], ['Integer'],
['InList', ['list' => $categories_id_list]]
],
'descr' => 'required',
'uplver' => [
['InList', ['list' => ['yes', 'no']]]
['InList', ['list' => [0, 1]]]
],
'hr' => [
['InList', ['list' => [0, 1]]]
],
];

Expand Down Expand Up @@ -239,28 +247,29 @@ public function flush()
])->queryScalar();
if ($count > 0) throw new \Exception('std_torrent_existed');

$nfo_blob = '';
if (isset($this->nfo)) {
$nfo_blob = $this->nfo->getFileContent();
}

// TODO update torrent status based on user class or their owned torrents count
app()->pdo->beginTransaction();
try {
app()->pdo->createCommand('INSERT INTO `torrents` (`owner_id`,`info_hash`,`status`,`added_at`,`title`,`subtitle`,`category`,`filename`,`torrent_name`,`torrent_type`,`torrent_size`,`torrent_structure`,`quality_audio`,`quality_codec`,`quality_medium`,`quality_resolution`,`descr`,`uplver`)
VALUES (:owner_id,:info_hash,:status,CURRENT_TIMESTAMP,:title,:subtitle,:category,:filename,:torrent_name,:torrent_type,:torrent_size,:torrent_structure,:quality_audio, :quality_codec, :quality_medium, :quality_resolution, :descr,:uplver)')->bindParams([
app()->pdo->createCommand('INSERT INTO `torrents` (`owner_id`,`info_hash`,`status`,`added_at`,`title`,`subtitle`,`category`,`filename`,`torrent_name`,`torrent_type`,`torrent_size`,`torrent_structure`,`quality_audio`,`quality_codec`,`quality_medium`,`quality_resolution`,`descr`,`nfo`,`uplver`,`hr`)
VALUES (:owner_id,:info_hash,:status,CURRENT_TIMESTAMP,:title,:subtitle,:category,:filename,:torrent_name,:torrent_type,:torrent_size,:torrent_structure,:quality_audio, :quality_codec, :quality_medium, :quality_resolution, :descr,:nfo ,:uplver, :hr)')->bindParams([
'owner_id' => app()->user->getId(),
'info_hash' => $this->info_hash,
'status' => $this->status,
'title' => $this->title,
'subtitle' => $this->subtitle,
'title' => $this->title, 'subtitle' => $this->subtitle,
'category' => $this->category,
'filename' => $this->file->getBaseName(),
'torrent_name' => $this->torrent_name,
'torrent_type' => $this->torrent_type,
'torrent_size' => $this->torrent_size,
'torrent_structure' => $this->torrent_structure,
'quality_audio' => $this->audio,
'quality_codec' => $this->codec,
'quality_medium' => $this->medium,
'quality_resolution' => $this->resolution,
'torrent_name' => $this->torrent_name, 'torrent_type' => $this->torrent_type,
'torrent_size' => $this->torrent_size, 'torrent_structure' => $this->torrent_structure,
'quality_audio' => $this->audio, 'quality_codec' => $this->codec,
'quality_medium' => $this->medium, 'quality_resolution' => $this->resolution,
'descr' => $this->descr,
'uplver' => $this->uplver,
'nfo' => $nfo_blob,
'uplver' => $this->uplver, 'hr' => $this->hr
])->execute();
$this->id = app()->pdo->getLastInsertId();

Expand Down
4 changes: 2 additions & 2 deletions apps/views/torrent/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@
<div class="row">
<div class="col-md-3">
<div class="switch<?= app()->user->getClass(true) > config('authority.upload_anonymous') ? '' : ' disabled' ?>">
<input type="checkbox" id="uplver" name="uplver" value="yes"><label for="uplver">Anonymous Upload</label>
<input type="checkbox" id="uplver" name="uplver" value="1"><label for="uplver">Anonymous Upload</label>
</div>
</div>
<div class="col-md-3">
<div class="switch<?= app()->user->getClass(true) > config('authority.upload_anonymous') ? '' : ' disabled' // FIXME Config key ?>">
<input type="checkbox" id="hr" name="hr" value="yes"><label for="hr">H&R</label>
<input type="checkbox" id="hr" name="hr" value="1"><label for="hr">H&R</label>
</div>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions migration/ridpt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jul 19, 2019 at 05:34 PM
-- Generation Time: Jul 19, 2019 at 11:29 PM
-- Server version: 8.0.16
-- PHP Version: 7.3.7

Expand Down Expand Up @@ -811,7 +811,9 @@ CREATE TABLE IF NOT EXISTS `torrents` (
`quality_medium` int(11) NOT NULL DEFAULT '0',
`quality_resolution` int(11) NOT NULL DEFAULT '0',
`descr` text,
`uplver` enum('yes','no') NOT NULL DEFAULT 'no',
`nfo` blob NOT NULL,
`uplver` tinyint(1) NOT NULL DEFAULT '0',
`hr` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `info_hash` (`info_hash`),
KEY `FK_torrent_categories` (`category`),
Expand Down

0 comments on commit a3eb839

Please sign in to comment.