Moved public data to public_html/

This is going to improve caching.
This commit is contained in:
Marcin Kurczewski 2014-09-17 14:32:26 +02:00
parent 55f4f4430b
commit 15eb2342b9
18 changed files with 58 additions and 34 deletions

2
data/.gitignore vendored
View file

@ -1,5 +1,3 @@
db.sqlite db.sqlite
executed_upgrades.txt executed_upgrades.txt
local.ini local.ini
thumbnails
posts

View file

@ -2,7 +2,17 @@ DirectoryIndex app.min.html
DirectoryIndex index.html DirectoryIndex index.html
RewriteEngine On RewriteEngine On
RewriteRule ^/?api/(.*) api-dispatch.php?q=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?data/posts/([^/]+)/? /api/posts/$1/content [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?data/thumbnails/(\d+)x(\d+)/posts/([^/]+)/? /api/posts/$3/thumbnail/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?data/thumbnails/(\d+)x(\d+)/avatars/([^/]+)/? /api/users/$3/avatar/$1 [L]
RewriteRule ^/?api/(.*) api-dispatch.php?q=$0 [QSA,L]
<IfModule mod_mime.c> <IfModule mod_mime.c>
AddType text/html .tpl AddType text/html .tpl

View file

@ -2,5 +2,6 @@
$start = microtime(true); $start = microtime(true);
require_once(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'AutoLoader.php'); require_once(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'AutoLoader.php');
$httpHelper = \Szurubooru\Injector::get(\Szurubooru\Helpers\HttpHelper::class);
$dispatcher = \Szurubooru\Injector::get(\Szurubooru\Dispatcher::class); $dispatcher = \Szurubooru\Injector::get(\Szurubooru\Dispatcher::class);
$dispatcher->run(); $dispatcher->run($httpHelper->getRequestMethod(), $_GET['q']);

2
public_html/data/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
posts
thumbnails

View file

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View file

@ -1,6 +1,6 @@
<li class="user"> <li class="user">
<a href="#/user/<%= user.name %>"> <a href="#/user/<%= user.name %>">
<img src="/api/users/<%= user.name %>/avatar/80" alt="<%= user.name %>"/> <img src="/data/thumbnails/80x80/avatars/<%= user.name %>" alt="<%= user.name %>"/>
</a> </a>
<div class="details"> <div class="details">
<h1> <h1>

View file

@ -3,7 +3,7 @@
<div class="top"> <div class="top">
<div class="side"> <div class="side">
<img src="/api/users/<%= user.name %>/avatar/100" alt="Avatar"/> <img src="/data/thumbnails/100x100/avatars/<%= user.name %>" alt="Avatar"/>
<br/> <br/>
<%= user.name %> <%= user.name %>
</div> </div>

View file

@ -4,11 +4,13 @@ namespace Szurubooru;
class Config extends \ArrayObject class Config extends \ArrayObject
{ {
private $dataDirectory; private $dataDirectory;
private $publicDataDirectory;
public function __construct($dataDirectory) public function __construct($dataDirectory, $publicDataDirectory)
{ {
$this->setFlags($this->getArrayObjectFlags()); $this->setFlags($this->getArrayObjectFlags());
$this->dataDirectory = $dataDirectory; $this->dataDirectory = $dataDirectory;
$this->publicDataDirectory = $publicDataDirectory;
$this->tryLoadFromIni([ $this->tryLoadFromIni([
$dataDirectory . DIRECTORY_SEPARATOR . 'config.ini', $dataDirectory . DIRECTORY_SEPARATOR . 'config.ini',
$dataDirectory . DIRECTORY_SEPARATOR . 'local.ini']); $dataDirectory . DIRECTORY_SEPARATOR . 'local.ini']);
@ -31,6 +33,11 @@ class Config extends \ArrayObject
return $this->dataDirectory; return $this->dataDirectory;
} }
public function getPublicDataDirectory()
{
return $this->publicDataDirectory;
}
public function offsetGet($index) public function offsetGet($index)
{ {
if (!parent::offsetExists($index)) if (!parent::offsetExists($index))

View file

@ -26,16 +26,14 @@ final class Dispatcher
$controller->registerRoutes($router); $controller->registerRoutes($router);
} }
public function run() public function run($requestMethod, $requestUri)
{ {
global $start; global $start;
try try
{ {
$code = 200; $code = 200;
$this->authorizeFromRequestHeader(); $this->authorizeFromRequestHeader();
$json = (array) $this->router->handle( $json = (array) $this->router->handle($requestMethod, $requestUri);
$this->httpHelper->getRequestMethod(),
$this->httpHelper->getRequestUri());
} }
catch (\Exception $e) catch (\Exception $e)
{ {

View file

@ -8,7 +8,7 @@ class FileService
public function __construct(\Szurubooru\Config $config, \Szurubooru\Helpers\HttpHelper $httpHelper) public function __construct(\Szurubooru\Config $config, \Szurubooru\Helpers\HttpHelper $httpHelper)
{ {
$this->dataDirectory = $config->getDataDirectory(); $this->dataDirectory = $config->getPublicDataDirectory();
$this->httpHelper = $httpHelper; $this->httpHelper = $httpHelper;
} }

View file

@ -1,8 +1,15 @@
<?php <?php
$dataDirectory = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data'; $dataDirectory = __DIR__
. DIRECTORY_SEPARATOR . '..'
. DIRECTORY_SEPARATOR . 'data';
$publicDataDirectory = __DIR__
. DIRECTORY_SEPARATOR . '..'
. DIRECTORY_SEPARATOR . 'public_html'
. DIRECTORY_SEPARATOR . 'data';
return [ return [
\Szurubooru\Config::class => DI\object()->constructor($dataDirectory), \Szurubooru\Config::class => DI\object()->constructor($dataDirectory, $publicDataDirectory),
\Szurubooru\ControllerRepository::class => DI\object()->constructor(DI\link('controllers')), \Szurubooru\ControllerRepository::class => DI\object()->constructor(DI\link('controllers')),
\Szurubooru\Upgrades\UpgradeRepository::class => DI\object()->constructor(DI\link('upgrades')), \Szurubooru\Upgrades\UpgradeRepository::class => DI\object()->constructor(DI\link('upgrades')),

View file

@ -8,9 +8,9 @@ abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
return $this->getMockBuilder($className)->disableOriginalConstructor()->getMock(); return $this->getMockBuilder($className)->disableOriginalConstructor()->getMock();
} }
public function mockConfig($path = null) public function mockConfig($dataPath = null, $publicDataPath = null)
{ {
return new ConfigMock($path); return new ConfigMock($dataPath, $publicDataPath);
} }
public function mockTransactionManager() public function mockTransactionManager()

View file

@ -18,21 +18,21 @@ final class ConfigTest extends \Szurubooru\Tests\AbstractTestCase
public function testReadingNonSections() public function testReadingNonSections()
{ {
file_put_contents($this->baseConfigFilePath, 'test=value'); file_put_contents($this->baseConfigFilePath, 'test=value');
$config = new \Szurubooru\Config($this->testDirectory); $config = $this->getTestConfig();
$this->assertEquals('value', $config->test); $this->assertEquals('value', $config->test);
} }
public function testReadingUnnestedSections() public function testReadingUnnestedSections()
{ {
file_put_contents($this->baseConfigFilePath, '[test]' . PHP_EOL . 'key=value'); file_put_contents($this->baseConfigFilePath, '[test]' . PHP_EOL . 'key=value');
$config = new \Szurubooru\Config($this->testDirectory); $config = $this->getTestConfig();
$this->assertEquals('value', $config->test->key); $this->assertEquals('value', $config->test->key);
} }
public function testReadingNestedSections() public function testReadingNestedSections()
{ {
file_put_contents($this->baseConfigFilePath, '[test.subtest]' . PHP_EOL . 'key=value'); file_put_contents($this->baseConfigFilePath, '[test.subtest]' . PHP_EOL . 'key=value');
$config = new \Szurubooru\Config($this->testDirectory); $config = $this->getTestConfig();
$this->assertEquals('value', $config->test->subtest->key); $this->assertEquals('value', $config->test->subtest->key);
} }
@ -42,14 +42,14 @@ final class ConfigTest extends \Szurubooru\Tests\AbstractTestCase
$this->baseConfigFilePath, $this->baseConfigFilePath,
'[test.subtest]' . PHP_EOL . 'key=value' . PHP_EOL . '[test.subtest]' . PHP_EOL . 'key=value' . PHP_EOL .
'[test.subtest.deeptest]' . PHP_EOL . 'key=zombie'); '[test.subtest.deeptest]' . PHP_EOL . 'key=zombie');
$config = new \Szurubooru\Config($this->testDirectory); $config = $this->getTestConfig();
$this->assertEquals('value', $config->test->subtest->key); $this->assertEquals('value', $config->test->subtest->key);
$this->assertEquals('zombie', $config->test->subtest->deeptest->key); $this->assertEquals('zombie', $config->test->subtest->deeptest->key);
} }
public function testReadingNonExistentFiles() public function testReadingNonExistentFiles()
{ {
$config = new \Szurubooru\Config($this->testDirectory); $config = $this->getTestConfig();
$this->assertEquals(0, count(iterator_to_array($config->getIterator()))); $this->assertEquals(0, count(iterator_to_array($config->getIterator())));
} }
@ -57,22 +57,27 @@ final class ConfigTest extends \Szurubooru\Tests\AbstractTestCase
{ {
file_put_contents($this->baseConfigFilePath, 'test=trash'); file_put_contents($this->baseConfigFilePath, 'test=trash');
file_put_contents($this->localConfigFilePath, 'test=overridden'); file_put_contents($this->localConfigFilePath, 'test=overridden');
$config = new \Szurubooru\Config($this->testDirectory); $config = $this->getTestConfig();
$this->assertEquals('overridden', $config->test); $this->assertEquals('overridden', $config->test);
} }
public function testReadingUnexistingProperties() public function testReadingUnexistingProperties()
{ {
file_put_contents($this->baseConfigFilePath, 'meh=value'); file_put_contents($this->baseConfigFilePath, 'meh=value');
$config = new \Szurubooru\Config($this->testDirectory); $config = $this->getTestConfig();
$this->assertNull($config->unexistingSection); $this->assertNull($config->unexistingSection);
} }
public function testOverwritingValues() public function testOverwritingValues()
{ {
file_put_contents($this->baseConfigFilePath, 'meh=value'); file_put_contents($this->baseConfigFilePath, 'meh=value');
$config = new \Szurubooru\Config($this->testDirectory); $config = $this->getTestConfig();
$config->newKey = 'fast'; $config->newKey = 'fast';
$this->assertEquals('fast', $config->newKey); $this->assertEquals('fast', $config->newKey);
} }
private function getTestConfig()
{
return new \Szurubooru\Config($this->testDirectory, null);
}
} }

View file

@ -31,7 +31,7 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractTestCase
$this->controllerRepositoryMock->method('getControllers')->willReturn([]); $this->controllerRepositoryMock->method('getControllers')->willReturn([]);
$dispatcher = $this->getDispatcher(); $dispatcher = $this->getDispatcher();
$actual = $dispatcher->run(); $actual = $dispatcher->run('GET', '/');
unset($actual['__time']); unset($actual['__time']);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
@ -47,7 +47,7 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractTestCase
$this->controllerRepositoryMock->method('getControllers')->willReturn([]); $this->controllerRepositoryMock->method('getControllers')->willReturn([]);
$dispatcher = $this->getDispatcher(); $dispatcher = $this->getDispatcher();
$actual = $dispatcher->run(); $actual = $dispatcher->run('GET', '/');
unset($actual['__time']); unset($actual['__time']);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
@ -60,7 +60,7 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractTestCase
$this->controllerRepositoryMock->method('getControllers')->willReturn([]); $this->controllerRepositoryMock->method('getControllers')->willReturn([]);
$dispatcher = $this->getDispatcher(); $dispatcher = $this->getDispatcher();
$dispatcher->run(); $dispatcher->run('GET', '/');
} }
private function getDispatcher() private function getDispatcher()

