Log non JSON API responses
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
PLUGIN="u-navigator"
|
PLUGIN="u-navigator"
|
||||||
VERSION="2026.06.23.r006"
|
VERSION="2026.06.23.r007"
|
||||||
PKG_DIR="packages"
|
PKG_DIR="packages"
|
||||||
WORK_DIR=".plugin-build"
|
WORK_DIR=".plugin-build"
|
||||||
PKG_NAME="${PLUGIN}-${VERSION}.tgz"
|
PKG_NAME="${PLUGIN}-${VERSION}.tgz"
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -32,6 +32,14 @@ function unav_read_only(): bool {
|
|||||||
return getenv('U_NAV_READ_ONLY') === '1';
|
return getenv('U_NAV_READ_ONLY') === '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unav_function_available(string $name): bool {
|
||||||
|
if (!function_exists($name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$disabled = array_map('trim', explode(',', (string)ini_get('disable_functions')));
|
||||||
|
return !in_array($name, $disabled, true);
|
||||||
|
}
|
||||||
|
|
||||||
function unav_json($payload, int $status = 200): void {
|
function unav_json($payload, int $status = 200): void {
|
||||||
http_response_code($status);
|
http_response_code($status);
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|||||||
@@ -35,11 +35,22 @@ unav_job_write($job);
|
|||||||
|
|
||||||
$worker = __DIR__ . '/job_worker.php';
|
$worker = __DIR__ . '/job_worker.php';
|
||||||
$php = is_executable('/usr/bin/php') ? '/usr/bin/php' : (PHP_BINARY ?: 'php');
|
$php = is_executable('/usr/bin/php') ? '/usr/bin/php' : (PHP_BINARY ?: 'php');
|
||||||
if (function_exists('exec') && is_file($worker)) {
|
$started = false;
|
||||||
exec(escapeshellarg($php) . ' ' . escapeshellarg($worker) . ' ' . escapeshellarg($id) . ' > /dev/null 2>&1 &');
|
|
||||||
} else {
|
if (unav_function_available('exec') && is_file($worker)) {
|
||||||
require $worker;
|
try {
|
||||||
|
$exitCode = 0;
|
||||||
|
@exec(escapeshellarg($php) . ' ' . escapeshellarg($worker) . ' ' . escapeshellarg($id) . ' > /dev/null 2>&1 &', $output, $exitCode);
|
||||||
|
$started = ($exitCode === 0);
|
||||||
|
} catch (Throwable $error) {
|
||||||
|
$started = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$started) {
|
||||||
|
require_once $worker;
|
||||||
unav_run_job($id);
|
unav_run_job($id);
|
||||||
|
$job = unav_job_read($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
unav_json($job, 202);
|
unav_json($job, 202);
|
||||||
|
|||||||
+18
-4
@@ -826,10 +826,17 @@ function startResizeWindow(event, win) {
|
|||||||
|
|
||||||
async function api(url, options) {
|
async function api(url, options) {
|
||||||
const response = await fetchChecked(url, options);
|
const response = await fetchChecked(url, options);
|
||||||
|
const text = await response.text();
|
||||||
try {
|
try {
|
||||||
return await response.json();
|
return JSON.parse(text);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
recordDebug('api.json.error', { url, error: serializeError(error) });
|
recordDebug('api.json.error', {
|
||||||
|
url,
|
||||||
|
status: response.status,
|
||||||
|
contentType: response.headers.get('content-type'),
|
||||||
|
body: text.slice(0, 2000),
|
||||||
|
error: serializeError(error)
|
||||||
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -837,12 +844,19 @@ async function api(url, options) {
|
|||||||
async function fetchChecked(url, options) {
|
async function fetchChecked(url, options) {
|
||||||
recordDebug('fetch.request', { url, method: options?.method || 'GET' });
|
recordDebug('fetch.request', { url, method: options?.method || 'GET' });
|
||||||
const response = await fetch(url, options);
|
const response = await fetch(url, options);
|
||||||
recordDebug('fetch.response', { url, status: response.status, ok: response.ok });
|
recordDebug('fetch.response', {
|
||||||
|
url,
|
||||||
|
status: response.status,
|
||||||
|
ok: response.ok,
|
||||||
|
contentType: response.headers.get('content-type')
|
||||||
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
let message = `${response.status} ${response.statusText}`;
|
let message = `${response.status} ${response.statusText}`;
|
||||||
|
const text = await response.text();
|
||||||
try {
|
try {
|
||||||
message = (await response.json()).error || message;
|
message = JSON.parse(text).error || message;
|
||||||
} catch {}
|
} catch {}
|
||||||
|
recordDebug('fetch.error.body', { url, status: response.status, body: text.slice(0, 2000) });
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE PLUGIN [
|
<!DOCTYPE PLUGIN [
|
||||||
<!ENTITY name "u-navigator">
|
<!ENTITY name "u-navigator">
|
||||||
<!ENTITY author "michael">
|
<!ENTITY author "michael">
|
||||||
<!ENTITY version "2026.06.23.r006">
|
<!ENTITY version "2026.06.23.r007">
|
||||||
<!ENTITY package "&name;-&version;.tgz">
|
<!ENTITY package "&name;-&version;.tgz">
|
||||||
]>
|
]>
|
||||||
<PLUGIN name="&name;" author="&author;" version="&version;" pluginURL="https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/u-navigator.plg">
|
<PLUGIN name="&name;" author="&author;" version="&version;" pluginURL="https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/u-navigator.plg">
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<FILE Name="/boot/config/plugins/&name;/&package;">
|
<FILE Name="/boot/config/plugins/&name;/&package;">
|
||||||
<URL>https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package;</URL>
|
<URL>https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package;</URL>
|
||||||
<MD5>6079415588844c2e4a3f8aa43f949bd4</MD5>
|
<MD5>c9e2b618f5907747315c5f17e80b132f</MD5>
|
||||||
</FILE>
|
</FILE>
|
||||||
|
|
||||||
<FILE Run="/bin/bash">
|
<FILE Run="/bin/bash">
|
||||||
|
|||||||
Reference in New Issue
Block a user