diff --git a/library/includes/file_list_v2.php b/library/includes/file_list_v2.php
new file mode 100644
index 000000000..ac37807bb
--- /dev/null
+++ b/library/includes/file_list_v2.php
@@ -0,0 +1,87 @@
+fetch_row($sql);
+
+if (empty($row) || empty($row['physical_filename'])) {
+ http_response_code(404);
+ die('Topic id is missing');
+}
+
+if (empty($row['info_hash_v2'])) {
+ http_response_code(404);
+ die('Currently v2 torrents support file list displaying');
+}
+
+$file_contents = file_get_contents(get_attachments_dir() . '/' . $row['physical_filename']);
+
+if (!$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY)) {
+ return $lang['TORFILE_INVALID'];
+}
+
+$torrent = new TorrentPier\Legacy\TorrentFileList($tor);
+$file_list = $torrent->fileTreeTable($tor['info']['file tree']);
+
+$date = '';
+$name = $tor['info']['name'] ?? '';
+if (isset($tor['creation date']) && is_numeric($tor['creation date'])) {
+ $date = date("d M Y | G:i:s T", $tor['creation date']);
+}
+$size = humn_size($file_list['size']);
+
+echo "
+
+
+
+
+
+
+File list — $name ($size)
+
+
+
+
+Document name: $name | Date: ($date) | Size: $size
+
+Location | Size | BTMR hash ? |
";
+
+echo implode('', $file_list['list']);
+
+echo '
+
+
+';
+
+die();
diff --git a/src/Legacy/TorrentFileList.php b/src/Legacy/TorrentFileList.php
index 648022cfe..fcb58a5f8 100644
--- a/src/Legacy/TorrentFileList.php
+++ b/src/Legacy/TorrentFileList.php
@@ -169,7 +169,7 @@ class TorrentFileList
public function fileTreeTable(array $array, string $parent = ''): array
{
$filesList = [];
-
+ $size = 0;
foreach ($array as $key => $value) {
$key = htmlCHR($key);
$current = "$parent/$key";
@@ -178,10 +178,14 @@ class TorrentFileList
} else {
$length = (int)$value['']['length'];
$root = bin2hex($value['']['pieces root'] ?? '');
+ $size += $length;
$filesList[] = '' . $current . ' | ' . humn_size($length, 2) . ' | ' . $root . ' |
';
}
}
- return $filesList;
+ return [
+ 'list' => $filesList,
+ 'size' => $size
+ ];
}
}
diff --git a/styles/templates/default/viewtopic_attach.tpl b/styles/templates/default/viewtopic_attach.tpl
index 2de55bc1a..eb8727174 100644
--- a/styles/templates/default/viewtopic_attach.tpl
+++ b/styles/templates/default/viewtopic_attach.tpl
@@ -168,6 +168,9 @@
{postrow.attach.tor_reged.FILESIZE}
+
+ ...
+
diff --git a/viewtopic.php b/viewtopic.php
index 8a9d9daa9..4d9d5ce5d 100644
--- a/viewtopic.php
+++ b/viewtopic.php
@@ -24,6 +24,7 @@ $page_cfg['load_tpl_vars'] = [
];
$newest = $next_topic_id = 0;
+$file_list = isset($_GET['filelist']) ? include(INC_DIR . '/file_list_v2.php') : 0;
$start = isset($_GET['start']) ? abs((int)$_GET['start']) : 0;
$topic_id = isset($_GET[POST_TOPIC_URL]) ? (int)$_GET[POST_TOPIC_URL] : 0;
$post_id = (!$topic_id && isset($_GET[POST_POST_URL])) ? (int)$_GET[POST_POST_URL] : 0;