mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
fix(mcp): use function declarations in upload widget
Address Graphite style review on Upload.tsx. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
f52da0f6c5
commit
521db2b615
1 changed files with 6 additions and 5 deletions
|
|
@ -39,14 +39,15 @@ const MAX_UPLOAD_BYTES = Math.floor(
|
|||
((TRANSPORT_MESSAGE_LIMIT_BYTES - ENVELOPE_ALLOWANCE_BYTES) * 3) / 4,
|
||||
)
|
||||
|
||||
const FILE_TOO_LARGE_MESSAGE = (size: number) =>
|
||||
`This file is ${formatFileSize(size)}. The maximum upload size is ${formatFileSize(MAX_UPLOAD_BYTES)} — please choose a smaller file.`
|
||||
function fileTooLargeMessage(size: number): string {
|
||||
return `This file is ${formatFileSize(size)}. The maximum upload size is ${formatFileSize(MAX_UPLOAD_BYTES)} — please choose a smaller file.`
|
||||
}
|
||||
|
||||
// The transport-level 413 surfaces as an opaque error string; translate it
|
||||
// so the user sees the size limit instead of a generic failure.
|
||||
function friendlyUploadError(raw: string, fileSize: number): string {
|
||||
if (/413|too large|payload/i.test(raw)) {
|
||||
return FILE_TOO_LARGE_MESSAGE(fileSize)
|
||||
return fileTooLargeMessage(fileSize)
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
|
@ -61,13 +62,13 @@ export function Upload({ activeTag, writableTags, onAdvance, onError }: Props) {
|
|||
)
|
||||
const [uploading, setUploading] = useState(false)
|
||||
|
||||
const handleFileSelect = (selected: File) => {
|
||||
function handleFileSelect(selected: File) {
|
||||
if (selected.size > MAX_UPLOAD_BYTES) {
|
||||
log(
|
||||
"warning",
|
||||
`[upload] rejected oversized file: ${selected.name} (${selected.size}B > ${MAX_UPLOAD_BYTES}B)`,
|
||||
)
|
||||
setFileError(FILE_TOO_LARGE_MESSAGE(selected.size))
|
||||
setFileError(fileTooLargeMessage(selected.size))
|
||||
setFile(null)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue