mirror of
git://f0xx.org/ac/ac-ms-graphs
synced 2026-07-29 04:39:04 +03:00
Use read_crash_upload_body() so graph_upload matches CrashUploadClient Content-Encoding: gzip. Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/../../src/bootstrap.php';
|
|
|
|
$raw = read_crash_upload_body();
|
|
if ($raw === null) {
|
|
json_out(['ok' => false, 'error' => 'empty body'], 400);
|
|
}
|
|
if ($raw === false) {
|
|
json_out(['ok' => false, 'error' => 'invalid gzip body'], 400);
|
|
}
|
|
$data = json_decode($raw, true);
|
|
if (!is_array($data)) {
|
|
json_out(['ok' => false, 'error' => 'invalid json'], 400);
|
|
}
|
|
if ((int) ($data['schema_version'] ?? 0) !== 1) {
|
|
json_out(['ok' => false, 'error' => 'unsupported schema_version'], 400);
|
|
}
|
|
if (($data['ingest_kind'] ?? 'graph_session') !== 'graph_session') {
|
|
json_out(['ok' => false, 'error' => 'ingest_kind must be graph_session'], 400);
|
|
}
|
|
|
|
try {
|
|
GraphRepository::insertSession($data);
|
|
json_out(['ok' => true, 'session_id' => $data['session_id'] ?? null]);
|
|
} catch (InvalidArgumentException $e) {
|
|
json_out(['ok' => false, 'error' => $e->getMessage()], 400);
|
|
} catch (Throwable $e) {
|
|
error_log('graph upload: ' . $e->getMessage());
|
|
$out = ['ok' => false, 'error' => 'store_failed'];
|
|
if (cfg('debug')) {
|
|
$out['hint'] = $e->getMessage();
|
|
}
|
|
json_out($out, 500);
|
|
}
|