aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/Main.tsx2
-rw-r--r--src/client/views/collections/CollectionViewBase.tsx28
-rw-r--r--src/server/index.ts16
3 files changed, 38 insertions, 8 deletions
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index d845fa7a3..32b6335d8 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -50,7 +50,7 @@ Documents.initProtos(mainDocId, (res?: Document) => {
}, 0);
}
- let imgurl = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg";
+ let imgurl = "http://localhost:1050/images/upload_9a3bfff22137b88012650570fb1fe344.png";
let weburl = "https://cs.brown.edu/courses/cs166/";
let clearDatabase = action(() => Utils.Emit(Server.Socket, MessageStore.DeleteAll, {}))
let addTextNode = action(() => Documents.TextDocument({ width: 200, height: 200, title: "a text note" }))
diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx
index 47c9e0986..661cec8ae 100644
--- a/src/client/views/collections/CollectionViewBase.tsx
+++ b/src/client/views/collections/CollectionViewBase.tsx
@@ -1,4 +1,4 @@
-import { action } from "mobx";
+import { action, runInAction } from "mobx";
import { Document } from "../../../fields/Document";
import { ListField } from "../../../fields/ListField";
import React = require("react");
@@ -62,7 +62,6 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
@action
protected onDrop(e: React.DragEvent, options: DocumentOptions): void {
- console.log("DRRRRROOOOPPPPPP");
e.stopPropagation()
e.preventDefault()
let that = this;
@@ -112,6 +111,31 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps>
method: 'POST',
body: formData
})
+ .then((res: Response) => {
+ return res.json()
+ }).then(json => {
+
+ json.map((file: any) => {
+ console.log(file)
+ console.log(typeof file)
+ let path = window.location.origin + file
+ console.log(path)
+ runInAction(() => {
+ var img = Documents.ImageDocument(path, { ...options, nativeWidth: 300, width: 300, })
+ let docs = that.props.Document.GetT(KeyStore.Data, ListField);
+ if (docs != FieldWaiting) {
+ if (!docs) {
+ docs = new ListField<Document>();
+ that.props.Document.Set(KeyStore.Data, docs)
+ }
+ docs.Data.push(img);
+
+ }
+ })
+
+
+ })
+ })
// fReader.addEventListener("load", action("drop", () => {
// if (fReader.result) {
// let form = request.post(upload).form();
diff --git a/src/server/index.ts b/src/server/index.ts
index 89a2793e8..f2046f92c 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -76,19 +76,25 @@ app.get("/login", getLogin);
app.post("/login", postLogin);
// IMAGE UPLOADING HANDLER
-
app.post("/upload", (req, res, err) => {
- new formidable.IncomingForm().parse(req, (err, fields, files) => {
+ let form = new formidable.IncomingForm()
+ form.uploadDir = __dirname + "/public/files/"
+ form.keepExtensions = true
+ // let path = req.body.path;
+ console.log("upload")
+ form.parse(req, (err, fields, files) => {
+ console.log("parsing")
+ let names: any[] = [];
for (const name in files) {
let file = files[name];
- file.path = __dirname + "/files/" + file.name;
- console.log(file.path);
+ names.push(`/files/` + path.basename(file.path));
}
+ res.send(names);
});
- //request.get(url).pipe(fs.createWriteStream(__dirname + "/public/images"));
})
app.use(express.static(__dirname + '/public'));
+app.use('/images', express.static(__dirname + '/public'))
let FieldStore: ObservableMap<FieldId, Field> = new ObservableMap();