Add premium My Case MVP

This commit is contained in:
2026-05-23 10:17:34 +02:00
parent e0aeefc73e
commit 83fc71414f
33 changed files with 1275 additions and 148 deletions
+53
View File
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../includes/bootstrap.php';
require_once __DIR__ . '/../../includes/CaseResults.php';
dbnToolsRequireMethod('POST');
dbnToolsRequireAuth();
if (!dbnToolsIsFreeTier()) {
dbnToolsError('Saved analyses are SSO-only.', 403, 'sso_only');
}
$userId = (int)($_SESSION['dbn_tools_sso_uid'] ?? 0);
if ($userId <= 0) {
dbnToolsError('Missing user id.', 401, 'no_user');
}
$input = dbnToolsJsonInput(4000);
$action = (string)($input['action'] ?? '');
$id = (int)($input['id'] ?? 0);
if ($id <= 0) {
dbnToolsError('Missing result id.', 422, 'missing_id');
}
switch ($action) {
case 'pin':
$pinned = CaseResults::togglePin($userId, $id);
if ($pinned === null) {
dbnToolsError('Result not found.', 404, 'not_found');
}
dbnToolsRespond(['ok' => true, 'pinned' => $pinned]);
break;
case 'delete':
if (!CaseResults::softDelete($userId, $id)) {
dbnToolsError('Result not found or already deleted.', 404, 'not_found');
}
dbnToolsRespond(['ok' => true]);
break;
case 'rename':
$title = (string)($input['title'] ?? '');
if (!CaseResults::updateTitle($userId, $id, $title)) {
dbnToolsError('Could not rename — empty title or result not found.', 422, 'rename_failed');
}
dbnToolsRespond(['ok' => true]);
break;
default:
dbnToolsError('Unknown action.', 422, 'unknown_action');
}
+51
View File
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../includes/bootstrap.php';
require_once __DIR__ . '/../../includes/CaseResults.php';
dbnToolsRequireMethod('GET');
dbnToolsRequireAuth();
if (!dbnToolsIsFreeTier()) {
http_response_code(403);
exit('Saved analyses are SSO-only.');
}
$userId = (int)($_SESSION['dbn_tools_sso_uid'] ?? 0);
$id = (int)($_GET['id'] ?? 0);
if ($userId <= 0 || $id <= 0) {
http_response_code(404);
exit('Not found.');
}
$result = CaseResults::get($userId, $id);
if (!$result) {
http_response_code(404);
exit('Not found.');
}
$filename = sprintf(
'dbn-%s-%d-%s.json',
$result['tool'],
$id,
date('Ymd-His', strtotime((string)$result['created_at']))
);
header('Content-Type: application/json; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: no-store');
echo json_encode([
'id' => (int)$result['id'],
'tool' => $result['tool'],
'title' => $result['title'],
'created_at' => $result['created_at'],
'model' => $result['model'],
'latency_ms' => $result['latency_ms'],
'used_case_context' => (bool)$result['used_case_context'],
'case_doc_ids' => $result['case_doc_ids'],
'input' => $result['input_payload'],
'output' => $result['output_payload'],
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);