8b77acb828
- FreeTier.php: credit check/deduct/reset engine with hourly rate limit - bootstrap.php: dbnmDb() singleton, dbnToolsIsFreeTier(), credit gate helpers - index.php: store tier=free|approved in session from SSO JWT - All 7 API endpoints: credit gate (402/429) + X-Credits-Remaining header - layout.php: credit meta tag, JS balance var, Syttende Mai banner (05-17 only) - tools.js: credit badge in topbar, 402 modal, 429 toast, dbnUpdateCredits() - barnevernet.js + deep-research.js: wire 402/429 handling for NDJSON streams - tools.css: styles for credit badge, no-credits modal, rate-limit toast Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
817 B
PHP
25 lines
817 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../includes/bootstrap.php';
|
|
|
|
dbnToolsRequireMethod('POST');
|
|
dbnToolsRequireAuth();
|
|
$ftUid = dbnToolsFreeTierCheck('extract');
|
|
$ftRemaining = dbnToolsFreeTierDeduct($ftUid, 'extract');
|
|
if ($ftRemaining >= 0) { header('X-Credits-Remaining: ' . $ftRemaining); }
|
|
|
|
try {
|
|
if (empty($_FILES['file']) || !is_array($_FILES['file'])) {
|
|
dbnToolsError('No file was uploaded.', 422, 'missing_file');
|
|
}
|
|
|
|
$result = dbnToolsExtractUploadedFile($_FILES['file']);
|
|
dbnToolsRespond($result);
|
|
} catch (DbnToolsHttpException $e) {
|
|
dbnToolsError($e->getMessage(), $e->status, $e->errorCode, $e->extra);
|
|
} catch (Throwable $e) {
|
|
error_log('DBN extract error: ' . $e->getMessage());
|
|
dbnToolsError('Text extraction failed.', 500, 'extract_error');
|
|
}
|