Moved public data to public_html/
This is going to improve caching.
This commit is contained in:
parent
55f4f4430b
commit
15eb2342b9
18 changed files with 58 additions and 34 deletions
2
data/.gitignore
vendored
2
data/.gitignore
vendored
|
@ -1,5 +1,3 @@
|
|||
db.sqlite
|
||||
executed_upgrades.txt
|
||||
local.ini
|
||||
thumbnails
|
||||
posts
|
||||
|
|
|
@ -2,7 +2,17 @@ DirectoryIndex app.min.html
|
|||
DirectoryIndex index.html
|
||||
|
||||
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>
|
||||
AddType text/html .tpl
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
$start = microtime(true);
|
||||
|
||||
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->run();
|
||||
$dispatcher->run($httpHelper->getRequestMethod(), $_GET['q']);
|
||||
|
|
2
public_html/data/.gitignore
vendored
Normal file
2
public_html/data/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
posts
|
||||
thumbnails
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
|
@ -1,6 +1,6 @@
|
|||
<li class="user">
|
||||
<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>
|
||||
<div class="details">
|
||||
<h1>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<div class="top">
|
||||
<div class="side">
|
||||
<img src="/api/users/<%= user.name %>/avatar/100" alt="Avatar"/>
|
||||
<img src="/data/thumbnails/100x100/avatars/<%= user.name %>" alt="Avatar"/>
|
||||
<br/>
|
||||
<%= user.name %>
|
||||
</div>
|
||||
|
|
|
@ -4,11 +4,13 @@ namespace Szurubooru;
|
|||
class Config extends \ArrayObject
|
||||
{
|
||||
private $dataDirectory;
|
||||
private $publicDataDirectory;
|
||||
|
||||
public function __construct($dataDirectory)
|
||||
public function __construct($dataDirectory, $publicDataDirectory)
|
||||
{
|
||||
$this->setFlags($this->getArrayObjectFlags());
|
||||
$this->dataDirectory = $dataDirectory;
|
||||
$this->publicDataDirectory = $publicDataDirectory;
|
||||
$this->tryLoadFromIni([
|
||||
$dataDirectory . DIRECTORY_SEPARATOR . 'config.ini',
|
||||
$dataDirectory . DIRECTORY_SEPARATOR . 'local.ini']);
|
||||
|
@ -31,6 +33,11 @@ class Config extends \ArrayObject
|
|||
return $this->dataDirectory;
|
||||
}
|
||||
|
||||
public function getPublicDataDirectory()
|
||||
{
|
||||
return $this->publicDataDirectory;
|
||||
}
|
||||
|
||||
public function offsetGet($index)
|
||||
{
|
||||
if (!parent::offsetExists($index))
|
||||
|
|
|
@ -26,16 +26,14 @@ final class Dispatcher
|
|||
$controller->registerRoutes($router);
|
||||
}
|
||||
|
||||
public function run()
|
||||
public function run($requestMethod, $requestUri)
|
||||
{
|
||||
global $start;
|
||||
try
|
||||
{
|
||||
$code = 200;
|
||||
$this->authorizeFromRequestHeader();
|
||||
$json = (array) $this->router->handle(
|
||||
$this->httpHelper->getRequestMethod(),
|
||||
$this->httpHelper->getRequestUri());
|
||||
$json = (array) $this->router->handle($requestMethod, $requestUri);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@ class FileService
|
|||
|
||||
public function __construct(\Szurubooru\Config $config, \Szurubooru\Helpers\HttpHelper $httpHelper)
|
||||
{
|
||||
$this->dataDirectory = $config->getDataDirectory();
|
||||
$this->dataDirectory = $config->getPublicDataDirectory();
|
||||
$this->httpHelper = $httpHelper;
|
||||
}
|
||||
|
||||
|
|
11
src/di.php
11
src/di.php
|
@ -1,8 +1,15 @@
|
|||
<?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 [
|
||||
\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\Upgrades\UpgradeRepository::class => DI\object()->constructor(DI\link('upgrades')),
|
||||
|
|
|
@ -8,9 +8,9 @@ abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
|
|||
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()
|
||||
|
|
|
@ -18,21 +18,21 @@ final class ConfigTest extends \Szurubooru\Tests\AbstractTestCase
|
|||
public function testReadingNonSections()
|
||||
{
|
||||
file_put_contents($this->baseConfigFilePath, 'test=value');
|
||||
$config = new \Szurubooru\Config($this->testDirectory);
|
||||
$config = $this->getTestConfig();
|
||||
$this->assertEquals('value', $config->test);
|
||||
}
|
||||
|
||||
public function testReadingUnnestedSections()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public function testReadingNestedSections()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -42,14 +42,14 @@ final class ConfigTest extends \Szurubooru\Tests\AbstractTestCase
|
|||
$this->baseConfigFilePath,
|
||||
'[test.subtest]' . PHP_EOL . 'key=value' . PHP_EOL .
|
||||
'[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('zombie', $config->test->subtest->deeptest->key);
|
||||
}
|
||||
|
||||
public function testReadingNonExistentFiles()
|
||||
{
|
||||
$config = new \Szurubooru\Config($this->testDirectory);
|
||||
$config = $this->getTestConfig();
|
||||
$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->localConfigFilePath, 'test=overridden');
|
||||
$config = new \Szurubooru\Config($this->testDirectory);
|
||||
$config = $this->getTestConfig();
|
||||
$this->assertEquals('overridden', $config->test);
|
||||
}
|
||||
|
||||
public function testReadingUnexistingProperties()
|
||||
{
|
||||
file_put_contents($this->baseConfigFilePath, 'meh=value');
|
||||
$config = new \Szurubooru\Config($this->testDirectory);
|
||||
$config = $this->getTestConfig();
|
||||
$this->assertNull($config->unexistingSection);
|
||||
}
|
||||
|
||||
public function testOverwritingValues()
|
||||
{
|
||||
file_put_contents($this->baseConfigFilePath, 'meh=value');
|
||||
$config = new \Szurubooru\Config($this->testDirectory);
|
||||
$config = $this->getTestConfig();
|
||||
$config->newKey = 'fast';
|
||||
$this->assertEquals('fast', $config->newKey);
|
||||
}
|
||||
|
||||
private function getTestConfig()
|
||||
{
|
||||
return new \Szurubooru\Config($this->testDirectory, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractTestCase
|
|||
$this->controllerRepositoryMock->method('getControllers')->willReturn([]);
|
||||
|
||||
$dispatcher = $this->getDispatcher();
|
||||
$actual = $dispatcher->run();
|
||||
$actual = $dispatcher->run('GET', '/');
|
||||
|
||||
unset($actual['__time']);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
@ -47,7 +47,7 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractTestCase
|
|||
$this->controllerRepositoryMock->method('getControllers')->willReturn([]);
|
||||
|
||||
$dispatcher = $this->getDispatcher();
|
||||
$actual = $dispatcher->run();
|
||||
$actual = $dispatcher->run('GET', '/');
|
||||
|
||||
unset($actual['__time']);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
@ -60,7 +60,7 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractTestCase
|
|||
$this->controllerRepositoryMock->method('getControllers')->willReturn([]);
|
||||
|
||||
$dispatcher = $this->getDispatcher();
|
||||
$dispatcher->run();
|
||||
$dispatcher->run('GET', '/');
|
||||
}
|
||||
|
||||
private function getDispatcher()
|
||||
|
|
|
@ -18,11 +18,7 @@ class PrivilegeTest extends \Szurubooru\Tests\AbstractTestCase
|
|||
$refl = new \ReflectionClass(\Szurubooru\Privilege::class);
|
||||
$constants = array_values($refl->getConstants());
|
||||
|
||||
$dataPath = __DIR__
|
||||
. DIRECTORY_SEPARATOR . '..'
|
||||
. DIRECTORY_SEPARATOR . 'data';
|
||||
|
||||
$config = new \Szurubooru\Config($dataPath);
|
||||
$config = \Szurubooru\Injector::get(\Szurubooru\Config::class);
|
||||
foreach ($config->security->privileges as $key => $value)
|
||||
{
|
||||
$this->assertTrue(in_array($key, $constants), "$key not in constants");
|
||||
|
|
|
@ -6,7 +6,7 @@ class FileServiceTest extends \Szurubooru\Tests\AbstractTestCase
|
|||
public function testSaving()
|
||||
{
|
||||
$testDirectory = $this->createTestDirectory();
|
||||
$configMock = $this->mockConfig($testDirectory);
|
||||
$configMock = $this->mockConfig(null, $testDirectory);
|
||||
$httpHelper = $this->mock(\Szurubooru\Helpers\HttpHelper::class);
|
||||
$fileService = new \Szurubooru\Services\FileService($configMock, $httpHelper);
|
||||
$fileService->save('dog.txt', 'awesome dog');
|
||||
|
|
|
@ -15,7 +15,7 @@ class ThumbnailServiceTest extends \Szurubooru\Tests\AbstractTestCase
|
|||
touch($tempDirectory . DS . 'thumbnails' . DS . '5x5' . DS . 'keep');
|
||||
touch($tempDirectory . DS . 'thumbnails' . DS . '10x10' . DS . 'remove');
|
||||
|
||||
$configMock = $this->mockConfig($tempDirectory);
|
||||
$configMock = $this->mockConfig(null, $tempDirectory);
|
||||
$httpHelperMock = $this->mock(\Szurubooru\Helpers\HttpHelper::class);
|
||||
$fileService = new \Szurubooru\Services\FileService($configMock, $httpHelperMock);
|
||||
$thumbnailGeneratorMock = $this->mock(\Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator::class);
|
||||
|
|
Loading…
Reference in a new issue