* album export
This commit is contained in:
parent
71253ff1ac
commit
5b04f5e222
@ -29,3 +29,4 @@
|
|||||||
$app->get('/', App\Action\HomePageAction::class, 'home');
|
$app->get('/', App\Action\HomePageAction::class, 'home');
|
||||||
$app->get('/api/galleries', App\Action\ListGalleriesAction::class, 'api.galleries');
|
$app->get('/api/galleries', App\Action\ListGalleriesAction::class, 'api.galleries');
|
||||||
$app->get('/image/{slug}/{image}[/{thumb}]', App\Action\GetImageAction::class, 'download.image');
|
$app->get('/image/{slug}/{image}[/{thumb}]', App\Action\GetImageAction::class, 'download.image');
|
||||||
|
$app->get('/export-album/{slug}', App\Action\ExportAlbumAction::class, 'export.album');
|
||||||
|
|||||||
@ -8,8 +8,9 @@ set('ssh_multiplexing', true);
|
|||||||
|
|
||||||
set('repository', 'https://gogs.ragnarok.yvan.hu/yvan/gallery-api.git');
|
set('repository', 'https://gogs.ragnarok.yvan.hu/yvan/gallery-api.git');
|
||||||
set('shared_dirs', [
|
set('shared_dirs', [
|
||||||
// 'vendor',
|
'data/export',
|
||||||
'data/galleries',
|
'data/galleries',
|
||||||
|
'data/tmp',
|
||||||
]);
|
]);
|
||||||
set('shared_files', [
|
set('shared_files', [
|
||||||
'config/autoload/doctrine.local.php',
|
'config/autoload/doctrine.local.php',
|
||||||
|
|||||||
1
public/export
Symbolic link
1
public/export
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../data/export
|
||||||
27
src/App/Action/ExportAlbumAction.php
Normal file
27
src/App/Action/ExportAlbumAction.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Action;
|
||||||
|
|
||||||
|
use App\Service\GalleryService;
|
||||||
|
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||||
|
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Zend\Diactoros\Response;
|
||||||
|
|
||||||
|
class ExportAlbumAction implements ServerMiddlewareInterface
|
||||||
|
{
|
||||||
|
private $galleryService;
|
||||||
|
|
||||||
|
public function __construct(GalleryService $galleryService)
|
||||||
|
{
|
||||||
|
$this->galleryService = $galleryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||||
|
{
|
||||||
|
$slug = $request->getAttribute('slug', false);
|
||||||
|
$this->galleryService->getExportFileName($slug);
|
||||||
|
return new Response\RedirectResponse("/export/{$slug}.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
src/App/Action/ExportAlbumFactory.php
Normal file
15
src/App/Action/ExportAlbumFactory.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Action;
|
||||||
|
|
||||||
|
use App\Service\GalleryService;
|
||||||
|
use Interop\Container\ContainerInterface;
|
||||||
|
|
||||||
|
class ExportAlbumFactory
|
||||||
|
{
|
||||||
|
public function __invoke(ContainerInterface $container)
|
||||||
|
{
|
||||||
|
$galleryService = $container->get(GalleryService::class);
|
||||||
|
return new ExportAlbumAction($galleryService);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -44,6 +44,7 @@ class ConfigProvider
|
|||||||
|
|
||||||
Action\ListGalleriesAction::class => Action\ListGalleriesFactory::class,
|
Action\ListGalleriesAction::class => Action\ListGalleriesFactory::class,
|
||||||
Action\GetImageAction::class => Action\GetImageFactory::class,
|
Action\GetImageAction::class => Action\GetImageFactory::class,
|
||||||
|
Action\ExportAlbumAction::class => Action\ExportAlbumFactory::class,
|
||||||
|
|
||||||
Service\GalleryService::class => Service\GalleryServiceFactory::class,
|
Service\GalleryService::class => Service\GalleryServiceFactory::class,
|
||||||
],
|
],
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
|
|
||||||
use App\Entity\Image;
|
use App\Entity\Image;
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
use Imagine\Gd\Imagine;
|
use Imagine\Gd\Imagine;
|
||||||
@ -17,6 +16,7 @@ class GalleryService
|
|||||||
|
|
||||||
const CONFIG_FILE = 'data/galleries/config.yaml';
|
const CONFIG_FILE = 'data/galleries/config.yaml';
|
||||||
const IMAGE_BASEDIR = 'data/galleries/%s/';
|
const IMAGE_BASEDIR = 'data/galleries/%s/';
|
||||||
|
const EXPORT_DIR = 'data/export/';
|
||||||
const THUMBNAIL_SIZE = 500;
|
const THUMBNAIL_SIZE = 500;
|
||||||
|
|
||||||
protected $contentTypeMap = [
|
protected $contentTypeMap = [
|
||||||
@ -36,25 +36,38 @@ class GalleryService
|
|||||||
$this->em = $entityManager;
|
$this->em = $entityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function exportGallery(string $slug)
|
public function getExportFileName(string $slug)
|
||||||
{
|
{
|
||||||
$config = $this->getConfig();
|
$config = $this->getConfig();
|
||||||
|
|
||||||
if (!isset($config['galleries'][$slug])) {
|
if (!isset($config['galleries'][$slug])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dir = $config['galleries'][$slug]['dir'];
|
$dir = $config['galleries'][$slug]['dir'];
|
||||||
$images = array_map('basename', glob(sprintf(self::IMAGE_BASEDIR . "*.{jpg,jpeg,png}", $dir), GLOB_BRACE));
|
return $this->ensureExportFileExists($dir, "{$slug}.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
private function ensureExportFileExists(string $dir, string $filename)
|
||||||
|
{
|
||||||
|
$exportName = self::EXPORT_DIR . $filename;
|
||||||
|
if(file_exists($exportName)) {
|
||||||
|
return $exportName;
|
||||||
|
}
|
||||||
|
|
||||||
|
$images = array_map('basename', glob($this->getImageDir($dir) . "*.{jpg,jpeg,png}", GLOB_BRACE));
|
||||||
|
|
||||||
$zipName = tempnam("data/tmp", "export");
|
$zipName = tempnam("data/tmp", "export");
|
||||||
$zipArchive = new \ZipArchive();
|
$zipArchive = new \ZipArchive();
|
||||||
$zipArchive->open($zipName, \ZipArchive::CREATE);
|
$zipArchive->open($zipName, \ZipArchive::CREATE);
|
||||||
foreach ($images as $image) {
|
foreach ($images as $image) {
|
||||||
$zipArchive->addFile("{$dir}/{$image}");
|
ini_set("max_execution_time", 60);
|
||||||
|
$zipArchive->addFile(
|
||||||
|
sprintf(self::IMAGE_BASEDIR,$dir) . $image,
|
||||||
|
"{$dir}/{$image}"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$zipArchive->close();
|
$zipArchive->close();
|
||||||
return $zipName;
|
rename($zipName, $exportName);
|
||||||
|
return $exportName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadGalleryData($includeHidden = false)
|
public function loadGalleryData($includeHidden = false)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user