designtopack/public/site/config/routes/save-file.php
2024-10-08 17:31:18 +02:00

25 lines
No EOL
545 B
PHP

<?php
return [
'pattern' => '(:all)save-file.json',
'method' => 'POST',
'action' => function () {
$json = file_get_contents('php://input');
$data = json_decode($json);
$page = page($data->pageUri);
$file = $page->file($data->fileName);
$newProperties = [];
foreach ($data->properties as $incomingProperty) {
$newProperties[$incomingProperty->name] = $incomingProperty->value;
}
$newFile = $file->update($newProperties);
return json_encode($newProperties);
}
];