45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../config/config.php';
|
|
|
|
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
|
|
json_out(['ok' => false, 'error' => 'method_not_allowed'], 405);
|
|
}
|
|
|
|
$raw = (string)file_get_contents('php://input');
|
|
$data = json_decode($raw, true);
|
|
if (!is_array($data)) {
|
|
$data = [];
|
|
}
|
|
|
|
$event = (string)($data['event'] ?? '');
|
|
$allowedEvents = [
|
|
'push_received',
|
|
'notification_shown',
|
|
'notification_show_failed',
|
|
'notification_click',
|
|
'notification_close',
|
|
'client_log_failed',
|
|
];
|
|
|
|
if (!in_array($event, $allowedEvents, true)) {
|
|
json_out(['ok' => false, 'error' => 'invalid_event'], 422);
|
|
}
|
|
|
|
$endpoint = (string)($data['endpoint'] ?? '');
|
|
$meta = is_array($data['meta'] ?? null) ? $data['meta'] : [];
|
|
$context = [
|
|
'endpoint' => $endpoint,
|
|
'message' => mb_substr((string)($data['push_id'] ?? ''), 0, 255),
|
|
'push_id' => (string)($data['push_id'] ?? ''),
|
|
'tag' => (string)($data['tag'] ?? ''),
|
|
'visibility_state' => (string)($data['visibility_state'] ?? ''),
|
|
'client_count' => isset($data['client_count']) ? (int)$data['client_count'] : null,
|
|
'meta' => $meta,
|
|
];
|
|
|
|
push_log_event($event, $context);
|
|
|
|
json_out(['ok' => true]);
|