From 865478933af8166cb699cbe4a2653aa52423dedb Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 29 Dec 2023 01:01:55 -0500
Subject: fixed dropping images from web.  fixed exif data on images and
 autorotating exif rotated images.  fixed selecting on web pages, and resizing
 web pages upward so that pointer events aren't grabbed.

---
 src/client/views/collections/CollectionSubView.tsx | 31 +++++++++++-----------
 1 file changed, 15 insertions(+), 16 deletions(-)

(limited to 'src/client/views/collections/CollectionSubView.tsx')

diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index b56973dc6..2ff435ce2 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -4,11 +4,11 @@ import * as rp from 'request-promise';
 import { Utils, returnFalse } from '../../../Utils';
 import CursorField from '../../../fields/CursorField';
 import { Doc, DocListCast, Field, Opt, StrListCast } from '../../../fields/Doc';
-import { AclPrivate } from '../../../fields/DocSymbols';
+import { AclPrivate, DocData } from '../../../fields/DocSymbols';
 import { Id } from '../../../fields/FieldSymbols';
 import { List } from '../../../fields/List';
 import { listSpec } from '../../../fields/Schema';
-import { BoolCast, Cast, ScriptCast, StrCast } from '../../../fields/Types';
+import { BoolCast, Cast, NumCast, ScriptCast, StrCast } from '../../../fields/Types';
 import { WebField } from '../../../fields/URLField';
 import { GetEffectiveAcl, TraceMobx } from '../../../fields/util';
 import { GestureUtils } from '../../../pen-gestures/GestureUtils';
@@ -309,20 +309,19 @@ export function CollectionSubView<X>(moreProps?: X) {
                     const cors = img.includes('corsProxy') ? img.match(/http.*corsProxy\//)![0] : '';
                     img = cors ? img.replace(cors, '') : img;
                     if (img) {
-                        const split = img.split('src="')[1].split('"')[0];
-                        let source = split;
-                        if (split.startsWith('data:image') && split.includes('base64')) {
-                            const [{ accessPaths }] = await Networking.PostToServer('/uploadRemoteImage', { sources: [split] });
-                            if (accessPaths.agnostic.client.indexOf('dashblobstore') === -1) {
-                                source = Utils.prepend(accessPaths.agnostic.client);
-                            } else {
-                                source = accessPaths.agnostic.client;
-                            }
-                        }
-                        if (source.startsWith('http')) {
-                            const doc = Docs.Create.ImageDocument(source, { ...options, _width: 300 });
-                            ImageUtils.ExtractExif(doc);
-                            addDocument(doc);
+                        const imgSrc = img.split('src="')[1].split('"')[0];
+                        const imgOpts = { ...options, _width: 300 };
+                        if (imgSrc.startsWith('data:image') && imgSrc.includes('base64')) {
+                            const result = (await Networking.PostToServer('/uploadRemoteImage', { sources: [imgSrc] })).lastElement();
+                            const newImgSrc =
+                                result.accessPaths.agnostic.client.indexOf('dashblobstore') === -1 //
+                                    ? Utils.prepend(result.accessPaths.agnostic.client)
+                                    : result.accessPaths.agnostic.client;
+
+                            addDocument(ImageUtils.AssignImgInfo(Docs.Create.ImageDocument(newImgSrc, imgOpts), result));
+                        } else if (imgSrc.startsWith('http')) {
+                            const doc = Docs.Create.ImageDocument(imgSrc, imgOpts);
+                            addDocument(ImageUtils.AssignImgInfo(doc, await ImageUtils.ExtractImgInfo(doc)));
                         }
                         return;
                     } else {
-- 
cgit v1.2.3-70-g09d2

