mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-14 04:15:35 +00:00
fix(attachments): close the .txt gap in the parseability gate
Review follow-ups on the attachment gate. .txt was listed as parser-backed, but it has no parser — it *is* the plain-text fallthrough. That let it skip the content check, so renaming a video to notes.txt walked straight back into the bug the gate exists for (verified: 5132 chars of binary "extracted" and stored). The list is now exactly the file extractor's keys, .txt included in the content check like any other unparsed suffix, and the drift test asserts equality rather than containment. The sniff now recognises a UTF-16/32 BOM as text, so a Notepad "Unicode" .txt is not caught by the NUL-byte rule. The picker's accept filter listed parser-backed suffixes only, hiding .txt, .py and .log — files the gate reads happily — behind "All files". It now carries text/* as well, so it can never be narrower than what the upload accepts. A rejected batch carries one errors entry per file, but the non-200 branch applied the top-level message to every chip, so two files failing for two reasons both reported the first one. Reasons are now matched by upload_index, with the top-level message as fallback. _get_store_attachment_user_error no longer reads str(exc): the unsupported-type message is rebuilt from the filename, so no exception state can reach a response body (CodeQL py/stack-trace-exposure).
This commit is contained in:
1 parent
6d0319fb63
commit
f7cd94668f
9 files changed
+302
-49
No files matched your search
@@ -50,6 +50,7 @@ import {
|
||||
AUDIO_FILE_ACCEPT_ATTR,
|
||||
getFileExtension,
|
||||
parseUploadErrorMessage,
|
||||
parseUploadErrorsByIndex,
|
||||
partitionAttachmentFiles,
|
||||
} from '../constants/fileUpload';
|
||||
import { UserToolType } from '../settings/types';
|
||||
@@ -781,12 +782,20 @@ export default function MessageInput({
|
||||
}
|
||||
} else {
|
||||
console.error('Upload failed', status, xhr.responseText);
|
||||
const errorMessage = parseUploadErrorMessage(xhr.responseText);
|
||||
Object.values(indexToUiId).forEach((id) =>
|
||||
// Each file gets its own reason where the server sent one; the
|
||||
// top-level message is the fallback, not the answer for all of
|
||||
// them — a batch can fail two files for two different reasons.
|
||||
const fallbackMessage = parseUploadErrorMessage(xhr.responseText);
|
||||
const errorsByIndex = parseUploadErrorsByIndex(xhr.responseText);
|
||||
Object.entries(indexToUiId).forEach(([index, id]) =>
|
||||
dispatch(
|
||||
updateAttachment({
|
||||
id,
|
||||
updates: { status: 'failed', errorMessage },
|
||||
updates: {
|
||||
status: 'failed',
|
||||
errorMessage:
|
||||
errorsByIndex.get(Number(index)) ?? fallbackMessage,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user