aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Message.ts86
-rw-r--r--src/server/ServerUtil.ts94
-rw-r--r--src/server/database.ts46
-rw-r--r--src/server/public/files/.gitignore1
-rw-r--r--src/server/public/files/upload_a6a70d84ebb65febf7900e29f52cc86d.pdfbin0 -> 1043556 bytes
-rw-r--r--src/server/public/files/upload_e72669595eae4384a2a32196496f4f05.pdfbin548616 -> 0 bytes
6 files changed, 134 insertions, 93 deletions
diff --git a/src/server/Message.ts b/src/server/Message.ts
index 05ae0f19a..0274609bb 100644
--- a/src/server/Message.ts
+++ b/src/server/Message.ts
@@ -9,12 +9,12 @@ export class Message<T> {
}
get Message(): string {
- return this.guid
+ return this.guid;
}
constructor(name: string) {
this.name = name;
- this.guid = Utils.GenerateDeterministicGuid(name)
+ this.guid = Utils.GenerateDeterministicGuid(name);
}
GetValue() {
@@ -31,8 +31,8 @@ export class SetFieldArgs {
value: any;
constructor(f: string, v: any) {
- this.field = f
- this.value = v
+ this.field = f;
+ this.value = v;
}
}
@@ -40,37 +40,55 @@ export class GetFieldArgs {
field: string;
constructor(f: string) {
- this.field = f
+ this.field = f;
}
}
export enum Types {
- Number, List, Key, Image, Web, Document, Text, RichText, DocumentReference, Html, Video, Audio, Ink, PDF, Tuple, HistogramOp
+ Number,
+ List,
+ Key,
+ Image,
+ Web,
+ Document,
+ Text,
+ RichText,
+ DocumentReference,
+ Html,
+ Video,
+ Audio,
+ Ink,
+ PDF,
+ Tuple,
+ HistogramOp,
+ Boolean
}
export class DocumentTransfer implements Transferable {
- readonly type = Types.Document
- _id: string
+ readonly type = Types.Document;
+ _id: string;
- constructor(readonly obj: { type: Types, data: [string, string][], _id: string }) {
- this._id = obj._id
+ constructor(
+ readonly obj: { type: Types; data: [string, string][]; _id: string }
+ ) {
+ this._id = obj._id;
}
}
export class ImageTransfer implements Transferable {
- readonly type = Types.Image
+ readonly type = Types.Image;
constructor(readonly _id: string) { }
}
export class KeyTransfer implements Transferable {
- name: string
- readonly _id: string
- readonly type = Types.Key
+ name: string;
+ readonly _id: string;
+ readonly type = Types.Key;
constructor(i: string, n: string) {
- this.name = n
- this._id = i
+ this.name = n;
+ this._id = i;
}
}
@@ -81,45 +99,47 @@ export class ListTransfer implements Transferable {
}
export class NumberTransfer implements Transferable {
- readonly type = Types.Number
+ readonly type = Types.Number;
constructor(readonly value: number, readonly _id: string) { }
}
export class TextTransfer implements Transferable {
- value: string
- readonly _id: string
- readonly type = Types.Text
+ value: string;
+ readonly _id: string;
+ readonly type = Types.Text;
constructor(t: string, i: string) {
- this.value = t
- this._id = i
+ this.value = t;
+ this._id = i;
}
}
export class RichTextTransfer implements Transferable {
- value: string
- readonly _id: string
- readonly type = Types.Text
+ value: string;
+ readonly _id: string;
+ readonly type = Types.Text;
constructor(t: string, i: string) {
- this.value = t
- this._id = i
+ this.value = t;
+ this._id = i;
}
}
export interface Transferable {
- readonly _id: string
- readonly type: Types
+ readonly _id: string;
+ readonly type: Types;
}
export namespace MessageStore {
export const Foo = new Message<string>("Foo");
export const Bar = new Message<string>("Bar");
export const AddDocument = new Message<DocumentTransfer>("Add Document");
- export const SetField = new Message<{ _id: string, data: any, type: Types }>("Set Field")
- export const GetField = new Message<string>("Get Field")
- export const GetFields = new Message<string[]>("Get Fields")
+ export const SetField = new Message<{ _id: string; data: any; type: Types }>(
+ "Set Field"
+ );
+ export const GetField = new Message<string>("Get Field");
+ export const GetFields = new Message<string[]>("Get Fields");
export const GetDocument = new Message<string>("Get Document");
export const DeleteAll = new Message<any>("Delete All");
-} \ No newline at end of file
+}
diff --git a/src/server/ServerUtil.ts b/src/server/ServerUtil.ts
index 98a7a1451..2c2bfd0c9 100644
--- a/src/server/ServerUtil.ts
+++ b/src/server/ServerUtil.ts
@@ -1,78 +1,84 @@
-
-import { Field } from './../fields/Field';
-import { TextField } from './../fields/TextField';
-import { NumberField } from './../fields/NumberField';
-import { RichTextField } from './../fields/RichTextField';
-import { Key } from './../fields/Key';
-import { ImageField } from './../fields/ImageField';
-import { ListField } from './../fields/ListField';
-import { Document } from './../fields/Document';
-import { Server } from './../client/Server';
-import { Types } from './Message';
-import { Utils } from '../Utils';
-import { HtmlField } from '../fields/HtmlField';
-import { WebField } from '../fields/WebField';
-import { AudioField } from '../fields/AudioField';
-import { VideoField } from '../fields/VideoField';
-import { InkField } from '../fields/InkField';
-import { PDFField } from '../fields/PDFField';
-import { TupleField } from '../fields/TupleField';
-import { HistogramField } from '../client/northstar/dash-fields/HistogramField';
-
-
+import { Field } from "./../fields/Field";
+import { TextField } from "./../fields/TextField";
+import { NumberField } from "./../fields/NumberField";
+import { RichTextField } from "./../fields/RichTextField";
+import { Key } from "./../fields/Key";
+import { ImageField } from "./../fields/ImageField";
+import { ListField } from "./../fields/ListField";
+import { Document } from "./../fields/Document";
+import { Server } from "./../client/Server";
+import { Types } from "./Message";
+import { Utils } from "../Utils";
+import { HtmlField } from "../fields/HtmlField";
+import { WebField } from "../fields/WebField";
+import { AudioField } from "../fields/AudioField";
+import { VideoField } from "../fields/VideoField";
+import { InkField } from "../fields/InkField";
+import { PDFField } from "../fields/PDFField";
+import { TupleField } from "../fields/TupleField";
+import { BooleanField } from "../fields/BooleanField";
+import { HistogramField } from "../client/northstar/dash-fields/HistogramField";
export class ServerUtils {
- public static prepend(extension: string): string { return window.location.origin + extension; }
+ public static prepend(extension: string): string {
+ return window.location.origin + extension;
+ }
public static FromJson(json: any): Field {
- let obj = json
- let data: any = obj.data
- let id: string = obj._id
- let type: Types = obj.type
+ let obj = json;
+ let data: any = obj.data;
+ let id: string = obj._id;
+ let type: Types = obj.type;
if (!(data !== undefined && id && type !== undefined)) {
- console.log("how did you manage to get an object that doesn't have a data or an id?")
+ console.log(
+ "how did you manage to get an object that doesn't have a data or an id?"
+ );
return new TextField("Something to fill the space", Utils.GenerateGuid());
}
switch (type) {
+ case Types.Boolean:
+ return new BooleanField(data, id, false);
case Types.Number:
- return new NumberField(data, id, false)
+ return new NumberField(data, id, false);
case Types.Text:
- return new TextField(data, id, false)
+ return new TextField(data, id, false);
case Types.Html:
- return new HtmlField(data, id, false)
+ return new HtmlField(data, id, false);
case Types.Web:
- return new WebField(new URL(data), id, false)
+ return new WebField(new URL(data), id, false);
case Types.RichText:
- return new RichTextField(data, id, false)
+ return new RichTextField(data, id, false);
case Types.Key:
- return new Key(data, id, false)
+ return new Key(data, id, false);
case Types.Image:
- return new ImageField(new URL(data), id, false)
+ return new ImageField(new URL(data), id, false);
case Types.HistogramOp:
return HistogramField.FromJson(id, data);
case Types.PDF:
- return new PDFField(new URL(data), id, false)
+ return new PDFField(new URL(data), id, false);
case Types.List:
- return ListField.FromJson(id, data)
+ return ListField.FromJson(id, data);
case Types.Audio:
- return new AudioField(new URL(data), id, false)
+ return new AudioField(new URL(data), id, false);
case Types.Video:
- return new VideoField(new URL(data), id, false)
+ return new VideoField(new URL(data), id, false);
case Types.Tuple:
return new TupleField(data, id, false);
case Types.Ink:
return InkField.FromJson(id, data);
case Types.Document:
- let doc: Document = new Document(id, false)
- let fields: [string, string][] = data as [string, string][]
+ let doc: Document = new Document(id, false);
+ let fields: [string, string][] = data as [string, string][];
fields.forEach(element => {
doc._proxies.set(element[0], element[1]);
});
- return doc
+ return doc;
default:
- throw Error("Error, unrecognized field type received from server. If you just created a new field type, be sure to add it here");
+ throw Error(
+ "Error, unrecognized field type received from server. If you just created a new field type, be sure to add it here"
+ );
}
}
-} \ No newline at end of file
+}
diff --git a/src/server/database.ts b/src/server/database.ts
index 87a0b3c70..415acc09a 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -1,8 +1,4 @@
-import { action, configure } from 'mobx';
import * as mongodb from 'mongodb';
-import { ObjectID } from 'mongodb';
-import { Transferable } from './Message';
-import { Utils } from '../Utils';
export class Database {
public static Instance = new Database()
@@ -16,21 +12,39 @@ export class Database {
})
}
+ private currentWrites: { [_id: string]: Promise<void> } = {};
+
public update(id: string, value: any, callback: () => void) {
if (this.db) {
let collection = this.db.collection('documents');
- collection.updateOne({ _id: id }, { $set: value }, {
- upsert: true
- }, (err, res) => {
- if (err) {
- console.log(err.message);
- console.log(err.errmsg);
- }
- if (res) {
- // console.log(JSON.stringify(res.result));
- }
- callback()
- });
+ const prom = this.currentWrites[id];
+ const run = (promise: Promise<void>, resolve?: () => void) => {
+ collection.updateOne({ _id: id }, { $set: value }, {
+ upsert: true
+ }, (err, res) => {
+ if (err) {
+ console.log(err.message);
+ console.log(err.errmsg);
+ }
+ // if (res) {
+ // console.log(JSON.stringify(res.result));
+ // }
+ if (this.currentWrites[id] === promise) {
+ delete this.currentWrites[id]
+ }
+ if (resolve) {
+ resolve();
+ }
+ callback();
+ });
+ }
+ if (prom) {
+ const newProm: Promise<void> = prom.then(() => run(newProm));
+ this.currentWrites[id] = newProm;
+ } else {
+ const newProm: Promise<void> = new Promise<void>(res => run(newProm, res))
+ this.currentWrites[id] = newProm;
+ }
}
}
diff --git a/src/server/public/files/.gitignore b/src/server/public/files/.gitignore
new file mode 100644
index 000000000..f59ec20aa
--- /dev/null
+++ b/src/server/public/files/.gitignore
@@ -0,0 +1 @@
+* \ No newline at end of file
diff --git a/src/server/public/files/upload_a6a70d84ebb65febf7900e29f52cc86d.pdf b/src/server/public/files/upload_a6a70d84ebb65febf7900e29f52cc86d.pdf
new file mode 100644
index 000000000..dfd6ab339
--- /dev/null
+++ b/src/server/public/files/upload_a6a70d84ebb65febf7900e29f52cc86d.pdf
Binary files differ
diff --git a/src/server/public/files/upload_e72669595eae4384a2a32196496f4f05.pdf b/src/server/public/files/upload_e72669595eae4384a2a32196496f4f05.pdf
deleted file mode 100644
index 8e58bfddd..000000000
--- a/src/server/public/files/upload_e72669595eae4384a2a32196496f4f05.pdf
+++ /dev/null
Binary files differ