Rework album/tag downloads #19
@ -6,7 +6,7 @@
|
||||
* Kabuki CMS (C) 2013-2019, Aaron van Geffen
|
||||
*****************************************************************************/
|
||||
|
||||
class Download extends HTMLController
|
||||
class Download
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
@ -16,37 +16,17 @@ class Download extends HTMLController
|
||||
throw new NotAllowedException();
|
||||
|
||||
if (!isset($_GET['tag']))
|
||||
throw new UnexpectedValueException('Must specify an album to download');
|
||||
throw new UserFacingException('No album or tag has been specified for download.');
|
||||
|
||||
$tag = (int)$_GET['tag'];
|
||||
$album = Tag::fromId($tag);
|
||||
|
||||
if($album->kind !== 'Album')
|
||||
throw new UnexpectedValueException('Specified tag does not correspond to an album');
|
||||
|
||||
//Yes TOCTOU but it does not need to be perfect.
|
||||
$lock_file = join('/', [sys_get_temp_dir(), 'pics-export.lock']);
|
||||
if(!file_exists($lock_file))
|
||||
{
|
||||
try
|
||||
{
|
||||
$fp = fopen($lock_file, 'x');
|
||||
|
||||
if(!$fp)
|
||||
throw new UnexpectedValueException('Could not open lock-file');
|
||||
if (isset($_SESSION['current_export']))
|
||||
|
||||
throw new UserFacingException('An export of "' . $tag->tag . '" is ongoing. Please try again later.');
|
||||
|
||||
// So far so good?
|
||||
$this->exportAlbum($album);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fclose($fp);
|
||||
unlink($lock_file);
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new UnexpectedValueException('Another export is busy, please try again later');
|
||||
|
||||
exit();
|
||||
exit;
|
||||
}
|
||||
|
||||
private function exportAlbum($album)
|
||||
|
Loading…
Reference in New Issue
Block a user
Ik zie deze check, maar ik zie niet waar deze session variable geset word? Of mis ik iets.
Oef, terecht. Ik vermoed dat ik die ben verloren in een overijverige rebase. Gaan we fixen.