@@ -214,22 +214,22 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
214
214
data : s ,
215
215
preview : s ,
216
216
type : 'url' ,
217
- name : s . substring ( s . lastIndexOf ( '/' ) + 1 )
217
+ name : s ? s . substring ( s . lastIndexOf ( '/' ) + 1 ) : ''
218
218
}
219
219
setPreviews ( ( prevPreviews ) => [ ...prevPreviews , upload ] )
220
220
} )
221
221
} else if ( item . kind === 'string' && item . type . match ( '^text/html' ) ) {
222
222
item . getAsString ( ( s ) => {
223
223
if ( s . indexOf ( 'href' ) === - 1 ) return
224
224
//extract href
225
- let start = s . substring ( s . indexOf ( 'href' ) + 6 )
225
+ let start = s ? s . substring ( s . indexOf ( 'href' ) + 6 ) : ''
226
226
let hrefStr = start . substring ( 0 , start . indexOf ( '"' ) )
227
227
228
228
let upload = {
229
229
data : hrefStr ,
230
230
preview : hrefStr ,
231
231
type : 'url' ,
232
- name : hrefStr . substring ( hrefStr . lastIndexOf ( '/' ) + 1 )
232
+ name : hrefStr ? hrefStr . substring ( hrefStr . lastIndexOf ( '/' ) + 1 ) : ''
233
233
}
234
234
setPreviews ( ( prevPreviews ) => [ ...prevPreviews , upload ] )
235
235
} )
@@ -282,7 +282,7 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
282
282
if ( pos === - 1 ) {
283
283
mimeType = blob . type
284
284
} else {
285
- mimeType = blob . type . substring ( 0 , pos )
285
+ mimeType = blob . type ? blob . type . substring ( 0 , pos ) : ''
286
286
}
287
287
// read blob and add to previews
288
288
const reader = new FileReader ( )
@@ -598,6 +598,26 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
598
598
}
599
599
}
600
600
601
+ const getLabel = ( URL , source ) => {
602
+ if ( URL && typeof URL === 'object' ) {
603
+ if ( URL . pathname && typeof URL . pathname === 'string' ) {
604
+ if ( URL . pathname . substring ( 0 , 15 ) === '/' ) {
605
+ return URL . host || ''
606
+ } else {
607
+ return `${ URL . pathname . substring ( 0 , 15 ) } ...`
608
+ }
609
+ } else if ( URL . host ) {
610
+ return URL . host
611
+ }
612
+ }
613
+
614
+ if ( source && source . pageContent && typeof source . pageContent === 'string' ) {
615
+ return `${ source . pageContent . substring ( 0 , 15 ) } ...`
616
+ }
617
+
618
+ return ''
619
+ }
620
+
601
621
const downloadFile = async ( fileAnnotation ) => {
602
622
try {
603
623
const response = await axios . post (
@@ -1180,13 +1200,7 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
1180
1200
< Chip
1181
1201
size = 'small'
1182
1202
key = { index }
1183
- label = {
1184
- URL
1185
- ? URL . pathname . substring ( 0 , 15 ) === '/'
1186
- ? URL . host
1187
- : `${ URL . pathname . substring ( 0 , 15 ) } ...`
1188
- : `${ source . pageContent . substring ( 0 , 15 ) } ...`
1189
- }
1203
+ label = { getLabel ( URL , source ) || '' }
1190
1204
component = 'a'
1191
1205
sx = { { mr : 1 , mb : 1 } }
1192
1206
variant = 'outlined'
@@ -1390,13 +1404,7 @@ export const ChatMessage = ({ open, chatflowid, isAgentCanvas, isDialog, preview
1390
1404
< Chip
1391
1405
size = 'small'
1392
1406
key = { index }
1393
- label = {
1394
- URL
1395
- ? URL . pathname . substring ( 0 , 15 ) === '/'
1396
- ? URL . host
1397
- : `${ URL . pathname . substring ( 0 , 15 ) } ...`
1398
- : `${ source . pageContent . substring ( 0 , 15 ) } ...`
1399
- }
1407
+ label = { getLabel ( URL , source ) || '' }
1400
1408
component = 'a'
1401
1409
sx = { { mr : 1 , mb : 1 } }
1402
1410
variant = 'outlined'
0 commit comments