From a1bbdbbcfb9ad704c42fae48bfe88a720803f756 Mon Sep 17 00:00:00 2001
From: Sam Wilkins <samwilkins333@gmail.com>
Date: Sat, 6 Jul 2019 12:03:25 -0400
Subject: added embedding of size and modified time

---
 .../util/Import & Export/DirectoryImportBox.tsx    | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

(limited to 'src/client/util/Import & Export/DirectoryImportBox.tsx')

diff --git a/src/client/util/Import & Export/DirectoryImportBox.tsx b/src/client/util/Import & Export/DirectoryImportBox.tsx
index b75944745..093cee168 100644
--- a/src/client/util/Import & Export/DirectoryImportBox.tsx	
+++ b/src/client/util/Import & Export/DirectoryImportBox.tsx	
@@ -19,6 +19,8 @@ import { List } from "../../../new_fields/List";
 import { Cast, BoolCast, NumCast } from "../../../new_fields/Types";
 import { listSpec } from "../../../new_fields/Schema";
 
+const unsupported = ["text/html", "text/plain"];
+
 @observer
 export default class DirectoryImportBox extends React.Component<FieldViewProps> {
     private selector = React.createRef<HTMLInputElement>();
@@ -77,21 +79,24 @@ export default class DirectoryImportBox extends React.Component<FieldViewProps>
         let validated: File[] = [];
         for (let i = 0; i < files.length; i++) {
             let file = files.item(i);
-            file && validated.push(file);
+            console.log(file);
+            file && !unsupported.includes(file.type) && validated.push(file);
         }
 
         runInAction(() => this.quota = validated.length);
 
-        for (let uploaded_file of validated) {
-            if (!uploaded_file) {
-                continue;
-            }
+        let sizes = [];
+        let modifiedDates = [];
 
+        for (let uploaded_file of validated) {
             let formData = new FormData();
             formData.append('file', uploaded_file);
             let dropFileName = uploaded_file ? uploaded_file.name : "-empty-";
             let type = uploaded_file.type;
 
+            sizes.push(uploaded_file.size);
+            modifiedDates.push(uploaded_file.lastModified);
+
             runInAction(() => this.remaining++);
 
             let prom = fetch(DocServer.prepend(RouteStore.upload), {
@@ -99,6 +104,7 @@ export default class DirectoryImportBox extends React.Component<FieldViewProps>
                 body: formData
             }).then(async (res: Response) => {
                 (await res.json()).map(action((file: any) => {
+                    console.log(file);
                     let docPromise = Docs.getDocumentFromType(type, DocServer.prepend(file), { nativeWidth: 300, width: 300, title: dropFileName });
                     docPromise.then(doc => {
                         doc && docs.push(doc) && runInAction(() => this.remaining--);
@@ -110,12 +116,15 @@ export default class DirectoryImportBox extends React.Component<FieldViewProps>
 
         await Promise.all(promises);
 
-        docs.forEach(doc => {
+        for (let i = 0; i < docs.length; i++) {
+            let doc = docs[i];
+            doc.size = sizes[i];
+            doc.modified = modifiedDates[i];
             this.entries.forEach(entry => {
                 let target = entry.onDataDoc ? Doc.GetProto(doc) : doc;
                 target[entry.key] = entry.value;
             });
-        });
+        }
 
         let doc = this.props.Document;
         let height: number = NumCast(doc.height) || 0;
-- 
cgit v1.2.3-70-g09d2

