Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions apps/web/components/add-document/file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -46,17 +46,31 @@ 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
}

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,
Expand Down Expand Up @@ -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">
Expand Down
Loading