From 929c1b90d6b16706f9c63339f5f2a2b42332f3f3 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 6 Aug 2025 15:21:03 +0200 Subject: split into two standalone containers --- .gitignore | 5 - Dockerfile | 6 - Justfile | 9 +- Readme.md | 14 +- composer.json | 23 -- composer.lock | 768 --------------------------------------------- docker-compose.dev.yml | 31 ++ docker-compose.yml | 55 +--- index.php | 38 --- mtg-pdf.php | 147 --------- print/.gitignore | 2 + print/Dockerfile | 14 + print/composer.json | 19 ++ print/composer.lock | 775 ++++++++++++++++++++++++++++++++++++++++++++++ print/print.php | 147 +++++++++ web.conf.template | 17 - web/Dockerfile | 18 ++ web/default.conf.template | 18 ++ web/index.php | 38 +++ 19 files changed, 1090 insertions(+), 1054 deletions(-) delete mode 100644 .gitignore delete mode 100644 Dockerfile delete mode 100644 composer.json delete mode 100644 composer.lock create mode 100644 docker-compose.dev.yml delete mode 100644 index.php delete mode 100644 mtg-pdf.php create mode 100644 print/.gitignore create mode 100644 print/Dockerfile create mode 100644 print/composer.json create mode 100644 print/composer.lock create mode 100644 print/print.php delete mode 100644 web.conf.template create mode 100644 web/Dockerfile create mode 100644 web/default.conf.template create mode 100644 web/index.php diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 1e29f20..0000000 --- a/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/vendor/ -/output/ - -AllPrintings.sqlite -.env diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index bbfce84..0000000 --- a/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM php:fpm-alpine - -COPY index.php . -COPY mtg-pdf.php . -COPY vendor vendor -COPY AllPrintings.sqlite . diff --git a/Justfile b/Justfile index 7e9cae9..f4a6b68 100644 --- a/Justfile +++ b/Justfile @@ -1,3 +1,6 @@ -generate deck: - DECKLIST="{{deck}}" docker compose run cli - docker compose down +build: + docker build --no-cache -t mtg-print print + docker build --no-cache -t mtg-print-web web + +get_printings: + curl -L https://mtgjson.com/api/v5/AllPrintings.sqlite -o print/AllPrintings.sqlite diff --git a/Readme.md b/Readme.md index 6508228..dd726f3 100644 --- a/Readme.md +++ b/Readme.md @@ -1 +1,13 @@ -TODO: split into generic package and server service implementation +## Run web interface +``` +docker compose up -d +# add overwrites as needed +``` + +## Update printings database + +``` +just get_printings +# or +curl -L https://mtgjson.com/api/v5/AllPrintings.sqlite -o print/AllPrintings.sqlite +``` diff --git a/composer.json b/composer.json deleted file mode 100644 index 1f6c131..0000000 --- a/composer.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "dweipert/mtg-pdf", - "authors": [ - { - "name": "Daniel Weipert", - "email": "code@drogueronin.de" - } - ], - "require": { - "gotenberg/gotenberg-php": "^1.1", - "guzzlehttp/guzzle": "^7.8" - }, - "autoload": { - "psr-4": { - "Dweipert\\MtgPdf\\": "src/" - } - }, - "config": { - "allow-plugins": { - "php-http/discovery": true - } - } -} diff --git a/composer.lock b/composer.lock deleted file mode 100644 index f3e7063..0000000 --- a/composer.lock +++ /dev/null @@ -1,768 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "8866dd682d37b1548722b1ca15cbf6bf", - "packages": [ - { - "name": "gotenberg/gotenberg-php", - "version": "v1.1.7", - "source": { - "type": "git", - "url": "https://github.com/gotenberg/gotenberg-php.git", - "reference": "cfe70a9693a9ca58ebdcda6ec6a4ea404219d592" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/gotenberg/gotenberg-php/zipball/cfe70a9693a9ca58ebdcda6ec6a4ea404219d592", - "reference": "cfe70a9693a9ca58ebdcda6ec6a4ea404219d592", - "shasum": "" - }, - "require": { - "ext-json": "*", - "ext-mbstring": "*", - "guzzlehttp/psr7": "^1 || ^2.1", - "php": "^7.4|^8.0|^8.1|^8.2|^8.3", - "php-http/discovery": "^1.14", - "psr/http-client": "^1.0", - "psr/http-message": "^1.0|^2.0" - }, - "require-dev": { - "doctrine/coding-standard": "^9.0", - "pestphp/pest": "^1.21", - "phpstan/phpstan": "^1.2", - "squizlabs/php_codesniffer": "^3.6" - }, - "type": "library", - "autoload": { - "psr-4": { - "Gotenberg\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Julien Neuhart", - "email": "neuhart.julien@gmail.com", - "homepage": "https://github.com/gulien", - "role": "Developer" - } - ], - "description": "A PHP client for interacting with Gotenberg, a developer-friendly API for converting numerous document formats into PDF files, and more!", - "homepage": "https://github.com/gotenberg/gotenberg-php", - "keywords": [ - "Gotenberg", - "LibreOffice", - "chrome", - "chromium", - "convert", - "csv", - "docx", - "excel", - "html", - "markdown", - "pdf", - "pdftk", - "pptx", - "puppeteer", - "unoconv", - "wkhtmltopdf", - "word", - "xlsx" - ], - "support": { - "issues": "https://github.com/gotenberg/gotenberg-php/issues", - "source": "https://github.com/gotenberg/gotenberg-php/tree/v1.1.7" - }, - "time": "2023-11-22T19:42:36+00:00" - }, - { - "name": "guzzlehttp/guzzle", - "version": "7.8.0", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1110f66a6530a40fe7aea0378fe608ee2b2248f9", - "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9", - "shasum": "" - }, - "require": { - "ext-json": "*", - "guzzlehttp/promises": "^1.5.3 || ^2.0.1", - "guzzlehttp/psr7": "^1.9.1 || ^2.5.1", - "php": "^7.2.5 || ^8.0", - "psr/http-client": "^1.0", - "symfony/deprecation-contracts": "^2.2 || ^3.0" - }, - "provide": { - "psr/http-client-implementation": "1.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", - "ext-curl": "*", - "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", - "php-http/message-factory": "^1.1", - "phpunit/phpunit": "^8.5.29 || ^9.5.23", - "psr/log": "^1.1 || ^2.0 || ^3.0" - }, - "suggest": { - "ext-curl": "Required for CURL handler support", - "ext-intl": "Required for Internationalized Domain Name (IDN) support", - "psr/log": "Required for using the Log middleware" - }, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "files": [ - "src/functions_include.php" - ], - "psr-4": { - "GuzzleHttp\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Jeremy Lindblom", - "email": "jeremeamia@gmail.com", - "homepage": "https://github.com/jeremeamia" - }, - { - "name": "George Mponos", - "email": "gmponos@gmail.com", - "homepage": "https://github.com/gmponos" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://github.com/sagikazarmark" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - } - ], - "description": "Guzzle is a PHP HTTP client library", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "psr-18", - "psr-7", - "rest", - "web service" - ], - "support": { - "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.8.0" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", - "type": "tidelift" - } - ], - "time": "2023-08-27T10:20:53+00:00" - }, - { - "name": "guzzlehttp/promises", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/promises.git", - "reference": "111166291a0f8130081195ac4556a5587d7f1b5d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/111166291a0f8130081195ac4556a5587d7f1b5d", - "reference": "111166291a0f8130081195ac4556a5587d7f1b5d", - "shasum": "" - }, - "require": { - "php": "^7.2.5 || ^8.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", - "phpunit/phpunit": "^8.5.29 || ^9.5.23" - }, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Promise\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - } - ], - "description": "Guzzle promises library", - "keywords": [ - "promise" - ], - "support": { - "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.0.1" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", - "type": "tidelift" - } - ], - "time": "2023-08-03T15:11:55+00:00" - }, - { - "name": "guzzlehttp/psr7", - "version": "2.6.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "be45764272e8873c72dbe3d2edcfdfcc3bc9f727" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/be45764272e8873c72dbe3d2edcfdfcc3bc9f727", - "reference": "be45764272e8873c72dbe3d2edcfdfcc3bc9f727", - "shasum": "" - }, - "require": { - "php": "^7.2.5 || ^8.0", - "psr/http-factory": "^1.0", - "psr/http-message": "^1.1 || ^2.0", - "ralouphie/getallheaders": "^3.0" - }, - "provide": { - "psr/http-factory-implementation": "1.0", - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", - "http-interop/http-factory-tests": "^0.9", - "phpunit/phpunit": "^8.5.29 || ^9.5.23" - }, - "suggest": { - "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" - }, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "George Mponos", - "email": "gmponos@gmail.com", - "homepage": "https://github.com/gmponos" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://github.com/sagikazarmark" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://sagikazarmark.hu" - } - ], - "description": "PSR-7 message implementation that also provides common utility methods", - "keywords": [ - "http", - "message", - "psr-7", - "request", - "response", - "stream", - "uri", - "url" - ], - "support": { - "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.6.1" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", - "type": "tidelift" - } - ], - "time": "2023-08-27T10:13:57+00:00" - }, - { - "name": "php-http/discovery", - "version": "1.19.1", - "source": { - "type": "git", - "url": "https://github.com/php-http/discovery.git", - "reference": "57f3de01d32085fea20865f9b16fb0e69347c39e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-http/discovery/zipball/57f3de01d32085fea20865f9b16fb0e69347c39e", - "reference": "57f3de01d32085fea20865f9b16fb0e69347c39e", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.0|^2.0", - "php": "^7.1 || ^8.0" - }, - "conflict": { - "nyholm/psr7": "<1.0", - "zendframework/zend-diactoros": "*" - }, - "provide": { - "php-http/async-client-implementation": "*", - "php-http/client-implementation": "*", - "psr/http-client-implementation": "*", - "psr/http-factory-implementation": "*", - "psr/http-message-implementation": "*" - }, - "require-dev": { - "composer/composer": "^1.0.2|^2.0", - "graham-campbell/phpspec-skip-example-extension": "^5.0", - "php-http/httplug": "^1.0 || ^2.0", - "php-http/message-factory": "^1.0", - "phpspec/phpspec": "^5.1 || ^6.1 || ^7.3", - "symfony/phpunit-bridge": "^6.2" - }, - "type": "composer-plugin", - "extra": { - "class": "Http\\Discovery\\Composer\\Plugin", - "plugin-optional": true - }, - "autoload": { - "psr-4": { - "Http\\Discovery\\": "src/" - }, - "exclude-from-classmap": [ - "src/Composer/Plugin.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com" - } - ], - "description": "Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations", - "homepage": "http://php-http.org", - "keywords": [ - "adapter", - "client", - "discovery", - "factory", - "http", - "message", - "psr17", - "psr7" - ], - "support": { - "issues": "https://github.com/php-http/discovery/issues", - "source": "https://github.com/php-http/discovery/tree/1.19.1" - }, - "time": "2023-07-11T07:02:26+00:00" - }, - { - "name": "psr/http-client", - "version": "1.0.3", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-client.git", - "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", - "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", - "shasum": "" - }, - "require": { - "php": "^7.0 || ^8.0", - "psr/http-message": "^1.0 || ^2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Client\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP clients", - "homepage": "https://github.com/php-fig/http-client", - "keywords": [ - "http", - "http-client", - "psr", - "psr-18" - ], - "support": { - "source": "https://github.com/php-fig/http-client" - }, - "time": "2023-09-23T14:17:50+00:00" - }, - { - "name": "psr/http-factory", - "version": "1.0.2", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-factory.git", - "reference": "e616d01114759c4c489f93b099585439f795fe35" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", - "reference": "e616d01114759c4c489f93b099585439f795fe35", - "shasum": "" - }, - "require": { - "php": ">=7.0.0", - "psr/http-message": "^1.0 || ^2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interfaces for PSR-7 HTTP message factories", - "keywords": [ - "factory", - "http", - "message", - "psr", - "psr-17", - "psr-7", - "request", - "response" - ], - "support": { - "source": "https://github.com/php-fig/http-factory/tree/1.0.2" - }, - "time": "2023-04-10T20:10:41+00:00" - }, - { - "name": "psr/http-message", - "version": "2.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], - "support": { - "source": "https://github.com/php-fig/http-message/tree/2.0" - }, - "time": "2023-04-04T09:54:51+00:00" - }, - { - "name": "ralouphie/getallheaders", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" - }, - "type": "library", - "autoload": { - "files": [ - "src/getallheaders.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" - } - ], - "description": "A polyfill for getallheaders.", - "support": { - "issues": "https://github.com/ralouphie/getallheaders/issues", - "source": "https://github.com/ralouphie/getallheaders/tree/develop" - }, - "time": "2019-03-08T08:55:37+00:00" - }, - { - "name": "symfony/deprecation-contracts", - "version": "v3.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "files": [ - "function.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-05-23T14:45:45+00:00" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [], - "plugin-api-version": "2.6.0" -} diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..b08d9bf --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,31 @@ +services: + gotenberg: + image: "gotenberg/gotenberg:8" + + print: + build: + context: print + depends_on: + - "gotenberg" + volumes: + - "./print:/var/www/html" + + php: + image: php:fpm-alpine + volumes: + - "./web:/var/www/html" + - "./print:/var/www/html/print" + + web: + build: + context: web + depends_on: + - "gotenberg" + - "php" + ports: + - "8080:80" + environment: + - "SERVER_NAME=localhost" + volumes: + - "./web:/var/www/html" + - "./print:/var/www/html/print" diff --git a/docker-compose.yml b/docker-compose.yml index e8e8280..6f6d28f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,57 +1,20 @@ services: gotenberg: - image: "gotenberg/gotenberg:7" - networks: - - "internal" - - cli: - image: "php:cli-alpine" - depends_on: - - "gotenberg" - environment: - - "DECKLIST=${DECKLIST}" - volumes: - - "./:/usr/src/app" - networks: - - "internal" - working_dir: "/usr/src/app" - command: ["php", "-d", "memory_limit=256M", "./mtg-pdf.php"] - profiles: [cli] + image: "gotenberg/gotenberg:8" php: - # image: php:fpm-alpine - build: . - depends_on: - - "gotenberg" - # volumes: - # - "./:/var/www/html" - networks: - - "internal" + image: php:fpm-alpine + volumes: + - "web:/var/www/html" web: - image: nginx:alpine - restart: unless-stopped + image: mtg-print-web depends_on: + - "gotenberg" - "php" - environment: - - "DOMAIN=${DOMAIN}" volumes: - - "./:/var/www/html" - - "./web.conf.template:/etc/nginx/templates/web.conf.template" - networks: - - "internal" - - "traefik" - labels: - - "traefik.enable=true" - - "traefik.docker.network=${TRAEFIK_NETWORK}" - - "traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host(`${DOMAIN}`)" - - "traefik.http.routers.${COMPOSE_PROJECT_NAME}.entrypoints=websecure" - - "traefik.http.routers.${COMPOSE_PROJECT_NAME}.tls=true" - - "traefik.http.routers.${COMPOSE_PROJECT_NAME}.tls.certresolver=letsencrypt" + - "web:/var/www/html" -networks: - internal: - traefik: - name: "${TRAEFIK_NETWORK}" - external: true +volumes: + web: diff --git a/index.php b/index.php deleted file mode 100644 index 79920f7..0000000 --- a/index.php +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - -
- - -
-
- Source - - diff --git a/mtg-pdf.php b/mtg-pdf.php deleted file mode 100644 index 55b8112..0000000 --- a/mtg-pdf.php +++ /dev/null @@ -1,147 +0,0 @@ - $matches[1][$idx], - 'name' => $matches[2][$idx], - 'set' => strtoupper($matches[3][$idx]), - 'number' => $matches[4][$idx], - ]; -} - -if (empty($cards)) { - die("Couldn't find any cards matching the pattern."); -} - -/* - * Select data from DB - */ - -$db = new \PDO('sqlite:AllPrintings.sqlite'); - -$images = []; -foreach ($cards as $card) { - $query = <<prepare($query); - $statement->execute(['setCode' => $card['set'], 'number' => $card['number']]); - $result = $statement->fetch(); - $id = $result['scryfallId'] ?? ''; - - if (empty($id)) { - $query = <<prepare($query); - $statement->execute(['setCode' => $card['set'], 'number' => $card['number']]); - $result = $statement->fetch(); - $id = $result['scryfallId'] ?? ''; - - if (empty($id)) { - echo "$card[name] ($card[set]) $card[number] not found."; - echo php_sapi_name() == 'cli' ? "\n" : '
'; - continue; - } - } - - $images[] = [ - 'quantity' => $card['quantity'], - 'src' => "https://cards.scryfall.io/png/front/" . substr($id, 0, 1) . "/" . substr($id, 1, 1) . "/$id.png", - 'alt' => $card['name'], - ]; - - if (in_array($result['layout'] ?? '', ['transform', 'double_faced_token'])) { - $images[] = [ - 'quantity' => $card['quantity'], - 'src' => "https://cards.scryfall.io/png/back/" . substr($id, 0, 1) . "/" . substr($id, 1, 1) . "/$id.png", - 'alt' => $card['name'], - ]; - } -} - -if (empty($images)) { - die('No cards to print.'); -} - -/* - * Build HTML - */ - -$template = << - - - - -
{{imgs}}
- - -HTML; - -$imgs = array_map(function ($image) { - return str_repeat("\"$image[alt]\"", $image['quantity']); -}, $images); - -$html = str_replace('{{imgs}}', implode('', $imgs), $template); - -/* - * Build PDF - */ - -$request = Gotenberg::chromium('gotenberg:3000') - ->paperSize(8.27, 11.7) # A4 - ->margins(0.3, 0, 0.3, 0) - ->outputFilename(date("Ymd_His")) - ->html(Stream::string('index.html', $html)); - -if (php_sapi_name() === 'cli') { - @mkdir(__DIR__ . '/output'); - Gotenberg::save($request, __DIR__ . '/output'); -} else { - $response = Gotenberg::send($request); - - header('Content-Type: application/pdf'); - header('Content-Disposition: attachment; filename="' . date("Ymd_His") . '"'); - echo $response->getBody(); -} diff --git a/print/.gitignore b/print/.gitignore new file mode 100644 index 0000000..9d80500 --- /dev/null +++ b/print/.gitignore @@ -0,0 +1,2 @@ +/vendor/ +AllPrintings.sqlite diff --git a/print/Dockerfile b/print/Dockerfile new file mode 100644 index 0000000..632b917 --- /dev/null +++ b/print/Dockerfile @@ -0,0 +1,14 @@ +FROM composer AS composer +FROM php:fpm-alpine + +COPY --from=composer /usr/bin/composer /usr/bin/composer + +WORKDIR /var/www/html + +COPY composer.* ./ +COPY print.php . +COPY AllPrintings.sqlite . + +RUN composer install + +CMD ["php", "./print.php"] diff --git a/print/composer.json b/print/composer.json new file mode 100644 index 0000000..b0835ef --- /dev/null +++ b/print/composer.json @@ -0,0 +1,19 @@ +{ + "name": "mtg-pdf/print", + "version": "0.1.0", + "authors": [ + { + "name": "Daniel Weipert", + "email": "git@mail.dweipert.de" + } + ], + "require": { + "gotenberg/gotenberg-php": "^2.14", + "guzzlehttp/guzzle": "^7.9" + }, + "config": { + "allow-plugins": { + "php-http/discovery": true + } + } +} diff --git a/print/composer.lock b/print/composer.lock new file mode 100644 index 0000000..4e8cc63 --- /dev/null +++ b/print/composer.lock @@ -0,0 +1,775 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "bf85f87211eb6b1a6fa04723482817f2", + "packages": [ + { + "name": "gotenberg/gotenberg-php", + "version": "v2.14.0", + "source": { + "type": "git", + "url": "https://github.com/gotenberg/gotenberg-php.git", + "reference": "748efe0a981b3e8eb676593246a75925448324ad" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/gotenberg/gotenberg-php/zipball/748efe0a981b3e8eb676593246a75925448324ad", + "reference": "748efe0a981b3e8eb676593246a75925448324ad", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "guzzlehttp/psr7": "^1 || ^2.1", + "php": "^8.1|^8.2|^8.3|^8.4", + "php-http/discovery": "^1.14", + "psr/http-client": "^1.0", + "psr/http-message": "^1.0|^2.0" + }, + "require-dev": { + "doctrine/coding-standard": "^12.0", + "pestphp/pest": "^2.28", + "phpstan/phpstan": "^1.12", + "squizlabs/php_codesniffer": "^3.10" + }, + "type": "library", + "autoload": { + "psr-4": { + "Gotenberg\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Julien Neuhart", + "email": "neuhart.julien@gmail.com", + "homepage": "https://github.com/gulien", + "role": "Developer" + } + ], + "description": "A PHP client for interacting with Gotenberg, a developer-friendly API for converting numerous document formats into PDF files, and more!", + "homepage": "https://github.com/gotenberg/gotenberg-php", + "keywords": [ + "Gotenberg", + "LibreOffice", + "chrome", + "chromium", + "convert", + "csv", + "docx", + "excel", + "html", + "markdown", + "pdf", + "pdftk", + "pptx", + "puppeteer", + "unoconv", + "wkhtmltopdf", + "word", + "xlsx" + ], + "support": { + "issues": "https://github.com/gotenberg/gotenberg-php/issues", + "source": "https://github.com/gotenberg/gotenberg-php/tree/v2.14.0" + }, + "funding": [ + { + "url": "https://github.com/gulien", + "type": "github" + } + ], + "time": "2025-05-20T10:00:34+00:00" + }, + { + "name": "guzzlehttp/guzzle", + "version": "7.9.3", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "7b2f29fe81dc4da0ca0ea7d42107a0845946ea77" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/7b2f29fe81dc4da0ca0ea7d42107a0845946ea77", + "reference": "7b2f29fe81dc4da0ca0ea7d42107a0845946ea77", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.5.3 || ^2.0.3", + "guzzlehttp/psr7": "^2.7.0", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "ext-curl": "*", + "guzzle/client-integration-tests": "3.0.2", + "php-http/message-factory": "^1.1", + "phpunit/phpunit": "^8.5.39 || ^9.6.20", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.9.3" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2025-03-27T13:37:11+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "7c69f28996b0a6920945dd20b3857e499d9ca96c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/7c69f28996b0a6920945dd20b3857e499d9ca96c", + "reference": "7c69f28996b0a6920945dd20b3857e499d9ca96c", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "phpunit/phpunit": "^8.5.39 || ^9.6.20" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/2.2.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2025-03-27T13:27:01+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.7.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "c2270caaabe631b3b44c85f99e5a04bbb8060d16" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/c2270caaabe631b3b44c85f99e5a04bbb8060d16", + "reference": "c2270caaabe631b3b44c85f99e5a04bbb8060d16", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "http-interop/http-factory-tests": "0.9.0", + "phpunit/phpunit": "^8.5.39 || ^9.6.20" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.7.1" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2025-03-27T12:30:47+00:00" + }, + { + "name": "php-http/discovery", + "version": "1.20.0", + "source": { + "type": "git", + "url": "https://github.com/php-http/discovery.git", + "reference": "82fe4c73ef3363caed49ff8dd1539ba06044910d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/discovery/zipball/82fe4c73ef3363caed49ff8dd1539ba06044910d", + "reference": "82fe4c73ef3363caed49ff8dd1539ba06044910d", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0|^2.0", + "php": "^7.1 || ^8.0" + }, + "conflict": { + "nyholm/psr7": "<1.0", + "zendframework/zend-diactoros": "*" + }, + "provide": { + "php-http/async-client-implementation": "*", + "php-http/client-implementation": "*", + "psr/http-client-implementation": "*", + "psr/http-factory-implementation": "*", + "psr/http-message-implementation": "*" + }, + "require-dev": { + "composer/composer": "^1.0.2|^2.0", + "graham-campbell/phpspec-skip-example-extension": "^5.0", + "php-http/httplug": "^1.0 || ^2.0", + "php-http/message-factory": "^1.0", + "phpspec/phpspec": "^5.1 || ^6.1 || ^7.3", + "sebastian/comparator": "^3.0.5 || ^4.0.8", + "symfony/phpunit-bridge": "^6.4.4 || ^7.0.1" + }, + "type": "composer-plugin", + "extra": { + "class": "Http\\Discovery\\Composer\\Plugin", + "plugin-optional": true + }, + "autoload": { + "psr-4": { + "Http\\Discovery\\": "src/" + }, + "exclude-from-classmap": [ + "src/Composer/Plugin.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations", + "homepage": "http://php-http.org", + "keywords": [ + "adapter", + "client", + "discovery", + "factory", + "http", + "message", + "psr17", + "psr7" + ], + "support": { + "issues": "https://github.com/php-http/discovery/issues", + "source": "https://github.com/php-http/discovery/tree/1.20.0" + }, + "time": "2024-10-02T11:20:13+00:00" + }, + { + "name": "psr/http-client", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client" + }, + "time": "2023-09-23T14:17:50+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory" + }, + "time": "2024-04-15T12:06:14+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.6.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62", + "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, + "branch-alias": { + "dev-main": "3.6-dev" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-25T14:21:43+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": {}, + "prefer-stable": false, + "prefer-lowest": false, + "platform": {}, + "platform-dev": {}, + "plugin-api-version": "2.6.0" +} diff --git a/print/print.php b/print/print.php new file mode 100644 index 0000000..0e1137f --- /dev/null +++ b/print/print.php @@ -0,0 +1,147 @@ + $matches[1][$idx], + 'name' => $matches[2][$idx], + 'set' => strtoupper($matches[3][$idx]), + 'number' => $matches[4][$idx], + ]; +} + +if (empty($cards)) { + die("Couldn't find any cards matching the pattern."); +} + +/* + * Select data from DB + */ + +$db = new \PDO('sqlite:' . __DIR__ . '/AllPrintings.sqlite'); + +$images = []; +foreach ($cards as $card) { + $query = <<prepare($query); + $statement->execute(['setCode' => $card['set'], 'number' => $card['number']]); + $result = $statement->fetch(); + $id = $result['scryfallId'] ?? ''; + + if (empty($id)) { + $query = <<prepare($query); + $statement->execute(['setCode' => $card['set'], 'number' => $card['number']]); + $result = $statement->fetch(); + $id = $result['scryfallId'] ?? ''; + + if (empty($id)) { + echo "$card[name] ($card[set]) $card[number] not found."; + echo php_sapi_name() == 'cli' ? "\n" : '
'; + continue; + } + } + + $images[] = [ + 'quantity' => $card['quantity'], + 'src' => "https://cards.scryfall.io/png/front/" . substr($id, 0, 1) . "/" . substr($id, 1, 1) . "/$id.png", + 'alt' => $card['name'], + ]; + + if (in_array($result['layout'] ?? '', ['transform', 'double_faced_token'])) { + $images[] = [ + 'quantity' => $card['quantity'], + 'src' => "https://cards.scryfall.io/png/back/" . substr($id, 0, 1) . "/" . substr($id, 1, 1) . "/$id.png", + 'alt' => $card['name'], + ]; + } +} + +if (empty($images)) { + die('No cards to print.'); +} + +/* + * Build HTML + */ + +$template = << + + + + +
{{imgs}}
+ + +HTML; + +$imgs = array_map(function ($image) { + return str_repeat("\"$image[alt]\"", $image['quantity']); +}, $images); + +$html = str_replace('{{imgs}}', implode('', $imgs), $template); + +/* + * Build PDF + */ + +$request = Gotenberg::chromium('gotenberg:3000')->pdf() + ->paperSize(8.27, 11.7) # A4 + ->margins(0.3, 0, 0.3, 0) + ->outputFilename(date("Ymd_His")) + ->html(Stream::string('index.html', $html)); + +if (php_sapi_name() === 'cli') { + @mkdir(__DIR__ . '/output'); + Gotenberg::save($request, __DIR__ . '/output'); +} else { + $response = Gotenberg::send($request); + + header('Content-Type: application/pdf'); + header('Content-Disposition: attachment; filename="' . date("Ymd_His") . '"'); + echo $response->getBody(); +} diff --git a/web.conf.template b/web.conf.template deleted file mode 100644 index 36016fa..0000000 --- a/web.conf.template +++ /dev/null @@ -1,17 +0,0 @@ -server { - server_name ${DOMAIN}; - - root /var/www/html; - index index.php; - - location / { - try_files $uri $uri/ /index.php$query_string; - } - - location ~ \.php$ { - fastcgi_pass php:9000; - fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - include fastcgi_params; - } -} diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..d80a89e --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,18 @@ +FROM mtg-print AS mtg-print +FROM nginx:alpine + +RUN \ + mkdir -p /var/www/html/print && \ + mkdir -p /var/www/html/print/vendor && \ + chmod 557 /var/www/html/print + +COPY --from=mtg-print \ + /var/www/html/AllPrintings.sqlite /var/www/html/print.php \ + /var/www/html/print/ + +COPY --from=mtg-print \ + /var/www/html/vendor/ \ + /var/www/html/print/vendor/ + +COPY default.conf.template /etc/nginx/templates/ +COPY index.php /var/www/html/ diff --git a/web/default.conf.template b/web/default.conf.template new file mode 100644 index 0000000..888aa04 --- /dev/null +++ b/web/default.conf.template @@ -0,0 +1,18 @@ +server { + server_name localhost; + listen 80; + + root /var/www/html; + index index.php; + + location / { + try_files $uri $uri/ /index.php$query_string; + } + + location ~ \.php$ { + fastcgi_pass php:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} diff --git a/web/index.php b/web/index.php new file mode 100644 index 0000000..2aec31f --- /dev/null +++ b/web/index.php @@ -0,0 +1,38 @@ + + + + + + + + + + +
+ + +
+
+ Source + + -- cgit v1.2.3