Skip to content

Commit

Permalink
fix: support releative path (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
thucpn authored Nov 22, 2024
1 parent 00317dc commit 22e25b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-seals-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@llamaindex/chat-ui': patch
---

fix: support releative URLs in document viewer
10 changes: 2 additions & 8 deletions packages/chat-ui/src/widgets/document-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function DocumentInfo({
onRemove?: () => void
}) {
const { url, sources } = document
const fileName = urlToFileName(url)
const urlParts = url.split('/')
const fileName = urlParts.length > 0 ? urlParts[urlParts.length - 1] : url
const fileExt = fileName?.split('.').pop() as DocumentFileType | undefined

const previewFile = {
Expand Down Expand Up @@ -191,10 +192,3 @@ function DocumentPreviewCard(props: {
function inKB(size: number) {
return Math.round((size / 1024) * 10) / 10
}

function urlToFileName(url: string) {
const urlObj = new URL(url)
const urlParts = urlObj.pathname.split('/')
const fileName = urlParts.length > 0 ? urlParts[urlParts.length - 1] : url
return fileName
}

0 comments on commit 22e25b0

Please sign in to comment.