@@ -9,6 +9,22 @@ import { tailwind } from '@/theme';
99import { Icon } from '@/components-next/common' ;
1010import { Spinner } from '@/components-next/spinner' ;
1111import { MESSAGE_VARIANTS } from '@/constants' ;
12+
13+ const generateUniqueFileName = ( url : string , originalFileName : string ) => {
14+ const hash = url . split ( '' ) . reduce ( ( acc , char ) => {
15+ const charCode = char . charCodeAt ( 0 ) ;
16+ return ( ( acc << 5 ) - acc + charCode ) | 0 ;
17+ } , 0 ) ;
18+ const uniqueHash = Math . abs ( hash ) . toString ( 36 ) ;
19+ const fileExtension = originalFileName . includes ( '.' )
20+ ? originalFileName . substring ( originalFileName . lastIndexOf ( '.' ) )
21+ : '' ;
22+ const baseFileName = originalFileName . includes ( '.' )
23+ ? originalFileName . substring ( 0 , originalFileName . lastIndexOf ( '.' ) )
24+ : originalFileName ;
25+ return `${ baseFileName } _${ uniqueHash } ${ fileExtension } ` ;
26+ } ;
27+
1228type FilePreviewProps = Pick < FileBubbleProps , 'fileSrc' > & {
1329 isComposed ?: boolean ;
1430 variant : string ;
@@ -20,7 +36,8 @@ export const FileBubblePreview = (props: FilePreviewProps) => {
2036
2137 const [ fileDownload , setFileDownload ] = useState ( false ) ;
2238 const fileName = fileSrc . split ( '/' ) [ fileSrc . split ( '/' ) . length - 1 ] ;
23- const localFilePath = dirs . DocumentDir + `/${ fileName } ` ;
39+ const uniqueFileName = generateUniqueFileName ( fileSrc , fileName ) ;
40+ const localFilePath = dirs . DocumentDir + `/${ uniqueFileName } ` ;
2441
2542 const previewFile = ( ) => {
2643 try {
0 commit comments