fipamo/app/Http/Controllers/API/SettingsAPIController.php
ro f8005aa60d
turned on backups
ported over the backup functionality from the old build to the new while
making  few tweaks

instead of packaging up all files in the site to create massive zip
files, now a list of files is created for the user and blog directories
that the system will use to download and put them in the appropriate
directories, resulting in a such slimmer backup file.

archiving images my be added at a later date, but will be kept seperate
from the current back up process
2024-04-05 12:29:38 -06:00

65 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\SettingsService;
use App\Services\RenderService;
use App\Services\MaintenanceService;
use App\Services\AuthService;
class SettingsAPIController extends Controller
{
protected $settings;
protected $render;
protected $mainteance;
protected $auth;
public function __construct(
SettingsService $settingsService,
RenderService $renderService,
MaintenanceService $maintenanceService,
AuthService $authService
) {
$this->settings = $settingsService;
$this->render = $renderService;
$this->maintenance = $maintenanceService;
$this->auth = $authService;
}
public function publish(Request $request)
{
$result = $this->render->publishAll();
return response()->json($result)->header('Content-Type', 'application/json');
}
public function sync(Request $request)
{
$body = json_decode($request->getContent());
$result = $this->settings->sync($body);
return response()->json($result)->header('Content-Type', 'application/json');
}
public function navSync(Request $request)
{
$body = json_decode($request->getContent());
$result = $this->settings->navSync($body);
return response()->json($result)->header('Content-Type', 'application/json');
}
public function createBackup(Request $request)
{
return response()->json($this->maintenance->createBackup())->header('Content-Type', 'application/json');
}
public function downloadBackup(Request $request)
{
if ($this->auth::status()) {
$latest = $this->settings->getGlobal()['last_backup'];
$file = 'backup-' . $latest . '.zip';
return response()->download('../content/backups/' . $file, $file, ['Content-Type: application/zip']);
}
}
}