mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 18:48:21 -07:00
Fix issues related to file list display and torrent registration (#1028)
Bencoding libraries properties changed in the new version
This commit is contained in:
parent
5005474b1a
commit
5d872e3555
4 changed files with 24 additions and 19 deletions
|
@ -132,7 +132,7 @@ $peer_hash = hash('xxh128', $passkey . $info_hash_hex . $port);
|
|||
// Events
|
||||
$stopped = ($event === 'stopped');
|
||||
|
||||
// Get the real port to help NAT users
|
||||
// Get the real port to help some NAT users
|
||||
$port = $_SERVER['REMOTE_PORT'];
|
||||
|
||||
// Set seeder & complete
|
||||
|
|
|
@ -32,14 +32,12 @@ if (!file_exists($filename) || !$file_contents = file_get_contents($filename)) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents)) {
|
||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
|
||||
return $lang['TORFILE_INVALID'];
|
||||
}
|
||||
|
||||
$torrent = new TorrentPier\Legacy\TorrentFileList($tor);
|
||||
if (($tor['info']['meta version'] ?? null) == 2) {
|
||||
$tor_filelist = $torrent->fileTreeList($tor['info']['file tree'], $tor['info']['name'] ?? ''); // v2
|
||||
} else {
|
||||
$tor_filelist = $torrent->get_filelist(); // v1
|
||||
}
|
||||
|
||||
$tor_filelist = $torrent->get_filelist();
|
||||
|
||||
$this->response['html'] = $tor_filelist;
|
||||
|
|
|
@ -316,7 +316,7 @@ class Torrent
|
|||
if (!is_file($filename) || !file_exists($filename)) {
|
||||
self::torrent_error_exit($lang['ERROR_NO_ATTACHMENT']);
|
||||
}
|
||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents)) {
|
||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
|
||||
self::torrent_error_exit($lang['TORFILE_INVALID']);
|
||||
}
|
||||
|
||||
|
@ -348,26 +348,27 @@ class Torrent
|
|||
}
|
||||
|
||||
// Check if torrent contains info_hash v2 or v1
|
||||
$bt_v1 = $bt_v2 = false;
|
||||
if (($info['meta version'] ?? null) == 2 && is_array($info['file tree'] ?? null)) {
|
||||
$bt_v2 = true;
|
||||
if (($info['meta version'] ?? null) == 2 ) {
|
||||
if (is_array($info['file tree'] ?? null)) {
|
||||
$bt_v2 = true;
|
||||
}
|
||||
}
|
||||
if (isset($info['pieces'])) {
|
||||
$bt_v1 = true;
|
||||
}
|
||||
if ($bb_cfg['tracker']['disabled_v2_torrents'] && $bt_v2 && !$bt_v1) {
|
||||
if ($bb_cfg['tracker']['disabled_v2_torrents'] && isset($bt_v2) && !isset($bt_v1)) {
|
||||
self::torrent_error_exit('v2-only torrents were disabled, allowed: v1 and hybrids');
|
||||
}
|
||||
|
||||
// Getting info_hash v1
|
||||
if ($bt_v1) {
|
||||
if (isset($bt_v1)) {
|
||||
$info_hash = pack('H*', hash('sha1', \Arokettu\Bencode\Bencode::encode($info)));
|
||||
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
||||
$info_hash_where = "WHERE info_hash = '$info_hash_sql'";
|
||||
}
|
||||
|
||||
// Getting info_hash v2
|
||||
if ($bt_v2) {
|
||||
if (isset($bt_v2)) {
|
||||
$v2_hash = hash('sha256', \Arokettu\Bencode\Bencode::encode($info));
|
||||
$info_hash_v2 = pack('H*', $v2_hash);
|
||||
$info_hash_v2_sql = rtrim(DB()->escape($info_hash_v2), ' ');
|
||||
|
@ -386,17 +387,18 @@ class Torrent
|
|||
}
|
||||
|
||||
$totallen = 0;
|
||||
|
||||
if (isset($info['length'])) {
|
||||
$totallen = (float)$info['length'];
|
||||
} elseif ($bt_v1 && isset($info['files']) && \is_array($info['files'])) {
|
||||
} elseif (isset($bt_v1) && isset($info['files']) && \is_array($info['files'])) {
|
||||
foreach ($info['files'] as $fn => $f) {
|
||||
// Exclude padding files
|
||||
if (($f['attr'] ?? null) !== 'p') {
|
||||
$totallen += (float)$f['length'];
|
||||
}
|
||||
}
|
||||
} elseif ($bt_v2) {
|
||||
$fileTreeSize = function ($array, string $name = '') use (&$fileTreeSize) {
|
||||
} elseif (isset($bt_v2)) {
|
||||
$fileTreeSize = function (array $array, string $name = '') use (&$fileTreeSize) {
|
||||
$size = 0;
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
|
@ -543,7 +545,7 @@ class Torrent
|
|||
$ann_url = $bb_cfg['bt_announce_url'];
|
||||
|
||||
$file_contents = file_get_contents($filename);
|
||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents)) {
|
||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
|
||||
bb_die($lang['TORFILE_INVALID']);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,11 @@ class TorrentFileList
|
|||
public function get_filelist()
|
||||
{
|
||||
global $html;
|
||||
if (($this->tor_decoded['info']['meta version'] ?? null) == 2) {
|
||||
if (is_array($this->tor_decoded['info']['file tree'] ?? null)) {
|
||||
return $this->fileTreeList($this->tor_decoded['info']['file tree']); //v2
|
||||
}
|
||||
}
|
||||
|
||||
$this->build_filelist_array();
|
||||
|
||||
|
@ -132,7 +137,7 @@ class TorrentFileList
|
|||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function fileTreeList($array, string $name = ''): string
|
||||
public function fileTreeList(array $array, string $name = ''): string
|
||||
{
|
||||
$folders = [];
|
||||
$rootFiles = [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue