@@ -75,6 +75,7 @@ export function DocDialog(
7575 const [ iframeKey , setIframeKey ] = useState ( 0 ) ;
7676 const [ isExpanded , setIsExpanded ] = useState ( false ) ;
7777 const [ clearedChatFlag , setClearChatFlag ] = useState ( clearChatFlag ) ;
78+ const [ iframeSrc , setIframeSrc ] = useState < string | undefined > ( undefined ) ;
7879 // const [aiKnowledgeMetadata, setAIKnowledgeMetadata] = useState<Document | null>(null);
7980
8081
@@ -90,6 +91,24 @@ export function DocDialog(
9091 setUrlWithSasToken ( undefined ) ;
9192 }
9293 } , [ metadata ] ) ; // Only run when metadata changes
94+
95+ useEffect ( ( ) => {
96+ if ( metadata && metadata . fileName . endsWith ( ".txt" ) ) {
97+ fetch ( metadata . document_url )
98+ . then ( ( response ) => response . text ( ) )
99+ . then ( ( textContent ) => {
100+ const blob = new Blob ( [ textContent ] , { type : "text/plain" } ) ;
101+ const objectURL = URL . createObjectURL ( blob ) ;
102+ setIframeSrc ( objectURL ) ;
103+
104+ // Cleanup the object URL when component unmounts or metadata changes
105+ return ( ) => URL . revokeObjectURL ( objectURL ) ;
106+ } )
107+ . catch ( ( error ) => console . error ( "Error fetching text file:" , error ) ) ;
108+ } else {
109+ setIframeSrc ( metadata ?. document_url ) ;
110+ }
111+ } , [ metadata ] ) ;
93112
94113
95114 const downloadFile = ( ) => {
@@ -236,7 +255,7 @@ export function DocDialog(
236255 < IFrameComponent
237256 className = "h-[100%]"
238257 metadata = { metadata }
239- urlWithSasToken = { urlWithSasToken }
258+ urlWithSasToken = { iframeSrc }
240259 iframeKey = { iframeKey }
241260 />
242261 </ div >
0 commit comments