* cors and other basic changes

This commit is contained in:
Danyi Dávid 2017-08-09 15:47:05 +02:00
parent 05519c20ba
commit 5b0d883558
11 changed files with 341 additions and 188 deletions

View File

@ -8,7 +8,7 @@
"sort-packages": true
},
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.1",
"imagine/imagine": "^0.7.1",
"roave/security-advisories": "dev-master",
"symfony/yaml": "*",
@ -51,7 +51,7 @@
"clear-config-cache": "php bin/clear-config-cache.php",
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"serve": "php -S 0.0.0.0:8080 -t public public/index.php",
"serve": "php -S 0.0.0.0:8888 -t public public/index.php",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"upload-coverage": "coveralls -v"

202
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "d4b6d9c19a66c89becd4c23986ac7a06",
"content-hash": "1f20b08976c04bb5ad210675c9abd33e",
"packages": [
{
"name": "container-interop/container-interop",
@ -345,12 +345,12 @@
"source": {
"type": "git",
"url": "https://github.com/Roave/SecurityAdvisories.git",
"reference": "fa53c38b02d1ec883f4ea2b2c05492da0c7611cf"
"reference": "9df1a9e73fc7caa573adaf98d159623048a7feed"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/fa53c38b02d1ec883f4ea2b2c05492da0c7611cf",
"reference": "fa53c38b02d1ec883f4ea2b2c05492da0c7611cf",
"url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/9df1a9e73fc7caa573adaf98d159623048a7feed",
"reference": "9df1a9e73fc7caa573adaf98d159623048a7feed",
"shasum": ""
},
"conflict": {
@ -396,7 +396,7 @@
"onelogin/php-saml": "<2.10.4",
"oro/crm": ">=1.7,<1.7.4",
"oro/platform": ">=1.7,<1.7.4",
"phpmailer/phpmailer": ">=5,<5.2.22",
"phpmailer/phpmailer": ">=5,<5.2.24",
"pusher/pusher-php-server": "<2.2.1",
"sabre/dav": ">=1.6,<1.6.99|>=1.7,<1.7.11|>=1.8,<1.8.9",
"shopware/shopware": "<4.4|>=5,<5.2.16",
@ -405,7 +405,7 @@
"silverstripe/framework": ">=3,<3.3",
"silverstripe/userforms": "<3",
"simplesamlphp/saml2": "<1.8.1|>=1.9,<1.9.1|>=1.10,<1.10.3|>=2,<2.3.3",
"simplesamlphp/simplesamlphp": "<1.14.12",
"simplesamlphp/simplesamlphp": "<1.14.15",
"simplesamlphp/simplesamlphp-module-infocard": "<1.0.1",
"socalnick/scn-social-auth": "<1.15.2",
"squizlabs/php_codesniffer": ">=1,<2.8.1",
@ -474,20 +474,20 @@
}
],
"description": "Prevents installation of composer packages with known security vulnerabilities: no API, simply require it",
"time": "2017-07-18T08:09:10+00:00"
"time": "2017-08-08T18:44:50+00:00"
},
{
"name": "symfony/yaml",
"version": "v3.3.5",
"version": "v3.3.6",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "1f93a8d19b8241617f5074a123e282575b821df8"
"reference": "ddc23324e6cfe066f3dd34a37ff494fa80b617ed"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/1f93a8d19b8241617f5074a123e282575b821df8",
"reference": "1f93a8d19b8241617f5074a123e282575b821df8",
"url": "https://api.github.com/repos/symfony/yaml/zipball/ddc23324e6cfe066f3dd34a37ff494fa80b617ed",
"reference": "ddc23324e6cfe066f3dd34a37ff494fa80b617ed",
"shasum": ""
},
"require": {
@ -529,7 +529,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2017-06-15T12:58:50+00:00"
"time": "2017-07-23T12:43:26+00:00"
},
{
"name": "zendframework/zend-component-installer",
@ -1243,32 +1243,32 @@
"packages-dev": [
{
"name": "doctrine/instantiator",
"version": "1.0.5",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
"reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda",
"reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda",
"shasum": ""
},
"require": {
"php": ">=5.3,<8.0-DEV"
"php": "^7.1"
},
"require-dev": {
"athletic/athletic": "~0.1.8",
"ext-pdo": "*",
"ext-phar": "*",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~2.0"
"phpunit/phpunit": "^6.2.3",
"squizlabs/php_codesniffer": "^3.0.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.2.x-dev"
}
},
"autoload": {
@ -1293,20 +1293,20 @@
"constructor",
"instantiate"
],
"time": "2015-06-14T21:17:01+00:00"
"time": "2017-07-22T11:58:36+00:00"
},
{
"name": "filp/whoops",
"version": "2.1.9",
"version": "2.1.10",
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
"reference": "b238974e1c7cc1859b0c16ddc1c02ecb70ecc07f"
"reference": "ffbbd2c06c64b08fb47974eed5dbce4ca2bb0eec"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/filp/whoops/zipball/b238974e1c7cc1859b0c16ddc1c02ecb70ecc07f",
"reference": "b238974e1c7cc1859b0c16ddc1c02ecb70ecc07f",
"url": "https://api.github.com/repos/filp/whoops/zipball/ffbbd2c06c64b08fb47974eed5dbce4ca2bb0eec",
"reference": "ffbbd2c06c64b08fb47974eed5dbce4ca2bb0eec",
"shasum": ""
},
"require": {
@ -1354,7 +1354,7 @@
"whoops",
"zf2"
],
"time": "2017-06-03T18:33:07+00:00"
"time": "2017-08-03T18:23:40+00:00"
},
{
"name": "myclabs/deep-copy",
@ -1556,22 +1556,22 @@
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "3.2.0",
"version": "3.2.2",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "46f7e8bb075036c92695b15a1ddb6971c751e585"
"reference": "4aada1f93c72c35e22fb1383b47fee43b8f1d157"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/46f7e8bb075036c92695b15a1ddb6971c751e585",
"reference": "46f7e8bb075036c92695b15a1ddb6971c751e585",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/4aada1f93c72c35e22fb1383b47fee43b8f1d157",
"reference": "4aada1f93c72c35e22fb1383b47fee43b8f1d157",
"shasum": ""
},
"require": {
"php": ">=5.5",
"phpdocumentor/reflection-common": "^1.0@dev",
"phpdocumentor/type-resolver": "^0.4.0",
"phpdocumentor/type-resolver": "^0.3.0",
"webmozart/assert": "^1.0"
},
"require-dev": {
@ -1597,20 +1597,20 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2017-07-15T11:38:20+00:00"
"time": "2017-08-08T06:39:58+00:00"
},
{
"name": "phpdocumentor/type-resolver",
"version": "0.4.0",
"version": "0.3.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "9c977708995954784726e25d0cd1dddf4e65b0f7"
"reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7",
"reference": "9c977708995954784726e25d0cd1dddf4e65b0f7",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fb3933512008d8162b3cdf9e18dba9309b7c3773",
"reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773",
"shasum": ""
},
"require": {
@ -1644,7 +1644,7 @@
"email": "me@mikevanriel.com"
}
],
"time": "2017-07-14T14:27:02+00:00"
"time": "2017-06-03T08:32:36+00:00"
},
{
"name": "phpspec/prophecy",
@ -1711,28 +1711,28 @@
},
{
"name": "phpunit/php-code-coverage",
"version": "5.2.1",
"version": "5.2.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "dc421f9ca5082a0c0cb04afb171c765f79add85b"
"reference": "8ed1902a57849e117b5651fc1a5c48110946c06b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/dc421f9ca5082a0c0cb04afb171c765f79add85b",
"reference": "dc421f9ca5082a0c0cb04afb171c765f79add85b",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/8ed1902a57849e117b5651fc1a5c48110946c06b",
"reference": "8ed1902a57849e117b5651fc1a5c48110946c06b",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-xmlwriter": "*",
"php": "^7.0",
"phpunit/php-file-iterator": "^1.3",
"phpunit/php-text-template": "^1.2",
"phpunit/php-file-iterator": "^1.4.2",
"phpunit/php-text-template": "^1.2.1",
"phpunit/php-token-stream": "^1.4.11 || ^2.0",
"sebastian/code-unit-reverse-lookup": "^1.0",
"sebastian/code-unit-reverse-lookup": "^1.0.1",
"sebastian/environment": "^3.0",
"sebastian/version": "^2.0",
"sebastian/version": "^2.0.1",
"theseer/tokenizer": "^1.1"
},
"require-dev": {
@ -1740,7 +1740,7 @@
"phpunit/phpunit": "^6.0"
},
"suggest": {
"ext-xdebug": "^2.5.3"
"ext-xdebug": "^2.5.5"
},
"type": "library",
"extra": {
@ -1771,7 +1771,7 @@
"testing",
"xunit"
],
"time": "2017-04-21T08:03:57+00:00"
"time": "2017-08-03T12:40:43+00:00"
},
{
"name": "phpunit/php-file-iterator",
@ -1912,29 +1912,29 @@
},
{
"name": "phpunit/php-token-stream",
"version": "1.4.11",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
"reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7"
"reference": "ecb0b2cdaa0add708fe6f329ef65ae0c5225130b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7",
"reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/ecb0b2cdaa0add708fe6f329ef65ae0c5225130b",
"reference": "ecb0b2cdaa0add708fe6f329ef65ae0c5225130b",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"php": ">=5.3.3"
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
"phpunit/phpunit": "^6.2.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
"dev-master": "2.0-dev"
}
},
"autoload": {
@ -1957,20 +1957,20 @@
"keywords": [
"tokenizer"
],
"time": "2017-02-27T10:12:30+00:00"
"time": "2017-08-03T14:17:41+00:00"
},
{
"name": "phpunit/phpunit",
"version": "6.2.3",
"version": "6.3.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "fa5711d0559fc4b64deba0702be52d41434cbcb7"
"reference": "9501bab711403a1ab5b8378a8adb4ec3db3debdb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fa5711d0559fc4b64deba0702be52d41434cbcb7",
"reference": "fa5711d0559fc4b64deba0702be52d41434cbcb7",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9501bab711403a1ab5b8378a8adb4ec3db3debdb",
"reference": "9501bab711403a1ab5b8378a8adb4ec3db3debdb",
"shasum": ""
},
"require": {
@ -1979,24 +1979,24 @@
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-xml": "*",
"myclabs/deep-copy": "^1.3",
"myclabs/deep-copy": "^1.6.1",
"phar-io/manifest": "^1.0.1",
"phar-io/version": "^1.0",
"php": "^7.0",
"phpspec/prophecy": "^1.7",
"phpunit/php-code-coverage": "^5.2",
"phpunit/php-file-iterator": "^1.4",
"phpunit/php-text-template": "^1.2",
"phpunit/php-timer": "^1.0.6",
"phpunit/phpunit-mock-objects": "^4.0",
"sebastian/comparator": "^2.0",
"sebastian/diff": "^1.4.3 || ^2.0",
"sebastian/environment": "^3.0.2",
"phpunit/php-code-coverage": "^5.2.2",
"phpunit/php-file-iterator": "^1.4.2",
"phpunit/php-text-template": "^1.2.1",
"phpunit/php-timer": "^1.0.9",
"phpunit/phpunit-mock-objects": "^4.0.3",
"sebastian/comparator": "^2.0.2",
"sebastian/diff": "^2.0",
"sebastian/environment": "^3.1",
"sebastian/exporter": "^3.1",
"sebastian/global-state": "^1.1 || ^2.0",
"sebastian/object-enumerator": "^3.0.2",
"sebastian/global-state": "^2.0",
"sebastian/object-enumerator": "^3.0.3",
"sebastian/resource-operations": "^1.0",
"sebastian/version": "^2.0"
"sebastian/version": "^2.0.1"
},
"conflict": {
"phpdocumentor/reflection-docblock": "3.0.2",
@ -2015,7 +2015,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.2.x-dev"
"dev-master": "6.3.x-dev"
}
},
"autoload": {
@ -2041,26 +2041,26 @@
"testing",
"xunit"
],
"time": "2017-07-03T15:54:24+00:00"
"time": "2017-08-04T05:20:39+00:00"
},
{
"name": "phpunit/phpunit-mock-objects",
"version": "4.0.2",
"version": "4.0.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "d8833b396dce9162bb2eb5d59aee5a3ab3cfa5b4"
"reference": "2f789b59ab89669015ad984afa350c4ec577ade0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/d8833b396dce9162bb2eb5d59aee5a3ab3cfa5b4",
"reference": "d8833b396dce9162bb2eb5d59aee5a3ab3cfa5b4",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/2f789b59ab89669015ad984afa350c4ec577ade0",
"reference": "2f789b59ab89669015ad984afa350c4ec577ade0",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.2",
"doctrine/instantiator": "^1.0.5",
"php": "^7.0",
"phpunit/php-text-template": "^1.2",
"phpunit/php-text-template": "^1.2.1",
"sebastian/exporter": "^3.0"
},
"conflict": {
@ -2100,7 +2100,7 @@
"mock",
"xunit"
],
"time": "2017-06-30T08:15:21+00:00"
"time": "2017-08-03T14:08:16+00:00"
},
{
"name": "psr/log",
@ -2196,21 +2196,21 @@
},
{
"name": "sebastian/comparator",
"version": "2.0.0",
"version": "2.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "20f84f468cb67efee293246e6a09619b891f55f0"
"reference": "ae068fede81d06e7bb9bb46a367210a3d3e1fe6a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/20f84f468cb67efee293246e6a09619b891f55f0",
"reference": "20f84f468cb67efee293246e6a09619b891f55f0",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/ae068fede81d06e7bb9bb46a367210a3d3e1fe6a",
"reference": "ae068fede81d06e7bb9bb46a367210a3d3e1fe6a",
"shasum": ""
},
"require": {
"php": "^7.0",
"sebastian/diff": "^1.2",
"sebastian/diff": "^2.0",
"sebastian/exporter": "^3.0"
},
"require-dev": {
@ -2256,32 +2256,32 @@
"compare",
"equality"
],
"time": "2017-03-03T06:26:08+00:00"
"time": "2017-08-03T07:14:59+00:00"
},
{
"name": "sebastian/diff",
"version": "1.4.3",
"version": "2.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
"reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4"
"reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4",
"reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/347c1d8b49c5c3ee30c7040ea6fc446790e6bddd",
"reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd",
"shasum": ""
},
"require": {
"php": "^5.3.3 || ^7.0"
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
"phpunit/phpunit": "^6.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
"dev-master": "2.0-dev"
}
},
"autoload": {
@ -2308,7 +2308,7 @@
"keywords": [
"diff"
],
"time": "2017-05-22T07:24:03+00:00"
"time": "2017-08-03T08:09:46+00:00"
},
{
"name": "sebastian/environment",
@ -2480,21 +2480,21 @@
},
{
"name": "sebastian/object-enumerator",
"version": "3.0.2",
"version": "3.0.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/object-enumerator.git",
"reference": "31dd3379d16446c5d86dec32ab1ad1f378581ad8"
"reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/31dd3379d16446c5d86dec32ab1ad1f378581ad8",
"reference": "31dd3379d16446c5d86dec32ab1ad1f378581ad8",
"url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5",
"reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5",
"shasum": ""
},
"require": {
"php": "^7.0",
"sebastian/object-reflector": "^1.0",
"sebastian/object-reflector": "^1.1.1",
"sebastian/recursion-context": "^3.0"
},
"require-dev": {
@ -2523,7 +2523,7 @@
],
"description": "Traverses array structures and object graphs to enumerate all referenced objects",
"homepage": "https://github.com/sebastianbergmann/object-enumerator/",
"time": "2017-03-12T15:17:29+00:00"
"time": "2017-08-03T12:35:26+00:00"
},
{
"name": "sebastian/object-reflector",
@ -2934,7 +2934,7 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^5.6 || ^7.0"
"php": "^7.1"
},
"platform-dev": []
}

