Rework album/tag downloads #19

Merged
Roflin merged 6 commits from tag-download into master 2020-03-11 20:04:31 +01:00
Showing only changes of commit bd1ca8d18c - Show all commits

View File

@ -22,7 +22,7 @@ class Download
$album = Tag::fromId($tag); $album = Tag::fromId($tag);
if (isset($_SESSION['current_export'])) if (isset($_SESSION['current_export']))
Review

Ik zie deze check, maar ik zie niet waar deze session variable geset word? Of mis ik iets.

Ik zie deze check, maar ik zie niet waar deze session variable geset word? Of mis ik iets.
Review

Oef, terecht. Ik vermoed dat ik die ben verloren in een overijverige rebase. Gaan we fixen.

Oef, terecht. Ik vermoed dat ik die ben verloren in een overijverige rebase. Gaan we fixen.
throw new UserFacingException('An export of "' . $tag->tag . '" is ongoing. Please try again later.'); throw new UserFacingException('You can only export one album at the same time. Please wait until the other download finishes, or try again later.');
// So far so good? // So far so good?
$this->exportAlbum($album); $this->exportAlbum($album);
@ -46,6 +46,15 @@ class Download
1 => ['pipe', 'w'], // STDOUT 1 => ['pipe', 'w'], // STDOUT
]; ];
// Prevent simultaneous exports.
$_SESSION['current_export'] = $album->id_tag;
// Allow new exports if the connection is terminated unexpectedly (e.g. when a user aborts a download).
register_shutdown_function(function() {
if (isset($_SESSION['current_export']))
unset($_SESSION['current_export']);
});
$command = 'tar -cf - -C ' . escapeshellarg(ASSETSDIR) . ' --null -T -'; $command = 'tar -cf - -C ' . escapeshellarg(ASSETSDIR) . ' --null -T -';
$proc = proc_open($command, $descriptorspec, $pipes, ASSETSDIR); $proc = proc_open($command, $descriptorspec, $pipes, ASSETSDIR);
@ -92,6 +101,9 @@ class Download
fclose($pipes[1]); fclose($pipes[1]);
proc_close($proc); proc_close($proc);
// Allow new exports from this point onward.
unset($_SESSION['current_export']);
} }
private function getChildAlbumIds($parent_id) private function getChildAlbumIds($parent_id)