@@ -232,8 +232,15 @@ func (m *Manager) setupDataDeviceSync() {
232232 return
233233 }
234234
235+ prevOffer := m .currentOffer
235236 m .currentOffer = offer
236237
238+ if prevOffer != nil && prevOffer != offer {
239+ m .offerMutex .Lock ()
240+ delete (m .offerMimeTypes , prevOffer )
241+ m .offerMutex .Unlock ()
242+ }
243+
237244 m .offerMutex .RLock ()
238245 mimes := m .offerMimeTypes [offer ]
239246 m .offerMutex .RUnlock ()
@@ -587,20 +594,26 @@ func (m *Manager) uriListPreview(data []byte) (string, bool) {
587594 uris = strings .Split (text , "\n " )
588595 }
589596
597+ if len (uris ) > 1 {
598+ return fmt .Sprintf ("[[ %d files ]]" , len (uris )), false
599+ }
600+
590601 if len (uris ) == 1 && strings .HasPrefix (uris [0 ], "file://" ) {
591602 filePath := strings .TrimPrefix (uris [0 ], "file://" )
592- if info , err := os .Stat (filePath ); err == nil && ! info .IsDir () {
603+ info , err := os .Stat (filePath )
604+ if err != nil || info .IsDir () {
605+ return m .textPreview (data ), false
606+ }
607+
608+ cfg := m .getConfig ()
609+ if info .Size () <= cfg .MaxEntrySize {
593610 if imgData , err := os .ReadFile (filePath ); err == nil {
594611 if config , imgFmt , err := image .DecodeConfig (bytes .NewReader (imgData )); err == nil {
595612 return fmt .Sprintf ("[[ file %s %s %dx%d ]]" , filepath .Base (filePath ), imgFmt , config .Width , config .Height ), true
596613 }
597614 }
598- return fmt .Sprintf ("[[ file %s ]]" , filepath .Base (filePath )), false
599615 }
600- }
601-
602- if len (uris ) > 1 {
603- return fmt .Sprintf ("[[ %d files ]]" , len (uris )), false
616+ return fmt .Sprintf ("[[ file %s ]]" , filepath .Base (filePath )), false
604617 }
605618
606619 return m .textPreview (data ), false
@@ -623,6 +636,11 @@ func (m *Manager) tryReadImageFromURI(data []byte) ([]byte, string, bool) {
623636 return nil , "" , false
624637 }
625638
639+ cfg := m .getConfig ()
640+ if info .Size () > cfg .MaxEntrySize {
641+ return nil , "" , false
642+ }
643+
626644 imgData , err := os .ReadFile (filePath )
627645 if err != nil {
628646 return nil , "" , false
0 commit comments