Skip to content

Commit

Permalink
Merge pull request #1254 from clandestine8/missing-torrentfile-list
Browse files Browse the repository at this point in the history
(Add) missingTorrentFiles.CSV
  • Loading branch information
HDVinnie authored Apr 10, 2020
2 parents 7decf27 + 5013223 commit 11bf696
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
41 changes: 25 additions & 16 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,8 @@ 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();
Expand All @@ -2002,25 +2004,32 @@ 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";
$failCount++;
} 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);
}
}
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();
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 11bf696

Please sign in to comment.