parent
9e88c45051
commit
78e60e22d2
|
|
@ -214,7 +214,7 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
|
|||
data: s,
|
||||
preview: s,
|
||||
type: 'url',
|
||||
name: s.substring(s.lastIndexOf('/') + 1)
|
||||
name: s ? s.substring(s.lastIndexOf('/') + 1) : ''
|
||||
}
|
||||
setPreviews((prevPreviews) => [...prevPreviews, upload])
|
||||
})
|
||||
|
|
@ -222,14 +222,14 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
|
|||
item.getAsString((s) => {
|
||||
if (s.indexOf('href') === -1) return
|
||||
//extract href
|
||||
let start = s.substring(s.indexOf('href') + 6)
|
||||
let start = s ? s.substring(s.indexOf('href') + 6) : ''
|
||||
let hrefStr = start.substring(0, start.indexOf('"'))
|
||||
|
||||
let upload = {
|
||||
data: hrefStr,
|
||||
preview: hrefStr,
|
||||
type: 'url',
|
||||
name: hrefStr.substring(hrefStr.lastIndexOf('/') + 1)
|
||||
name: hrefStr ? hrefStr.substring(hrefStr.lastIndexOf('/') + 1) : ''
|
||||
}
|
||||
setPreviews((prevPreviews) => [...prevPreviews, upload])
|
||||
})
|
||||
|
|
@ -282,7 +282,7 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
|
|||
if (pos === -1) {
|
||||
mimeType = blob.type
|
||||
} else {
|
||||
mimeType = blob.type.substring(0, pos)
|
||||
mimeType = blob.type ? blob.type.substring(0, pos) : ''
|
||||
}
|
||||
// read blob and add to previews
|
||||
const reader = new FileReader()
|
||||
|
|
@ -598,6 +598,26 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
|
|||
}
|
||||
}
|
||||
|
||||
const getLabel = (URL, source) => {
|
||||
if (URL && typeof URL === 'object') {
|
||||
if (URL.pathname && typeof URL.pathname === 'string') {
|
||||
if (URL.pathname.substring(0, 15) === '/') {
|
||||
return URL.host || ''
|
||||
} else {
|
||||
return `${URL.pathname.substring(0, 15)}...`
|
||||
}
|
||||
} else if (URL.host) {
|
||||
return URL.host
|
||||
}
|
||||
}
|
||||
|
||||
if (source && source.pageContent && typeof source.pageContent === 'string') {
|
||||
return `${source.pageContent.substring(0, 15)}...`
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
const downloadFile = async (fileAnnotation) => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
|
|
@ -1180,13 +1200,7 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
|
|||
<Chip
|
||||
size='small'
|
||||
key={index}
|
||||
label={
|
||||
URL
|
||||
? URL.pathname.substring(0, 15) === '/'
|
||||
? URL.host
|
||||
: `${URL.pathname.substring(0, 15)}...`
|
||||
: `${source.pageContent.substring(0, 15)}...`
|
||||
}
|
||||
label={getLabel(URL, source) || ''}
|
||||
component='a'
|
||||
sx={{ mr: 1, mb: 1 }}
|
||||
variant='outlined'
|
||||
|
|
@ -1390,13 +1404,7 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
|
|||
<Chip
|
||||
size='small'
|
||||
key={index}
|
||||
label={
|
||||
URL
|
||||
? URL.pathname.substring(0, 15) === '/'
|
||||
? URL.host
|
||||
: `${URL.pathname.substring(0, 15)}...`
|
||||
: `${source.pageContent.substring(0, 15)}...`
|
||||
}
|
||||
label={getLabel(URL, source) || ''}
|
||||
component='a'
|
||||
sx={{ mr: 1, mb: 1 }}
|
||||
variant='outlined'
|
||||
|
|
|
|||
Loading…
Reference in New Issue