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 utf-8 path support for torrent upload
Browse files Browse the repository at this point in the history
1. Add utf-8 path support for torrent upload
2. Add torrent clean part , It may help to clean the unnecessary
key in `info` dict. For example,
 - `x_cross_seed` by PyroCor (@see https://github.com/pyroscope/pyrocore)
 - `unique` by xseed (@see https://whatbox.ca/wiki/xseed)
 - `ttg_tag` by TTG
  • Loading branch information
Rhilip committed Feb 3, 2019
1 parent 0e1a6ab commit 1901e17
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions apps/models/form/TorrentUploadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function loadValidatorMetadata(ClassMetadata $metadata)
}
$metadata->addConstraint(new Assert\Callback([
'callback' => 'isValidTorrent',
'payload' => ["name" => "file", "maxSize" => app()->config->get("torrent.max_file_size"), "mimeTypes" => "application/x-bittorrent"]
'payload' => ['name' => 'file', 'maxSize' => app()->config->get("torrent.max_file_size"), 'mimeTypes' => 'application/x-bittorrent']
]));
}

Expand All @@ -81,17 +81,18 @@ public function isValidTorrent(ExecutionContextInterface $context, $payload)

if (isset($info['length'])) {
$this->torrent_size = $info['length'];
$this->torrent_list[] = ["filename" => $dname, "size" => $info['length'], "torrent_id" => &$this->id];
$this->torrent_type = "single";
$this->torrent_list[] = ['filename' => $dname, 'size' => $info['length'], 'torrent_id' => &$this->id];
$this->torrent_type = 'single';
} else {
$f_list = $this->checkTorrentDict($info, "files", "array");
$f_list = $this->checkTorrentDict($info, 'files', 'array');
if (!isset($f_list)) throw new ParseErrorException('std_missing_length_and_files');
if (!count($f_list)) throw new ParseErrorException('no files');

$this->torrent_size = 0;
foreach ($f_list as $fn) {
$ll = $this->checkTorrentDict($fn, "length", "integer");
$ff = $this->checkTorrentDict($fn, "path", "list");
$ll = $this->checkTorrentDict($fn, 'length', 'integer');
$path_key = isset($fn['path.utf-8']) ? 'path.utf-8' : 'path';
$ff = $this->checkTorrentDict($fn, $path_key, 'list');
$this->torrent_size += $ll;
$ffa = [];
foreach ($ff as $ffe) {
Expand All @@ -100,9 +101,9 @@ public function isValidTorrent(ExecutionContextInterface $context, $payload)
}
if (!count($ffa)) throw new ParseErrorException('std_filename_errors');
$ffe = implode("/", $ffa);
$this->torrent_list[] = ["filename" => $ffe, "size" => $ll, "torrent_id" => &$this->id];
$this->torrent_list[] = ['filename' => $ffe, 'size' => $ll, 'torrent_id' => &$this->id];
}
$this->torrent_type = "multi";
$this->torrent_type = 'multi';
}
}
} catch (ParseErrorException $e) {
Expand All @@ -125,8 +126,24 @@ public function makePrivateTorrent()
// Some other change if you need
//$this->torrent_dict['commit'] = "";

// The following line requires uploader to re-download torrents after uploading **Since info_hash change**
// even the torrent is set as private and with uploader's passkey in it.
/**
* The following line requires uploader to re-download torrents after uploading **Since info_hash change**
* even the torrent is set as private and with uploader's passkey in it.
*/

// Clean The `info` dict
$allowed_keys = [
'files', 'name', 'piece length', 'pieces', 'private', 'length',
'name.utf8', 'name.utf-8', 'md5sum', 'sha1', 'source',
'file-duration', 'file-media', 'profiles'
];
foreach ($this->torrent_dict['info'] as $key => $value) {
if (!in_array($key, $allowed_keys)) {
unset($this->torrent_dict['info'][$key]);
}
}

// Make it private and unique by add our source flag
$this->torrent_dict['info']['private'] = 1; // add private tracker flag
$this->torrent_dict['info']['source'] = "Powered by [" . app()->config->get("base.site_url") . "] " . app()->config->get("base.site_name");

Expand Down

0 comments on commit 1901e17

Please sign in to comment.