@@ -11,7 +11,7 @@ import { AttachmentSourceOriginDTO, AttachmentSourceOriginFile, useAttachmentsSt
11
11
12
12
13
13
// enable to debug attachment operations
14
- const ATTACHMENTS_DEBUG = false ;
14
+ const ATTACHMENTS_DEBUG_INTAKE = false ;
15
15
16
16
17
17
export const useAttachments = ( enableLoadURLs : boolean ) => {
@@ -29,7 +29,7 @@ export const useAttachments = (enableLoadURLs: boolean) => {
29
29
// Creation helpers
30
30
31
31
const attachAppendFile = React . useCallback ( ( origin : AttachmentSourceOriginFile , fileWithHandle : FileWithHandle , overrideFileName ?: string ) => {
32
- if ( ATTACHMENTS_DEBUG )
32
+ if ( ATTACHMENTS_DEBUG_INTAKE )
33
33
console . log ( 'attachAppendFile' , origin , fileWithHandle , overrideFileName ) ;
34
34
35
35
return createAttachment ( {
@@ -42,13 +42,15 @@ export const useAttachments = (enableLoadURLs: boolean) => {
42
42
43
43
// https://github.com/enricoros/big-AGI/issues/286
44
44
const textHtml = dt . getData ( 'text/html' ) || '' ;
45
- const heuristicsIsExcel = textHtml . includes ( '"urn:schemas-microsoft-com:office:excel"' ) ;
45
+ const heuristicIsExcel = textHtml . includes ( '"urn:schemas-microsoft-com:office:excel"' ) ;
46
+ const heuristicIsPowerPoint = textHtml . includes ( 'xmlns:m="http://schemas.microsoft.com/office/20' ) && textHtml . includes ( '<meta name=Generator content="Microsoft PowerPoint' ) ;
47
+ const heuristicBypassImage = heuristicIsExcel || heuristicIsPowerPoint ;
46
48
47
- if ( ATTACHMENTS_DEBUG )
49
+ if ( ATTACHMENTS_DEBUG_INTAKE )
48
50
console . log ( 'attachAppendDataTransfer' , dt . types , dt . items , dt . files , textHtml ) ;
49
51
50
52
// attach File(s)
51
- if ( dt . files . length >= 1 && ! heuristicsIsExcel /* special case: ignore images from Microsoft Office pastes (prioritize the HTML paste) */ ) {
53
+ if ( dt . files . length >= 1 && ! heuristicBypassImage /* special case: ignore images from Microsoft Office pastes (prioritize the HTML paste) */ ) {
52
54
// rename files from a common prefix, to better relate them (if the transfer contains a list of paths)
53
55
let overrideFileNames : string [ ] = [ ] ;
54
56
if ( dt . types . includes ( 'text/plain' ) ) {
@@ -118,15 +120,15 @@ export const useAttachments = (enableLoadURLs: boolean) => {
118
120
119
121
// https://github.com/enricoros/big-AGI/issues/286
120
122
const textHtml = clipboardItem . types . includes ( 'text/html' ) ? await clipboardItem . getType ( 'text/html' ) . then ( blob => blob . text ( ) ) : '' ;
121
- const heuristicsIsExcel = textHtml . startsWith ( '<table ' ) ;
123
+ const heuristicBypassImage = textHtml . startsWith ( '<table ' ) ;
122
124
123
- if ( ATTACHMENTS_DEBUG )
124
- console . log ( ' - attachAppendClipboardItems.item:' , clipboardItem , textHtml , heuristicsIsExcel ) ;
125
+ if ( ATTACHMENTS_DEBUG_INTAKE )
126
+ console . log ( ' - attachAppendClipboardItems.item:' , clipboardItem , textHtml , heuristicBypassImage ) ;
125
127
126
128
// attach as image
127
129
let imageAttached = false ;
128
130
for ( const mimeType of clipboardItem . types ) {
129
- if ( mimeType . startsWith ( 'image/' ) && ! heuristicsIsExcel ) {
131
+ if ( mimeType . startsWith ( 'image/' ) && ! heuristicBypassImage ) {
130
132
try {
131
133
const imageBlob = await clipboardItem . getType ( mimeType ) ;
132
134
const imageName = mimeType . replace ( 'image/' , 'clipboard.' ) . replaceAll ( '/' , '.' ) || 'clipboard.png' ;
0 commit comments