View File

@ -14,6 +14,7 @@ use Zend\Stratigility\Middleware\ErrorHandler;
// The error handler should be the first (most outer) middleware to catch
// all Exceptions.
$app->pipe(ErrorHandler::class);
$app->pipe(App\Middleware\PreFlightMiddleware::class);
$app->pipe(ServerUrlMiddleware::class);
// Pipe more middleware here that you want to execute on every request:

View File

@ -29,4 +29,4 @@
$app->get('/', App\Action\HomePageAction::class, 'home');
$app->get('/api/galleries', App\Action\ListGalleriesAction::class, 'api.galleries');
$app->get('/api/gallery/{slug}', App\Action\GetGalleryImagesAction::class, 'api.gallery');
$app->get('/api/image/{slug}/{image}[/{thumb}]', App\Action\GetImageAction::class, 'api.image');
$app->get('/image/{slug}/{image}[/{thumb}]', App\Action\GetImageAction::class, 'download.image');

View File

@ -6,7 +6,7 @@ require 'recipe/common.php';
set('ssh_type', 'native');
set('ssh_multiplexing', true);
set('repository', 'ssh://gogs@gogs.ragnarok.yvan.hu:2206/yvan/gallery-api.git');
set('repository', 'https://gogs.ragnarok.yvan.hu/yvan/gallery-api.git');
set('shared_dirs', [
// 'vendor',
'data/galleries',
@ -15,12 +15,12 @@ set('writable_dirs', []);
set('keep_releases', 3);
set('default_stage', 'production');
server('prod', 'woody.fixnet.hu', 22)
server('prod', 'alfheim.ragnarok.yvan.hu', 22)
->stage('production')
->user('yvan')
->forwardAgent()
->set('php_service_name', 'php7.1-fpm')
->set('deploy_path', '/mnt/domains/yvan.hu/photos/api');
->set('deploy_path', '/mnt/apps/photos/api');
desc('Restart PHP-FPM service');
task('php-fpm:restart', function () {
@ -28,7 +28,7 @@ task('php-fpm:restart', function () {
// /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service
run('sudo service {{php_service_name}} reload');
});
//after('deploy:symlink', 'php-fpm:restart');
after('deploy:symlink', 'php-fpm:restart');
task('deploy', [
'deploy:prepare',

View File

@ -2,11 +2,11 @@
namespace App\Action;
use App\Response\JsonCorsResponse;
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\JsonResponse;
class GetGalleryImagesAction implements ServerMiddlewareInterface
{
@ -20,6 +20,6 @@ class GetGalleryImagesAction implements ServerMiddlewareInterface
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
$slug = $request->getAttribute('slug', false);
return new JsonResponse($this->galleryService->getGallery($slug));
return new JsonCorsResponse($this->galleryService->getGallery($slug));
}
}

View File

@ -34,8 +34,8 @@ class GetImageAction implements ServerMiddlewareInterface
->withHeader('Content-Transfer-Encoding', 'Binary')
->withHeader('Content-Description', 'File Transfer')
->withHeader('Pragma', 'public')
->withHeader('Expires', '0')
->withHeader('Cache-Control', 'must-revalidate')
// ->withHeader('Expires', '0')
// ->withHeader('Cache-Control', 'must-revalidate')
->withBody($stream)
->withHeader('Content-Length', "{$stream->getSize()}");
}

View File

@ -2,11 +2,11 @@
namespace App\Action;
use App\Response\JsonCorsResponse;
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\JsonResponse;
class ListGalleriesAction implements ServerMiddlewareInterface
{
@ -19,6 +19,7 @@ class ListGalleriesAction implements ServerMiddlewareInterface
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
return new JsonResponse($this->galleryService->listGalleries());
// return new JsonCorsResponse($this->galleryService->listGalleries(true));
return new JsonCorsResponse($this->galleryService->loadGalleryData(true));
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace App\Middleware;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
class PreFlightMiddleware
{
const ALLOW_HEADERS = [
'DNT',
'X-CustomHeader',
'Keep-Alive',
'User-Agent',
'X-Requested-With',
'If-Modified-Since',
'Cache-Control',
'Content-Type',
'Authorization',
];
public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
{
$requestMethod = strtoupper($request->getMethod());
if ($requestMethod == 'OPTIONS') {
return $response
->withHeader('Accept', 'OPTIONS,GET,POST,PUT,PATCH,DELETE')
->withHeader('Access-Control-Allow-Origin', '*')
->withHeader('Access-Control-Allow-Methods', 'OPTIONS,GET,POST,PUT,PATCH,DELETE')
->withHeader('Access-Control-Allow-Headers', implode(",", self::ALLOW_HEADERS));
}
return $next($request, $response);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Response;
use Zend\Diactoros\Response\JsonResponse;
class JsonCorsResponse extends JsonResponse
{
const ALLOW_HEADERS = [
'DNT',
'X-CustomHeader',
'Keep-Alive',
'User-Agent',
'X-Requested-With',
'If-Modified-Since',
'Cache-Control',
'Content-Type',
'Authorization',
];
public function __construct(
$data,
$status = 200,
array $headers = [],
$encodingOptions = self::DEFAULT_JSON_FLAGS
) {
$headers['Access-Control-Allow-Origin'] = '*';
$headers['Access-Control-Allow-Methods'] = 'OPTIONS,GET,POST,PUT,PATCH,DELETE';
$headers['Access-Control-Allow-Headers'] = implode(",", self::ALLOW_HEADERS);
parent::__construct($data, $status, $headers, $encodingOptions);
}
}

View File

@ -13,7 +13,7 @@ use Zend\Config\Reader\Yaml;
class GalleryService
{
const CONFIG_FILE = 'data/galleries/gallery.yaml';
const CONFIG_FILE = 'data/galleries/config.yaml';
const IMAGE_BASEDIR = 'data/galleries/%s/';
const THUMBNAIL_SIZE = 250;
@ -24,6 +24,67 @@ class GalleryService
];
protected $config;
public function loadGalleryData($includeHidden = false)
{
$config = $this->getConfig();
$slugs = [];
foreach ($config['galleries'] as $id => $data) {
if ($includeHidden || $data['public']) {
$slugs[] = [
'slug' => $id,
'name' => $data['name'],
'coverImage' => isset($data['cover'])
? $this->getCoverImage($data['cover'])
: null,
'date' => $this->getGalleryDate($data['dir']),
'type' => $data['type'],
'isNew' => $data['new'],
'isPublic' => $data['public'],
'images' => $this->loadGalleryImages($data['dir']),
];
}
}
return $slugs;
}
private function getGalleryDate(string $dir): string
{
$timestamp = sprintf("@%s", filemtime(sprintf(self::IMAGE_BASEDIR, $dir)));
$date = new \DateTime($timestamp);
return $date->format("Y-m-d");
}
/**
* @param string $dir
* @return array
* @todo implement label for image in some way
*/
private function loadGalleryImages(string $dir)
{
$images = array_map('basename', glob(
sprintf(self::IMAGE_BASEDIR . "*.{jpg,jpeg,png}", $dir),
GLOB_BRACE
));
return array_map(function ($image) {
return [
'label' => '',
'path' => $image,
];
}, $images);
}
/**
* @param string $image
* @return array
*/
private function getCoverImage(string $image)
{
return [
'label' => '',
'path' => $image,
];
}
public function listGalleries($includeHidden = false)
{
$config = $this->getConfig();
@ -51,7 +112,10 @@ class GalleryService
if (in_array($slug, $slugs)) {
$dir = $config['galleries'][$slug]['dir'];
$images = array_map('basename', glob(sprintf(self::IMAGE_BASEDIR . "*.{jpg,jpeg,png}", $dir), GLOB_BRACE));
$images = array_map('basename', glob(
sprintf(self::IMAGE_BASEDIR . "*.{jpg,jpeg,png}", $dir),
GLOB_BRACE
));
}
return [
@ -72,6 +136,27 @@ class GalleryService
return $imageFileName;
}
public function exportGallery(string $slug)
{
$config = $this->getConfig();
if (!isset($config['galleries'][$slug])) {
return false;
}
$dir = $config['galleries'][$slug]['dir'];
$images = array_map('basename', glob(sprintf(self::IMAGE_BASEDIR . "*.{jpg,jpeg,png}", $dir), GLOB_BRACE));
$zipName = tempnam("data/tmp", "export");
$zipArchive = new \ZipArchive();
$zipArchive->open($zipName, \ZipArchive::CREATE);
foreach ($images as $image) {
$zipArchive->addFile("{$dir}/{$image}");
}
$zipArchive->close();
return $zipName;
}
protected function getResizedImageName($galleryDirectory, $imageName, $size): string
{
$numericSize = $size == 'thumb' ? self::THUMBNAIL_SIZE : $size;