Skip to content

Commit 682c168

Browse files
committed
Attachments: further improve heuristics, mainly for powerpoint. #286
1 parent 48f0395 commit 682c168

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/apps/chat/components/composer/attachments/useAttachments.tsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { AttachmentSourceOriginDTO, AttachmentSourceOriginFile, useAttachmentsSt
1111

1212

1313
// enable to debug attachment operations
14-
const ATTACHMENTS_DEBUG = false;
14+
const ATTACHMENTS_DEBUG_INTAKE = false;
1515

1616

1717
export const useAttachments = (enableLoadURLs: boolean) => {
@@ -29,7 +29,7 @@ export const useAttachments = (enableLoadURLs: boolean) => {
2929
// Creation helpers
3030

3131
const attachAppendFile = React.useCallback((origin: AttachmentSourceOriginFile, fileWithHandle: FileWithHandle, overrideFileName?: string) => {
32-
if (ATTACHMENTS_DEBUG)
32+
if (ATTACHMENTS_DEBUG_INTAKE)
3333
console.log('attachAppendFile', origin, fileWithHandle, overrideFileName);
3434

3535
return createAttachment({
@@ -42,13 +42,15 @@ export const useAttachments = (enableLoadURLs: boolean) => {
4242

4343
// https://github.com/enricoros/big-AGI/issues/286
4444
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;
4648

47-
if (ATTACHMENTS_DEBUG)
49+
if (ATTACHMENTS_DEBUG_INTAKE)
4850
console.log('attachAppendDataTransfer', dt.types, dt.items, dt.files, textHtml);
4951

5052
// 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) */) {
5254
// rename files from a common prefix, to better relate them (if the transfer contains a list of paths)
5355
let overrideFileNames: string[] = [];
5456
if (dt.types.includes('text/plain')) {
@@ -118,15 +120,15 @@ export const useAttachments = (enableLoadURLs: boolean) => {
118120

119121
// https://github.com/enricoros/big-AGI/issues/286
120122
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 ');
122124

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);
125127

126128
// attach as image
127129
let imageAttached = false;
128130
for (const mimeType of clipboardItem.types) {
129-
if (mimeType.startsWith('image/') && !heuristicsIsExcel) {
131+
if (mimeType.startsWith('image/') && !heuristicBypassImage) {
130132
try {
131133
const imageBlob = await clipboardItem.getType(mimeType);
132134
const imageName = mimeType.replace('image/', 'clipboard.').replaceAll('/', '.') || 'clipboard.png';

0 commit comments

Comments
 (0)