feat: document & audio corpus picker for all tools
- Add "Select from My Docs" button to all text tool forms; free-tier users see an upgrade modal, paid (CaveauAI) users get a searchable multi-select modal backed by /api/dashboard/documents.php - Add "Select from My Audio" picker on Transcribe with single-select and a "Save to My Audio" button for persisting uploaded clips - New PHP helpers in bootstrap.php: dbnToolsFetchDocChunks, dbnToolsClientIdFromSession, dbnToolsInjectDocContent - timeline, ask, redact APIs prepend selected document content (fetched from client_chunks SQL) before the textarea text - api/dashboard/audio-upload.php stores audio files on server and creates a client_documents row with source_type='audio' - api/transcribe.php falls back to stored audio via audio_doc_id POST field when no file is uploaded - api/dashboard/documents.php supports ?source_type= filter - tools.js: doc_ids added to JSON payload; stored-audio transcribe path - New assets/css/doc-picker.css, assets/js/doc-picker.js - SQL migration: scripts/sql/audio_docs_column.sql Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+39
-9
@@ -32,17 +32,47 @@ $postModel = in_array($_POST['post_model'] ?? '', $allowedPostModels, true)
|
||||
? (string)($_POST['post_model'] ?? '')
|
||||
: '';
|
||||
|
||||
// ── Validate upload ───────────────────────────────────────────────────────────
|
||||
// ── Validate upload (or load from stored audio corpus) ────────────────────────
|
||||
|
||||
$storedAudioTmp = null;
|
||||
|
||||
if (empty($_FILES['audio']) || $_FILES['audio']['error'] !== UPLOAD_ERR_OK) {
|
||||
$code = $_FILES['audio']['error'] ?? -1;
|
||||
$map = [
|
||||
UPLOAD_ERR_INI_SIZE => 'File exceeds server upload limit.',
|
||||
UPLOAD_ERR_FORM_SIZE => 'File exceeds form size limit.',
|
||||
UPLOAD_ERR_PARTIAL => 'File was only partially uploaded.',
|
||||
UPLOAD_ERR_NO_FILE => 'No audio file received.',
|
||||
];
|
||||
dbnToolsError($map[$code] ?? "Upload error (code {$code}).", 400, 'upload_error');
|
||||
// Check if the user picked a previously saved audio document
|
||||
$audioDocId = (int)($_POST['audio_doc_id'] ?? 0);
|
||||
if ($audioDocId > 0) {
|
||||
$clientId = dbnToolsClientIdFromSession();
|
||||
if ($clientId <= 0) {
|
||||
dbnToolsError('No audio file received and no valid session for stored audio.', 400, 'upload_error');
|
||||
}
|
||||
$db = dbnToolsDb();
|
||||
$row = $db->prepare(
|
||||
'SELECT audio_storage_path, title FROM client_documents
|
||||
WHERE id = ? AND client_id = ? AND source_type = ? AND status = ? LIMIT 1'
|
||||
);
|
||||
$row->execute([$audioDocId, $clientId, 'audio', 'ready']);
|
||||
$audioRow = $row->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$audioRow || empty($audioRow['audio_storage_path']) || !is_readable((string)$audioRow['audio_storage_path'])) {
|
||||
dbnToolsError('Stored audio file not found or not readable.', 404, 'audio_not_found');
|
||||
}
|
||||
// Synthesise a $_FILES-compatible entry pointing at the stored file
|
||||
$storedAudioTmp = $audioRow['audio_storage_path'];
|
||||
$_FILES['audio'] = [
|
||||
'name' => basename($storedAudioTmp),
|
||||
'tmp_name' => $storedAudioTmp,
|
||||
'error' => UPLOAD_ERR_OK,
|
||||
'size' => (int)filesize($storedAudioTmp),
|
||||
'type' => mime_content_type($storedAudioTmp) ?: 'application/octet-stream',
|
||||
];
|
||||
} else {
|
||||
$code = $_FILES['audio']['error'] ?? -1;
|
||||
$map = [
|
||||
UPLOAD_ERR_INI_SIZE => 'File exceeds server upload limit.',
|
||||
UPLOAD_ERR_FORM_SIZE => 'File exceeds form size limit.',
|
||||
UPLOAD_ERR_PARTIAL => 'File was only partially uploaded.',
|
||||
UPLOAD_ERR_NO_FILE => 'No audio file received.',
|
||||
];
|
||||
dbnToolsError($map[$code] ?? "Upload error (code {$code}).", 400, 'upload_error');
|
||||
}
|
||||
}
|
||||
|
||||
$file = $_FILES['audio'];
|
||||
|
||||
Reference in New Issue
Block a user