Skip to content

Commit

Permalink
Add photo directory parameter as env var + Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
bierdok committed Mar 17, 2019
1 parent e845b65 commit ed74356
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ APP_SECRET=4295372718d2cd82a396041d99adf191
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS='^localhost|example\.com$'
###< symfony/framework-bundle ###

APP_PHOTO_DIR=/photos
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<h3 align="center"><img width="80" src="public/android-chrome-256x256.png"><br>pixapop</h3>
<h1 align="center"><img width="80" src="public/android-chrome-256x256.png" alt="Pixapop"></h1>

**pixapop** is a free and open-source single page application built with [Symfony](https://symfony.com/) and [VueJS](https://vuejs.org/) to view your photos in the easiest way possible.
# Pixapop

[![License](https://poser.pugx.org/bierdok/pixapop/license?format=flat-square)](https://opensource.org/licenses/MIT)
[![Latest Stable Version](https://poser.pugx.org/bierdok/pixapop/v/stable.svg?format=flat-square)](https://packagist.org/packages/bierdok/pixapop)

**pixapop** is an open-source single page application built with [Symfony](https://symfony.com/) and [VueJS](https://vuejs.org/) to view your photos in the easiest way possible.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "bierdok/pixapop",
"type": "project",
"license": "MIT",
"require": {
Expand Down Expand Up @@ -45,7 +46,8 @@
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
"assets:install %PUBLIC_DIR%": "symfony-cmd",
"app:create-symlink": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
Expand Down
2 changes: 1 addition & 1 deletion config/packages/liip_imagine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ liip_imagine:
loaders:
photos:
filesystem:
data_root: "/photos"
data_root: '%env(APP_PHOTO_DIR)%'
6 changes: 6 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ services:

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

App\Command\CreateSymlinkCommand:
calls:
- method: setProjectDir
arguments:
- '%kernel.project_dir%'
32 changes: 32 additions & 0 deletions src/Command/CreateSymlinkCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

class CreateSymlinkCommand extends Command
{
protected static $defaultName = 'app:create-symlink';

/**
* @var string
*/
private $projectDir;

/**
* @param string $projectDir
*/
public function setProjectDir(string $projectDir): void
{
$this->projectDir = $projectDir;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$fileSystem = new Filesystem();
$fileSystem->symlink(getenv('APP_PHOTO_DIR'), $this->projectDir . '/public/photos');
}
}
18 changes: 8 additions & 10 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

class DefaultController extends Controller
{
const DIR = '/photos';

/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
Expand All @@ -24,32 +22,32 @@ public function index(Request $request)
$fileSystem = new Filesystem();
$finder = new Finder();

if (!$fileSystem->exists(self::DIR)) {
if (!$fileSystem->exists(getenv('APP_PHOTO_DIR'))) {
throw new BadRequestHttpException('Non-existent directory');
}

$pixapop = [];
$galleries = [];
/** @var File $file */
foreach ($finder->files()->in(self::DIR)->depth(0) as $x => $file) {
foreach ($finder->files()->in(getenv('APP_PHOTO_DIR'))->depth(0) as $x => $file) {
if (!$data = @exif_read_data($file->getRealPath())) {
continue;
}
$time = new \DateTime($data['DateTimeOriginal']);
$pixapop[$time->format('Y-m')][$time->getTimestamp() . $x] = [
$galleries[$time->format('Y-m')][$time->getTimestamp() . $x] = [
'name' => $file->getFilename(),
'time' => $time->getTimestamp(),
'size' => $file->getSize()
];
}
krsort($pixapop);
foreach ($pixapop as $month => &$gallery) {
krsort($galleries);
foreach ($galleries as $month => &$gallery) {
krsort($gallery);
$gallery = array_values($gallery);
}

return $this->render('index.html.twig', [
'locale' => substr($request->getPreferredLanguage(), 0, 2),
'pixapop' => $pixapop
'pixapop' => $galleries
]);
}

Expand All @@ -62,7 +60,7 @@ public function index(Request $request)
public function preview(int $width, int $height, string $name)
{
$finder = new Finder();
$finder->files()->in(self::DIR)->depth(0)->name($name);
$finder->files()->in(getenv('APP_PHOTO_DIR'))->depth(0)->name($name);

foreach ($finder as $file) {
if (!$data = @exif_read_data($file->getRealPath())) {
Expand Down

0 comments on commit ed74356

Please sign in to comment.