mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 05:43:55 -07:00
Some code improvements for file listing (#1068)
This commit is contained in:
parent
b12c8e4d4b
commit
f59cfe848d
2 changed files with 27 additions and 14 deletions
|
@ -4,6 +4,8 @@ if (!defined('BB_ROOT')) {
|
||||||
die(basename(__FILE__));
|
die(basename(__FILE__));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$user->session_start();
|
||||||
|
|
||||||
$topic_id = (int)$_GET['t'];
|
$topic_id = (int)$_GET['t'];
|
||||||
|
|
||||||
$sql = 'SELECT t.attach_id, t.info_hash_v2, ad.physical_filename
|
$sql = 'SELECT t.attach_id, t.info_hash_v2, ad.physical_filename
|
||||||
|
@ -17,30 +19,39 @@ $row = DB()->fetch_row($sql);
|
||||||
|
|
||||||
if (empty($row) || empty($row['physical_filename'])) {
|
if (empty($row) || empty($row['physical_filename'])) {
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
die('Valid topic id is missing');
|
die($lang['TOPIC_POST_NOT_EXIST']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($row['info_hash_v2'])) {
|
if (empty($row['info_hash_v2'])) {
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
die('Currently v2 torrents support file list displaying');
|
die('Currently torrents with BitTorrent v2 support are enabled for file listing');
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_contents = file_get_contents(get_attachments_dir() . '/' . $row['physical_filename']);
|
$file_path = get_attachments_dir() . '/' . $row['physical_filename'];
|
||||||
|
|
||||||
|
if(!is_file($file_path)){
|
||||||
|
die($lang['INVALID_ATTACH_ID']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_contents = file_get_contents($file_path);
|
||||||
|
|
||||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
|
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
|
||||||
return $lang['TORFILE_INVALID'];
|
die($lang['TORFILE_INVALID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$torrent = new TorrentPier\Legacy\TorrentFileList($tor);
|
$torrent = new TorrentPier\Legacy\TorrentFileList($tor);
|
||||||
$file_list = $torrent->fileTreeTable($tor['info']['file tree']);
|
$file_list = $torrent->fileTreeTable($tor['info']['file tree']);
|
||||||
|
|
||||||
$date = '';
|
$data = [
|
||||||
$name = htmlCHR($tor['info']['name'] ?? '');
|
'date' => '',
|
||||||
$client = htmlCHR(substr($tor['created by'] ?? 'unknown client', 0, 20));
|
'name' => htmlCHR($tor['info']['name'] ?? ''),
|
||||||
|
'client' => htmlCHR(substr($tor['created by'] ?? 'unknown client', 0, 20)),
|
||||||
|
'size' => humn_size($file_list['size'])
|
||||||
|
];
|
||||||
|
|
||||||
if (isset($tor['creation date']) && is_numeric($tor['creation date'])) {
|
if (isset($tor['creation date']) && is_numeric($tor['creation date'])) {
|
||||||
$date = date("d M Y | G:i:s T", $tor['creation date']);
|
$data['date'] = date("d M Y | G:i:s T", $tor['creation date']);
|
||||||
}
|
}
|
||||||
$size = humn_size($file_list['size']);
|
|
||||||
|
|
||||||
echo "<html>
|
echo "<html>
|
||||||
<head>
|
<head>
|
||||||
|
@ -48,7 +59,7 @@ echo "<html>
|
||||||
<meta name=\"robots\" content=\"index, follow\">
|
<meta name=\"robots\" content=\"index, follow\">
|
||||||
<meta name=\"description\" content=\"File list for topic - $topic_id\">
|
<meta name=\"description\" content=\"File list for topic - $topic_id\">
|
||||||
|
|
||||||
<title>File list — $name ($size)</title>
|
<title>File list — {$data['name']} ({$data['size']})</title>
|
||||||
</head>
|
</head>
|
||||||
<body style=\"background-color: #1f1f1f; color: #ffffff;\">
|
<body style=\"background-color: #1f1f1f; color: #ffffff;\">
|
||||||
<style>
|
<style>
|
||||||
|
@ -85,9 +96,9 @@ echo "<html>
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<center>
|
<center>
|
||||||
<h2 style = \"color: #b3b3b3;font-family: Monospace\">Document name: $name | Date: ($date) | Size: $size
|
<h2 style = \"color: #b3b3b3;font-family: Monospace\">Document name: {$data['name']} | Date: ({$data['date']}) | Size: {$data['size']}
|
||||||
</h2>
|
</h2>
|
||||||
<p><i>Created by: $client</i></p>
|
<p><i>Created by: {$data['client']}</i></p>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<table><tr><th>Path</th><th>Size</th><th title=\"BitTorrent Merkle Root — The hash of the file, which is embedded in torrents with BitTorrent v2 support, tracker users can extract, calculate them, also deduplicate torrents using desktop tools such as Torrent Merkle Root Reader.\">Hash <sup>?</sup></th></tr>";
|
<table><tr><th>Path</th><th>Size</th><th title=\"BitTorrent Merkle Root — The hash of the file, which is embedded in torrents with BitTorrent v2 support, tracker users can extract, calculate them, also deduplicate torrents using desktop tools such as Torrent Merkle Root Reader.\">Hash <sup>?</sup></th></tr>";
|
||||||
|
|
|
@ -311,11 +311,13 @@ class Torrent
|
||||||
self::torrent_auth_check($forum_id, $torrent['poster_id']);
|
self::torrent_auth_check($forum_id, $torrent['poster_id']);
|
||||||
|
|
||||||
$filename = get_attachments_dir() . '/' . $torrent['physical_filename'];
|
$filename = get_attachments_dir() . '/' . $torrent['physical_filename'];
|
||||||
$file_contents = file_get_contents($filename);
|
|
||||||
|
|
||||||
if (!is_file($filename) || !file_exists($filename)) {
|
if (!is_file($filename)) {
|
||||||
self::torrent_error_exit($lang['ERROR_NO_ATTACHMENT']);
|
self::torrent_error_exit($lang['ERROR_NO_ATTACHMENT']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$file_contents = file_get_contents($filename);
|
||||||
|
|
||||||
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
|
if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
|
||||||
self::torrent_error_exit($lang['TORFILE_INVALID']);
|
self::torrent_error_exit($lang['TORFILE_INVALID']);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue