added new config key to separate config and db folders from tmp files, if it not set it will rely on WS_DATA_PATH.
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
];
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user