All checks were successful
Deploy / Build and Deploy to Production (push) Successful in 15s
Reorganize routes following design-to-pack pattern: - routes/markers.php: CRUD operations for markers - routes/position.php: Position update (single mode) - routes/image.php: Image capture and regeneration flag management Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
83 lines
2.2 KiB
PHP
83 lines
2.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Position Update Route
|
|
* PATCH route for updating page position (single mode)
|
|
*/
|
|
|
|
return [
|
|
'pattern' => 'map-editor/pages/(:all)/position',
|
|
'method' => 'PATCH',
|
|
'auth' => false,
|
|
'action' => function (string $pageId) {
|
|
try {
|
|
$user = kirby()->user();
|
|
|
|
if (!$user && !kirby()->option('debug', false)) {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Unauthorized',
|
|
'code' => 401
|
|
];
|
|
}
|
|
|
|
$page = kirby()->page($pageId);
|
|
if (!$page) {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Page not found',
|
|
'code' => 404
|
|
];
|
|
}
|
|
|
|
if (!$page->permissions()->can('update')) {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Forbidden',
|
|
'code' => 403
|
|
];
|
|
}
|
|
|
|
$data = kirby()->request()->data();
|
|
|
|
if (!isset($data['latitude']) || !isset($data['longitude'])) {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Latitude and longitude are required',
|
|
'code' => 400
|
|
];
|
|
}
|
|
|
|
$lat = (float) $data['latitude'];
|
|
$lon = (float) $data['longitude'];
|
|
|
|
if ($lat < -90 || $lat > 90 || $lon < -180 || $lon > 180) {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Invalid coordinates',
|
|
'code' => 400
|
|
];
|
|
}
|
|
|
|
$page->update([
|
|
'latitude' => $lat,
|
|
'longitude' => $lon
|
|
]);
|
|
|
|
return [
|
|
'status' => 'success',
|
|
'data' => [
|
|
'latitude' => $lat,
|
|
'longitude' => $lon
|
|
]
|
|
];
|
|
|
|
} catch (Exception $e) {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => $e->getMessage(),
|
|
'code' => 500
|
|
];
|
|
}
|
|
}
|
|
];
|