diff --git a/web/hooks/usePath.ts b/web/hooks/usePath.ts
index afdafe11f..315072000 100644
--- a/web/hooks/usePath.ts
+++ b/web/hooks/usePath.ts
@@ -1,6 +1,8 @@
-import { openFileExplorer, joinPath, baseName } from '@janhq/core'
+import { openFileExplorer, joinPath, baseName, fs } from '@janhq/core'
import { useAtomValue } from 'jotai'
+import { getFileInfo } from '@/utils/file'
+
import { janDataFolderPathAtom } from '@/helpers/atoms/AppConfig.atom'
import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
import { selectedModelAtom } from '@/helpers/atoms/Model.atom'
@@ -47,13 +49,23 @@ export const usePath = () => {
const onViewFile = async (id: string) => {
if (!activeThread) return
- let filePath = undefined
-
id = await baseName(id)
- filePath = await joinPath(['threads', `${activeThread.id}/files`, `${id}`])
- if (!filePath) return
- const fullPath = await joinPath([janDataFolderPath, filePath])
- openFileExplorer(fullPath)
+
+ // New ID System
+ if (!id.startsWith('file-')) {
+ const threadFilePath = await joinPath([
+ janDataFolderPath,
+ 'threads',
+ `${activeThread.id}/files`,
+ id,
+ ])
+ openFileExplorer(threadFilePath)
+ } else {
+ id = id.split('.')[0]
+ const fileName = (await getFileInfo(id)).filename
+ const filesPath = await joinPath([janDataFolderPath, 'files', fileName])
+ openFileExplorer(filesPath)
+ }
}
const onViewFileContainer = async () => {
diff --git a/web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx b/web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx
index b3246a26b..4f00bbc59 100644
--- a/web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx
+++ b/web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx
@@ -126,7 +126,7 @@ const ChatInput = () => {
const renderPreview = (fileUpload: any) => {
if (fileUpload) {
if (fileUpload.type === 'image') {
- return
+ return
} else {
return
}
diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/DocMessage.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/DocMessage.tsx
index 69d61d0d5..0051f832e 100644
--- a/web/screens/Thread/ThreadCenterPanel/TextMessage/DocMessage.tsx
+++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/DocMessage.tsx
@@ -1,44 +1,39 @@
-import { memo } from 'react'
-
-import { Tooltip } from '@janhq/joi'
-
-import { FolderOpenIcon } from 'lucide-react'
+import { memo, useEffect, useState } from 'react'
import { usePath } from '@/hooks/usePath'
-import { toGibibytes } from '@/utils/converter'
-import { openFileTitle } from '@/utils/titleUtils'
+import { getFileInfo } from '@/utils/file'
import Icon from '../FileUploadPreview/Icon'
-const DocMessage = ({ id, name }: { id: string; name?: string }) => {
- const { onViewFile, onViewFileContainer } = usePath()
+const DocMessage = ({ id }: { id: string }) => {
+ const { onViewFile } = usePath()
+ const [fileInfo, setFileInfo] = useState<
+ { filename: string; id: string } | undefined
+ >()
+ useEffect(() => {
+ if (!fileInfo) {
+ getFileInfo(id).then((data) => {
+ setFileInfo(data)
+ })
+ }
+ }, [fileInfo, id])
return (
onViewFile(`${id}.pdf`)}
/>
-
-
-
- }
- content={
{openFileTitle()}}
- />
+
-
- {name?.replaceAll(/[-._]/g, ' ')}
+
+ {fileInfo?.filename}
- {/*
- {toGibibytes(Number(size))}
-
*/}
+
+ {fileInfo?.id ?? id}
+
)
diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/ImageMessage.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/ImageMessage.tsx
index e83d35fbb..14041721b 100644
--- a/web/screens/Thread/ThreadCenterPanel/TextMessage/ImageMessage.tsx
+++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/ImageMessage.tsx
@@ -1,34 +1,11 @@
import { memo } from 'react'
-import { Tooltip } from '@janhq/joi'
-
-import { FolderOpenIcon } from 'lucide-react'
-
-import { usePath } from '@/hooks/usePath'
-
-import { openFileTitle } from '@/utils/titleUtils'
-
import { RelativeImage } from '../TextMessage/RelativeImage'
const ImageMessage = ({ image }: { image: string }) => {
- const { onViewFile, onViewFileContainer } = usePath()
-
return (
-
-
- onViewFile(image)} />
-
-
-
-
- }
- content={{openFileTitle()}}
- />
+
+
)
}
diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/RelativeImage.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/RelativeImage.tsx
index 72d2a9365..bfd13b0ef 100644
--- a/web/screens/Thread/ThreadCenterPanel/TextMessage/RelativeImage.tsx
+++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/RelativeImage.tsx
@@ -7,7 +7,7 @@ export const RelativeImage = ({
onClick,
}: {
src: string
- onClick: () => void
+ onClick?: () => void
}) => {
const [path, setPath] = useState('')
@@ -17,9 +17,12 @@ export const RelativeImage = ({
})
}, [])
return (
-