mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
ENG-712: Accept JSON uploads in Nova + fix file-size display (#1047)
This commit is contained in:
parent
f5383b6671
commit
fdd966f20e
1 changed files with 16 additions and 2 deletions
|
|
@ -8,7 +8,7 @@ import { useHotkeys } from "react-hotkeys-hook"
|
|||
import { toast } from "sonner"
|
||||
|
||||
export const FILE_ACCEPT =
|
||||
"image/*,.pdf,.doc,.docx,.xls,.xlsx,.csv,.txt,.md,.mdx,text/markdown"
|
||||
"image/*,.pdf,.doc,.docx,.xls,.xlsx,.csv,.txt,.md,.mdx,.json,text/markdown,application/json"
|
||||
|
||||
export type FileQueueItemStatus = "pending" | "uploading" | "success" | "error"
|
||||
|
||||
|
|
@ -46,10 +46,12 @@ function isAcceptedFile(file: File): boolean {
|
|||
".txt",
|
||||
".md",
|
||||
".mdx",
|
||||
".json",
|
||||
])
|
||||
if (allowedExt.has(ext)) return true
|
||||
if (file.type.startsWith("image/")) return true
|
||||
if (file.type === "text/markdown") return true
|
||||
if (file.type === "application/json") return true
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +59,18 @@ function fileQueueKey(file: File): string {
|
|||
return `${file.name}:${file.size}:${file.lastModified}`
|
||||
}
|
||||
|
||||
function formatFileSize(bytes: number): string {
|
||||
if (bytes < 1024) return `${bytes} B`
|
||||
const units = ["KB", "MB", "GB", "TB"]
|
||||
let size = bytes / 1024
|
||||
let i = 0
|
||||
while (size >= 1024 && i < units.length - 1) {
|
||||
size /= 1024
|
||||
i++
|
||||
}
|
||||
return `${size.toFixed(size < 10 ? 1 : 0)} ${units[i]}`
|
||||
}
|
||||
|
||||
export function FileContent({
|
||||
data,
|
||||
onDataChange,
|
||||
|
|
@ -284,7 +298,7 @@ export function FileContent({
|
|||
{item.file.name}
|
||||
</p>
|
||||
<p className="text-[#737373] text-xs">
|
||||
{(item.file.size / 1024 / 1024).toFixed(2)} MB
|
||||
{formatFileSize(item.file.size)}
|
||||
</p>
|
||||
{item.status === "error" && item.errorMessage ? (
|
||||
<p className="text-red-400 text-xs mt-1 flex items-center gap-1">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue