mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 20:36:15 +02:00
Added: Download endpoint
This commit is contained in:
parent
8129b6b60b
commit
1cdfbb08d8
26
controllers/ExportController.php
Normal file
26
controllers/ExportController.php
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Grocy\Controllers;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
|
||||||
|
class ExportController extends BaseController
|
||||||
|
{
|
||||||
|
public function DownloadSql(Request $request, Response $response, array $args) {
|
||||||
|
$databasePath = GROCY_DATAPATH . '/grocy.db';
|
||||||
|
|
||||||
|
if (file_exists($databasePath))
|
||||||
|
{
|
||||||
|
$response = $response->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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -241,7 +241,10 @@ $app->group('/api', function (RouteCollectorProxy $group)
|
||||||
|
|
||||||
// Calendar
|
// Calendar
|
||||||
$group->get('/calendar/ical', '\Grocy\Controllers\CalendarApiController:Ical')->setName('calendar-ical');
|
$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);
|
})->add(JsonMiddleware::class);
|
||||||
|
|
||||||
// Handle CORS preflight OPTIONS requests
|
// Handle CORS preflight OPTIONS requests
|
||||||
|
|
|
||||||
|
|
@ -674,6 +674,8 @@
|
||||||
href="{{ $U('/api') }}"><i class="fa-solid fa-fw fa-book"></i> {{ $__t('REST API browser') }}</a>
|
href="{{ $U('/api') }}"><i class="fa-solid fa-fw fa-book"></i> {{ $__t('REST API browser') }}</a>
|
||||||
<a class="dropdown-item discrete-link"
|
<a class="dropdown-item discrete-link"
|
||||||
href="{{ $U('/barcodescannertesting') }}"><i class="fa-solid fa-fw fa-barcode"></i> {{ $__t('Barcode scanner testing') }}</a>
|
href="{{ $U('/barcodescannertesting') }}"><i class="fa-solid fa-fw fa-barcode"></i> {{ $__t('Barcode scanner testing') }}</a>
|
||||||
|
<a class="dropdown-item discrete-link"
|
||||||
|
href="{{ $U('/api/export/sql') }}"><i class="fa-solid fa-fw fa-database"></i> {{ $__t('Download database') }}</a>
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
<a class="dropdown-item discrete-link show-as-dialog-link"
|
<a class="dropdown-item discrete-link show-as-dialog-link"
|
||||||
data-dialog-type="wider"
|
data-dialog-type="wider"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user