From f9441733fd690090ecdc4160e5bd4d77da9782e1 Mon Sep 17 00:00:00 2001 From: Gogs Date: Tue, 7 Jul 2026 12:49:25 +0200 Subject: [PATCH] Cleanup Phase 1 --- app/public/api/live-now.php | 25 +++++++------------------ app/public/index.php | 10 +--------- app/src/ApiResponse.php | 25 +++++++++++++++++++++++++ app/src/Http/ApiResponse.php | 25 +++++++++++++++++++++++++ app/src/bootstrap.php | 17 +++++++++++++++++ 5 files changed, 75 insertions(+), 27 deletions(-) create mode 100644 app/src/ApiResponse.php create mode 100644 app/src/Http/ApiResponse.php create mode 100644 app/src/bootstrap.php diff --git a/app/public/api/live-now.php b/app/public/api/live-now.php index fbaaedd..ea5d99b 100644 --- a/app/public/api/live-now.php +++ b/app/public/api/live-now.php @@ -1,9 +1,6 @@ get('timezone', 'Europe/Vienna'); - $cacheFile = '/var/www/cache/guide.json'; if (!file_exists($cacheFile)) { - http_response_code(404); - echo json_encode([ - 'error' => 'guide.json not found', - ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); - exit; + ApiResponse::error('guide.json not found', 404); } $data = json_decode(file_get_contents($cacheFile), true); if (!is_array($data)) { - http_response_code(500); - echo json_encode([ - 'error' => 'guide.json is invalid', - ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); - exit; + ApiResponse::error('guide.json is invalid', 500); } $service = new ProgrammeService($timezone); @@ -37,8 +25,9 @@ $items = $service->getCurrentProgrammes($data, $config); $now = new DateTimeImmutable('now', new DateTimeZone($timezone)); -echo json_encode([ - 'now' => $now->format(DateTimeInterface::ATOM), +ApiResponse::json([ + 'ok' => true, 'timestamp' => $now->getTimestamp(), + 'datetime' => $now->format(DateTimeInterface::ATOM), 'items' => $items, -], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); +]); diff --git a/app/public/index.php b/app/public/index.php index 60c2cf3..5c97869 100644 --- a/app/public/index.php +++ b/app/public/index.php @@ -1,14 +1,6 @@ false, + 'error' => $message, + ], $statusCode); + } +} diff --git a/app/src/Http/ApiResponse.php b/app/src/Http/ApiResponse.php new file mode 100644 index 0000000..4ecee58 --- /dev/null +++ b/app/src/Http/ApiResponse.php @@ -0,0 +1,25 @@ + false, + 'error' => $message, + ], $statusCode); + } +} diff --git a/app/src/bootstrap.php b/app/src/bootstrap.php new file mode 100644 index 0000000..c78295a --- /dev/null +++ b/app/src/bootstrap.php @@ -0,0 +1,17 @@ +