diff --git a/config/config.php b/config/config.php index 082f5a26..b6407d8c 100644 --- a/config/config.php +++ b/config/config.php @@ -18,13 +18,15 @@ use Symfony\Component\Cache\Adapter\FilesystemAdapter; return (function () { $config = [ 'name' => 'WatchState', - 'version' => 'v0.0.1-beta', + 'version' => 'v0.0.0', 'tz' => null, 'path' => fixPath( env('WS_DATA_PATH', fn() => env('IN_DOCKER') ? '/config' : realpath(__DIR__ . '/../var')) ), ]; + $config['tmpDir'] = fixPath(env('WS_TMP_DIR', fn() => ag($config, 'path'))); + $config['storage'] = [ 'type' => PDOAdapter::class, 'opts' => [ @@ -78,7 +80,7 @@ return (function () { $config['cache'] = [ 'adapter' => FilesystemAdapter::class, 'config' => [ - 'directory' => env('WS_CACHE_DIR', fn() => ag($config, 'path') . '/cache'), + 'directory' => ag($config, 'tmpDir') . '/cache', ], ]; @@ -87,7 +89,7 @@ return (function () { 'options' => [ 'save.handler' => 'file', 'save.handler.file' => [ - 'filename' => ag($config, 'path') . '/logs/profiler_' . gmdate('Y_m_d_His') . '.json' + 'filename' => ag($config, 'tmpDir') . '/profiler/profiler_' . gmdate('Y_m_d_His') . '.json' ], ], ], @@ -104,7 +106,7 @@ return (function () { 'type' => 'stream', 'enabled' => env('WS_LOGGER_FILE_ENABLE', false), 'level' => env('WS_LOGGER_FILE_LEVEL', Logger::ERROR), - 'filename' => env('WS_LOGGER_FILE', fn() => ag($config, 'path') . '/logs/app.log'), + 'filename' => env('WS_LOGGER_FILE', fn() => ag($config, 'tmpDir') . '/logs/app.log'), ], 'syslog' => [ 'type' => 'syslog', diff --git a/config/directories.php b/config/directories.php index a85620ab..29c46faf 100644 --- a/config/directories.php +++ b/config/directories.php @@ -4,7 +4,9 @@ declare(strict_types=1); return [ '%(path)/db', - '%(path)/logs', '%(path)/config', - '%(path)/cache', + '%(tmpDir)/logs', + '%(tmpDir)/cache', + '%(tmpDir)/profiler', + '%(tmpDir)/webhooks', ]; diff --git a/src/Libs/KernelConsole.php b/src/Libs/KernelConsole.php index bd1eb463..9759f897 100644 --- a/src/Libs/KernelConsole.php +++ b/src/Libs/KernelConsole.php @@ -49,7 +49,7 @@ class KernelConsole } if (file_exists($dataPath . '/config/env')) { - (new Dotenv())->overload($dataPath . '/config/env'); + (new Dotenv())->usePutenv(true)->overload($dataPath . '/config/env'); } })(); @@ -182,16 +182,20 @@ class KernelConsole } if (!($path = Config::get('path'))) { - throw new RuntimeException('No app path was set in config path or WS_DATA_PATH ENV'); + throw new RuntimeException('No ENV:WS_DATA_PATH was set.'); } - if (!file_exists($path)) { - if (!@mkdir($path, 0755, true) && !is_dir($path)) { - throw new RuntimeException(sprintf('Unable to create "%s" Directory.', $path)); - } + if (!($tmpDir = Config::get('tmpDir'))) { + throw new RuntimeException('No ENV:WS_TMP_DIR was set.'); } $fn = function (string $key, string $path): string { + if (!file_exists($path)) { + if (!@mkdir($path, 0755, true) && !is_dir($path)) { + throw new RuntimeException(sprintf('Unable to create "%s" Directory.', $path)); + } + } + if (!is_dir($path)) { throw new RuntimeException(sprintf('%s is not a directory.', $key)); } @@ -219,10 +223,13 @@ class KernelConsole return DIRECTORY_SEPARATOR !== $path ? rtrim($path, DIRECTORY_SEPARATOR) : $path; }; - $path = $fn('path', $path); + $list = [ + '%(path)' => $fn('path', $path), + '%(tmpDir)' => $fn('tmpDir', $tmpDir), + ]; foreach (require $dirList as $dir) { - $dir = str_replace('%(path)', $path, $dir); + $dir = str_replace(array_keys($list), array_values($list), $dir); if (!file_exists($dir)) { if (!@mkdir($dir, 0755, true) && !is_dir($dir)) { diff --git a/src/Libs/Servers/JellyfinServer.php b/src/Libs/Servers/JellyfinServer.php index f9d333a8..bd107d1d 100644 --- a/src/Libs/Servers/JellyfinServer.php +++ b/src/Libs/Servers/JellyfinServer.php @@ -223,7 +223,7 @@ class JellyfinServer implements ServerInterface return $request; } - $body = $request->getBody()->getContents(); + $body = (string)$request->getBody(); if (null === ($json = json_decode($body, true))) { return $request; diff --git a/src/Libs/helpers.php b/src/Libs/helpers.php index 8fe0da41..a931f4cc 100644 --- a/src/Libs/helpers.php +++ b/src/Libs/helpers.php @@ -234,13 +234,13 @@ if (!function_exists('saveWebhookPayload')) { 'query' => $request->getQueryParams(), 'parsed' => $request->getParsedBody(), 'server' => $request->getServerParams(), - 'body' => $request->getBody()->getContents(), + 'body' => (string)$request->getBody(), 'attributes' => $request->getAttributes(), 'cParsed' => $parsed, ]; @file_put_contents( - Config::get('path') . '/logs/' . sprintf('webhook.%s.%d.json', $name, time()), + Config::get('tmpDir') . '/webhooks/' . sprintf('webhook.%s.%d.json', $name, time()), json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) ); }