View file

@ -18,11 +18,7 @@ class PrivilegeTest extends \Szurubooru\Tests\AbstractTestCase
$refl = new \ReflectionClass(\Szurubooru\Privilege::class); $refl = new \ReflectionClass(\Szurubooru\Privilege::class);
$constants = array_values($refl->getConstants()); $constants = array_values($refl->getConstants());
$dataPath = __DIR__ $config = \Szurubooru\Injector::get(\Szurubooru\Config::class);
. DIRECTORY_SEPARATOR . '..'
. DIRECTORY_SEPARATOR . 'data';
$config = new \Szurubooru\Config($dataPath);
foreach ($config->security->privileges as $key => $value) foreach ($config->security->privileges as $key => $value)
{ {
$this->assertTrue(in_array($key, $constants), "$key not in constants"); $this->assertTrue(in_array($key, $constants), "$key not in constants");

View file

@ -6,7 +6,7 @@ class FileServiceTest extends \Szurubooru\Tests\AbstractTestCase
public function testSaving() public function testSaving()
{ {
$testDirectory = $this->createTestDirectory(); $testDirectory = $this->createTestDirectory();
$configMock = $this->mockConfig($testDirectory); $configMock = $this->mockConfig(null, $testDirectory);
$httpHelper = $this->mock(\Szurubooru\Helpers\HttpHelper::class); $httpHelper = $this->mock(\Szurubooru\Helpers\HttpHelper::class);
$fileService = new \Szurubooru\Services\FileService($configMock, $httpHelper); $fileService = new \Szurubooru\Services\FileService($configMock, $httpHelper);
$fileService->save('dog.txt', 'awesome dog'); $fileService->save('dog.txt', 'awesome dog');

View file

@ -15,7 +15,7 @@ class ThumbnailServiceTest extends \Szurubooru\Tests\AbstractTestCase
touch($tempDirectory . DS . 'thumbnails' . DS . '5x5' . DS . 'keep'); touch($tempDirectory . DS . 'thumbnails' . DS . '5x5' . DS . 'keep');
touch($tempDirectory . DS . 'thumbnails' . DS . '10x10' . DS . 'remove'); touch($tempDirectory . DS . 'thumbnails' . DS . '10x10' . DS . 'remove');
$configMock = $this->mockConfig($tempDirectory); $configMock = $this->mockConfig(null, $tempDirectory);
$httpHelperMock = $this->mock(\Szurubooru\Helpers\HttpHelper::class); $httpHelperMock = $this->mock(\Szurubooru\Helpers\HttpHelper::class);
$fileService = new \Szurubooru\Services\FileService($configMock, $httpHelperMock); $fileService = new \Szurubooru\Services\FileService($configMock, $httpHelperMock);
$thumbnailGeneratorMock = $this->mock(\Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator::class); $thumbnailGeneratorMock = $this->mock(\Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator::class);