diff --git a/filelist.php b/filelist.php index 0b10895c6..58d7e7c92 100644 --- a/filelist.php +++ b/filelist.php @@ -31,14 +31,16 @@ $sql = 'SELECT t.attach_id, t.info_hash, t.info_hash_v2, t.size, ad.physical_fil $row = DB()->fetch_row($sql); -if (empty($row) || empty($row['physical_filename'])) { +if (empty($row['physical_filename'])) { bb_simple_die($lang['INVALID_TOPIC_ID_DB'], 404); } // Method fields -$t_version_field = !empty($row['info_hash_v2']) ? 'v2' : 'v1'; -$t_files_field = ($t_version_field === 'v2') ? 'getFileTree' : 'getFiles'; -$t_hash_field = ($t_version_field === 'v2') ? 'piecesRoot' : 'sha1'; +$meta_v1 = !empty($row['info_hash']); +$meta_v2 = !empty($row['info_hash_v2']); +$t_version_field = $meta_v2 ? 'v2' : 'v1'; +$t_files_field = $meta_v2 ? 'getFileTree' : 'getFiles'; +$t_hash_field = $meta_v2 ? 'piecesRoot' : 'sha1'; $file_path = get_attachments_dir() . '/' . $row['physical_filename']; @@ -76,6 +78,10 @@ if (IS_GUEST && $torrent->isPrivate()) { $files = $torrent->$t_version_field()->$t_files_field(); +if ($meta_v1 && $meta_v2) { + $files = new \RecursiveIteratorIterator($files); // Flatten the list +} + $allFiles = ''; foreach ($files as $file) { $allFiles .= '