From 79a156f6030be811ca581b770062edbfa44a7b7f Mon Sep 17 00:00:00 2001 From: clandestine8 Date: Sun, 29 Mar 2020 01:41:01 -0400 Subject: [PATCH 1/5] add: missingTorrentFiles.CSV When Downloading All torrents, if torrent file is missing it will output into a CSV container in the Zip File. --- app/Http/Controllers/UserController.php | 37 ++++++++++++++----------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 445730ff4c..7dd0292d0a 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -1993,6 +1993,7 @@ public function downloadHistoryTorrents(Request $request, $username) if ($zip->open($path.'/'.$zipFileName, ZipArchive::CREATE) === true) { // Match History Results To Torrents + $failCSV = "\"Name\",\"URL\",\"ID\",\"info_hash\"\r\n"; foreach ($historyTorrents as $historyTorrent) { // Get Torrent $torrent = Torrent::withAnyStatus()->where('info_hash', '=', $historyTorrent)->first(); @@ -2002,26 +2003,30 @@ public function downloadHistoryTorrents(Request $request, $username) // The Torrent File Exist? if (!file_exists(getcwd().'/files/torrents/'.$torrent->file_name)) { - return redirect()->back()->withErrors('Torrent File Not Found! Please Report This Torrent!'); - } - // Delete The Last Torrent Tmp File If Exist - if (file_exists(getcwd().'/files/tmp/'.$tmpFileName)) { - unlink(getcwd().'/files/tmp/'.$tmpFileName); - } + $failCSV .= "\"".$torrent->name . "\",\"". route('torrent', ['id' => $torrent->id]) . "\",\"" . $torrent->id . "\",\"" . $historyTorrent ."\"\r\n" ; + } else { + // Delete The Last Torrent Tmp File If Exist + if (file_exists(getcwd() . '/files/tmp/' . $tmpFileName)) { + unlink(getcwd() . '/files/tmp/' . $tmpFileName); + } - // Get The Content Of The Torrent - $dict = Bencode::bdecode(file_get_contents(getcwd().'/files/torrents/'.$torrent->file_name)); - // Set the announce key and add the user passkey - $dict['announce'] = route('announce', ['passkey' => $user->passkey]); - // Remove Other announce url - unset($dict['announce-list']); + // Get The Content Of The Torrent + $dict = Bencode::bdecode(file_get_contents(getcwd() . '/files/torrents/' . $torrent->file_name)); + // Set the announce key and add the user passkey + $dict['announce'] = route('announce', ['passkey' => $user->passkey]); + // Remove Other announce url + unset($dict['announce-list']); - $fileToDownload = Bencode::bencode($dict); - file_put_contents(getcwd().'/files/tmp/'.$tmpFileName, $fileToDownload); + $fileToDownload = Bencode::bencode($dict); + file_put_contents(getcwd() . '/files/tmp/' . $tmpFileName, $fileToDownload); - // Add Files To ZipArchive - $zip->addFile(getcwd().'/files/tmp/'.$tmpFileName, $tmpFileName); + // Add Files To ZipArchive + $zip->addFile(getcwd() . '/files/tmp/' . $tmpFileName, $tmpFileName); + } } + $CSVtmpName = sprintf('%s.zip', $user->username).'-missingTorrentFiles.CSV'; + file_put_contents(getcwd().'/files/tmp/'.$CSVtmpName, $failCSV); + $zip->addFile(getcwd().'/files/tmp/'.$CSVtmpName, 'missingTorrentFiles.CSV'); // Close ZipArchive $zip->close(); } From 94d5fa338734075121dec0ad7031e2ffa0cba340 Mon Sep 17 00:00:00 2001 From: clandestine8 Date: Tue, 7 Apr 2020 15:52:42 -0400 Subject: [PATCH 2/5] (fix) Add ext-zip to composer.json --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0aacbc65ff..e10525b079 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ "spatie/ssl-certificate": "^1.12", "symfony/dom-crawler": "^2.7|^3.0", "theodorejb/polycast": "^1.0", - "voku/anti-xss": "^4.1" + "voku/anti-xss": "^4.1", + "ext-zip": "*" }, "require-dev": { "facade/ignition": "^1.4", From b57b005a5ef186e70211a13cc43f19a5554c2e08 Mon Sep 17 00:00:00 2001 From: clandestine8 Date: Tue, 7 Apr 2020 15:59:39 -0400 Subject: [PATCH 3/5] (fix) StyleCI - Remove escaped characters & Spaces in Strings --- app/Http/Controllers/UserController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 7dd0292d0a..cf8ec45022 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -2003,25 +2003,25 @@ public function downloadHistoryTorrents(Request $request, $username) // The Torrent File Exist? if (!file_exists(getcwd().'/files/torrents/'.$torrent->file_name)) { - $failCSV .= "\"".$torrent->name . "\",\"". route('torrent', ['id' => $torrent->id]) . "\",\"" . $torrent->id . "\",\"" . $historyTorrent ."\"\r\n" ; + $failCSV .= '"'.$torrent->name.'","'.route('torrent', ['id' => $torrent->id]).'","'.$torrent->id.'","'.$historyTorrent."\"\r\n"; } else { // Delete The Last Torrent Tmp File If Exist - if (file_exists(getcwd() . '/files/tmp/' . $tmpFileName)) { - unlink(getcwd() . '/files/tmp/' . $tmpFileName); + if (file_exists(getcwd().'/files/tmp/'.$tmpFileName)) { + unlink(getcwd().'/files/tmp/'.$tmpFileName); } // Get The Content Of The Torrent - $dict = Bencode::bdecode(file_get_contents(getcwd() . '/files/torrents/' . $torrent->file_name)); + $dict = Bencode::bdecode(file_get_contents(getcwd().'/files/torrents/'.$torrent->file_name)); // Set the announce key and add the user passkey $dict['announce'] = route('announce', ['passkey' => $user->passkey]); // Remove Other announce url unset($dict['announce-list']); $fileToDownload = Bencode::bencode($dict); - file_put_contents(getcwd() . '/files/tmp/' . $tmpFileName, $fileToDownload); + file_put_contents(getcwd().'/files/tmp/'.$tmpFileName, $fileToDownload); // Add Files To ZipArchive - $zip->addFile(getcwd() . '/files/tmp/' . $tmpFileName, $tmpFileName); + $zip->addFile(getcwd().'/files/tmp/'.$tmpFileName, $tmpFileName); } } $CSVtmpName = sprintf('%s.zip', $user->username).'-missingTorrentFiles.CSV'; From e2ce7b2fb9e85e021764cd09662cc79812469bf1 Mon Sep 17 00:00:00 2001 From: clandestine8 Date: Tue, 7 Apr 2020 16:03:37 -0400 Subject: [PATCH 4/5] (fix) Only add CSV file if Failed Torrent Count is greater than 0 --- app/Http/Controllers/UserController.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index cf8ec45022..95ec1dbf7d 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -1994,6 +1994,7 @@ public function downloadHistoryTorrents(Request $request, $username) if ($zip->open($path.'/'.$zipFileName, ZipArchive::CREATE) === true) { // Match History Results To Torrents $failCSV = "\"Name\",\"URL\",\"ID\",\"info_hash\"\r\n"; + $failCount = 0; foreach ($historyTorrents as $historyTorrent) { // Get Torrent $torrent = Torrent::withAnyStatus()->where('info_hash', '=', $historyTorrent)->first(); @@ -2004,6 +2005,7 @@ public function downloadHistoryTorrents(Request $request, $username) // The Torrent File Exist? if (!file_exists(getcwd().'/files/torrents/'.$torrent->file_name)) { $failCSV .= '"'.$torrent->name.'","'.route('torrent', ['id' => $torrent->id]).'","'.$torrent->id.'","'.$historyTorrent."\"\r\n"; + $failCount++; } else { // Delete The Last Torrent Tmp File If Exist if (file_exists(getcwd().'/files/tmp/'.$tmpFileName)) { @@ -2024,9 +2026,11 @@ public function downloadHistoryTorrents(Request $request, $username) $zip->addFile(getcwd().'/files/tmp/'.$tmpFileName, $tmpFileName); } } - $CSVtmpName = sprintf('%s.zip', $user->username).'-missingTorrentFiles.CSV'; - file_put_contents(getcwd().'/files/tmp/'.$CSVtmpName, $failCSV); - $zip->addFile(getcwd().'/files/tmp/'.$CSVtmpName, 'missingTorrentFiles.CSV'); + if ($failCount > 0) { + $CSVtmpName = sprintf('%s.zip', $user->username) . '-missingTorrentFiles.CSV'; + file_put_contents(getcwd() . '/files/tmp/' . $CSVtmpName, $failCSV); + $zip->addFile(getcwd() . '/files/tmp/' . $CSVtmpName, 'missingTorrentFiles.CSV'); + } // Close ZipArchive $zip->close(); } From 5013223ced49a3306c23cf0a36d254811514928a Mon Sep 17 00:00:00 2001 From: clandestine8 Date: Tue, 7 Apr 2020 16:07:20 -0400 Subject: [PATCH 5/5] (fix) StyleCI - Remove Spaces in Strings --- app/Http/Controllers/UserController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 95ec1dbf7d..7690d94fe1 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -2027,9 +2027,9 @@ public function downloadHistoryTorrents(Request $request, $username) } } if ($failCount > 0) { - $CSVtmpName = sprintf('%s.zip', $user->username) . '-missingTorrentFiles.CSV'; - file_put_contents(getcwd() . '/files/tmp/' . $CSVtmpName, $failCSV); - $zip->addFile(getcwd() . '/files/tmp/' . $CSVtmpName, 'missingTorrentFiles.CSV'); + $CSVtmpName = sprintf('%s.zip', $user->username).'-missingTorrentFiles.CSV'; + file_put_contents(getcwd().'/files/tmp/'.$CSVtmpName, $failCSV); + $zip->addFile(getcwd().'/files/tmp/'.$CSVtmpName, 'missingTorrentFiles.CSV'); } // Close ZipArchive $zip->close();