From 1cdfbb08d8c13ca7f6bea96fccfbca36af603340 Mon Sep 17 00:00:00 2001 From: Luc Mcgrady Date: Thu, 25 Sep 2025 12:36:21 +0100 Subject: [PATCH] Added: Download endpoint --- controllers/ExportController.php | 26 ++++++++++++++++++++++++++ routes.php | 5 ++++- views/layout/default.blade.php | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 controllers/ExportController.php diff --git a/controllers/ExportController.php b/controllers/ExportController.php new file mode 100644 index 00000000..cb387b59 --- /dev/null +++ b/controllers/ExportController.php @@ -0,0 +1,26 @@ +withHeader('Content-Type', 'application/octet-stream'); + $response = $response->withHeader('Content-Disposition', 'attachment; filename="grocy.db"'); + $response = $response->withHeader('Content-Length', filesize($databasePath)); + $response->getBody()->write(file_get_contents($databasePath)); + return $response; + } + else + { + return $response->withStatus(404, 'Database file not found'); + } + } +} diff --git a/routes.php b/routes.php index 16ab88bd..e8b9272d 100644 --- a/routes.php +++ b/routes.php @@ -241,7 +241,10 @@ $app->group('/api', function (RouteCollectorProxy $group) // Calendar $group->get('/calendar/ical', '\Grocy\Controllers\CalendarApiController:Ical')->setName('calendar-ical'); - $group->get('/calendar/ical/sharing-link', '\Grocy\Controllers\CalendarApiController:IcalSharingLink'); + $group->get('/calendar/ical/sharing-link', '\Grocy\Controllers\CalendarApiController:IcalSharingLink');# + + // Export routes + $group->get('/export/sql', '\Grocy\Controllers\ExportController:DownloadSql'); })->add(JsonMiddleware::class); // Handle CORS preflight OPTIONS requests diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 7c28f713..e0cc3c8f 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -674,6 +674,8 @@ href="{{ $U('/api') }}"> {{ $__t('REST API browser') }}  {{ $__t('Barcode scanner testing') }} +  {{ $__t('Download database') }}