From f19afc41f0555cdfc244e9b178b5866f12441af3 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 16 Nov 2025 22:52:07 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Implement=20Trakt=20config=20loadin?= =?UTF-8?q?g=20from=20JSON=20file=20with=20ENV=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 +- composer.lock | 160 ++++++++++++++++++++++++++++++++++++++++++++++- config/trakt.php | 28 ++++++--- 3 files changed, 180 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index c130c1b..728138d 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ "laravel-zero/framework": "^10.0", "nunomaduro/termwind": "^1.3", "php-ffmpeg/php-ffmpeg": "^1.0", - "spatie/laravel-data": "^2.0" + "spatie/laravel-data": "^2.0", + "xdg/base-directory": "^1.2" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index f09a1ad..94880d3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9ebd8521e376754effa9bc94f7afbc9e", + "content-hash": "dbc82eba2362bad2cc7266710afb0827", "packages": [ { "name": "brick/math", @@ -5166,6 +5166,76 @@ ], "time": "2024-09-25T14:21:43+00:00" }, + { + "name": "symfony/filesystem", + "version": "v6.4.24", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "75ae2edb7cdcc0c53766c30b0a2512b8df574bd8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/75ae2edb7cdcc0c53766c30b0a2512b8df574bd8", + "reference": "75ae2edb7cdcc0c53766c30b0a2512b8df574bd8", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8" + }, + "require-dev": { + "symfony/process": "^5.4|^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides basic utilities for the filesystem", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/filesystem/tree/v6.4.24" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-07-10T08:14:14+00:00" + }, { "name": "symfony/finder", "version": "v6.4.24", @@ -6907,6 +6977,94 @@ "source": "https://github.com/webmozarts/assert/tree/1.12.0" }, "time": "2025-10-20T12:43:39+00:00" + }, + { + "name": "xdg/base-directory", + "version": "1.2", + "source": { + "type": "git", + "url": "https://github.com/php-xdg/base-directory.git", + "reference": "7a91de4c387e9e0d31b8ab6aa564dc85f546b381" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-xdg/base-directory/zipball/7a91de4c387e9e0d31b8ab6aa564dc85f546b381", + "reference": "7a91de4c387e9e0d31b8ab6aa564dc85f546b381", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/filesystem": "^5.4||^6.0", + "xdg/environment": "^2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Xdg\\BaseDirectory\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "ju1ius", + "email": "jules.bernable@gmail.com" + } + ], + "description": "Implementation of the XDG Base Directory Specification", + "support": { + "issues": "https://github.com/php-xdg/base-directory/issues", + "source": "https://github.com/php-xdg/base-directory/tree/1.2" + }, + "time": "2023-03-02T08:43:12+00:00" + }, + { + "name": "xdg/environment", + "version": "2.1", + "source": { + "type": "git", + "url": "https://github.com/php-xdg/environment.git", + "reference": "d626d63e902150bbf326756e4b78eea461fd7c12" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-xdg/environment/zipball/d626d63e902150bbf326756e4b78eea461fd7c12", + "reference": "d626d63e902150bbf326756e4b78eea461fd7c12", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Xdg\\Environment\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "ju1ius", + "email": "jules.bernable@gmail.com" + } + ], + "description": "An abstraction layer over environment variables.", + "keywords": [ + "environment", + "environment-variables", + "freedesktop", + "xdg" + ], + "support": { + "issues": "https://github.com/php-xdg/environment/issues", + "source": "https://github.com/php-xdg/environment/tree/2.1" + }, + "time": "2023-03-13T19:24:46+00:00" } ], "packages-dev": [ diff --git a/config/trakt.php b/config/trakt.php index 5b91722..90b13f3 100644 --- a/config/trakt.php +++ b/config/trakt.php @@ -1,11 +1,21 @@ env('TRAKT_APP_ID'), - 'app_secret' => env('TRAKT_APP_secret'), - 'redirect_uri' => env('TRAKT_REDIRECT_URI', 'urn:ietf:wg:oauth:2.0:oob'), - 'login' => [ - 'device' => json_decode(env('TRAKT_DEVICE_RESP', '{}}'), true), - 'oauth' => json_decode(env('TRAKT_OAUTH_RESP', '{}}'), true), - ], -]; +use Xdg\BaseDirectory\XdgBaseDirectory as Xdg; +use Illuminate\Support\Arr; + +$data = []; + +$xdg = Xdg::fromEnvironment(); +$path = $xdg->findDataPath("trakt/data.json", file_exists(...)); +if (file_exists($path)) { + $data = json_decode(file_get_contents($path), true); +} + +$data = Arr::add($data, 'app_id', env('TRAKT_APP_ID')); +$data = Arr::add($data, 'app_secret', env('TRAKT_APP_SECRET')); +$data = Arr::add($data, 'redirect_uri', env('TRAKT_REDIRECT_URI', 'urn:ietf:wg:oauth:2.0:oob')); +$data['login'] = $data['login'] ?? []; +$data['login'] = Arr::add($data['login'], 'device', json_decode(env('TRAKT_DEVICE_RESP', '{}'), true)); +$data['login'] = Arr::add($data['login'], 'oauth', json_decode(env('TRAKT_OAUTH_RESP', '{}'), true)); + +return $data;