aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/ApiManagers/DownloadManager.ts12
-rw-r--r--src/server/ApiManagers/HypothesisManager.ts44
-rw-r--r--src/server/ApiManagers/PDFManager.ts2
-rw-r--r--src/server/ApiManagers/UploadManager.ts19
-rw-r--r--src/server/Recommender.ts4
-rw-r--r--src/server/apis/google/GoogleApiServerUtils.ts3
-rw-r--r--src/server/downsize.ts2
-rw-r--r--src/server/index.ts4
-rw-r--r--src/server/websocket.ts9
9 files changed, 69 insertions, 30 deletions
diff --git a/src/server/ApiManagers/DownloadManager.ts b/src/server/ApiManagers/DownloadManager.ts
index c5f3ca717..0d4472fdc 100644
--- a/src/server/ApiManagers/DownloadManager.ts
+++ b/src/server/ApiManagers/DownloadManager.ts
@@ -80,20 +80,14 @@ async function getDocs(id: string) {
}
const ids: string[] = [];
for (const key in doc.fields) {
- if (!doc.fields.hasOwnProperty(key)) {
- continue;
- }
+ if (!doc.fields.hasOwnProperty(key)) { continue; }
const field = doc.fields[key];
- if (field === undefined || field === null) {
- continue;
- }
+ if (field === undefined || field === null) { continue; }
if (field.__type === "proxy" || field.__type === "prefetch_proxy") {
ids.push(field.fieldId);
} else if (field.__type === "script" || field.__type === "computed") {
- if (field.captures) {
- ids.push(field.captures.fieldId);
- }
+ field.captures && ids.push(field.captures.fieldId);
} else if (field.__type === "list") {
ids.push(...fn(field));
} else if (typeof field === "string") {
diff --git a/src/server/ApiManagers/HypothesisManager.ts b/src/server/ApiManagers/HypothesisManager.ts
new file mode 100644
index 000000000..33badbc42
--- /dev/null
+++ b/src/server/ApiManagers/HypothesisManager.ts
@@ -0,0 +1,44 @@
+import ApiManager, { Registration } from "./ApiManager";
+import { Method, _permission_denied } from "../RouteManager";
+import { GoogleApiServerUtils } from "../apis/google/GoogleApiServerUtils";
+import { Database } from "../database";
+import { writeFile, readFile, readFileSync, existsSync } from "fs";
+import { serverPathToFile, Directory } from "./UploadManager";
+
+export default class HypothesisManager extends ApiManager {
+
+ protected initialize(register: Registration): void {
+
+ register({
+ method: Method.GET,
+ subscription: "/readHypothesisAccessToken",
+ secureHandler: async ({ user, res }) => {
+ if (existsSync(serverPathToFile(Directory.hypothesis, user.id))) {
+ const read = readFileSync(serverPathToFile(Directory.hypothesis, user.id), "base64") || "";
+ console.log("READ = " + read);
+ res.send(read);
+ } else res.send("");
+ }
+ });
+
+ register({
+ method: Method.POST,
+ subscription: "/writeHypothesisAccessToken",
+ secureHandler: async ({ user, req, res }) => {
+ const write = req.body.authenticationCode;
+ console.log("WRITE = " + write);
+ res.send(await writeFile(serverPathToFile(Directory.hypothesis, user.id), write, "base64", () => { }));
+ }
+ });
+
+ register({
+ method: Method.GET,
+ subscription: "/revokeHypothesisAccessToken",
+ secureHandler: async ({ user, res }) => {
+ await Database.Auxiliary.GoogleAccessToken.Revoke("dash-hyp-" + user.id);
+ res.send();
+ }
+ });
+
+ }
+} \ No newline at end of file
diff --git a/src/server/ApiManagers/PDFManager.ts b/src/server/ApiManagers/PDFManager.ts
index e028d628d..2b4212588 100644
--- a/src/server/ApiManagers/PDFManager.ts
+++ b/src/server/ApiManagers/PDFManager.ts
@@ -114,4 +114,4 @@ class NodeCanvasFactory {
canvasAndContext.canvas = null;
canvasAndContext.context = null;
}
-} \ No newline at end of file
+}
diff --git a/src/server/ApiManagers/UploadManager.ts b/src/server/ApiManagers/UploadManager.ts
index 696ad0288..515fbe4ff 100644
--- a/src/server/ApiManagers/UploadManager.ts
+++ b/src/server/ApiManagers/UploadManager.ts
@@ -15,6 +15,7 @@ import RouteSubscriber from "../RouteSubscriber";
const imageDataUri = require('image-data-uri');
import { isWebUri } from "valid-url";
import { Opt } from "../../fields/Doc";
+import { SolrManager } from "./SearchManager";
export enum Directory {
parsed_files = "parsed_files",
@@ -23,7 +24,8 @@ export enum Directory {
pdfs = "pdfs",
text = "text",
pdf_thumbnails = "pdf_thumbnails",
- audio = "audio"
+ audio = "audio",
+ hypothesis = "hypothesis"
}
export function serverPathToFile(directory: Directory, filename: string) {
@@ -137,13 +139,9 @@ export default class UploadManager extends ApiManager {
doc.id = getId(doc.id);
}
for (const key in doc.fields) {
- if (!doc.fields.hasOwnProperty(key)) {
- continue;
- }
+ if (!doc.fields.hasOwnProperty(key)) { continue; }
const field = doc.fields[key];
- if (field === undefined || field === null) {
- continue;
- }
+ if (field === undefined || field === null) { continue; }
if (field.__type === "proxy" || field.__type === "prefetch_proxy") {
field.fieldId = getId(field.fieldId);
@@ -206,11 +204,8 @@ export default class UploadManager extends ApiManager {
} catch (e) { console.log(e); }
unlink(path_2, () => { });
}
- if (id) {
- res.send(JSON.stringify(getId(id)));
- } else {
- res.send(JSON.stringify("error"));
- }
+ SolrManager.update();
+ res.send(JSON.stringify(id ? getId(id) : "error"));
} catch (e) { console.log(e); }
resolve();
});
diff --git a/src/server/Recommender.ts b/src/server/Recommender.ts
index 423ce9b46..935ec3871 100644
--- a/src/server/Recommender.ts
+++ b/src/server/Recommender.ts
@@ -21,7 +21,6 @@
// private choice: string = ""; // Tensorflow or Word2Vec
// constructor() {
-// console.log("creating recommender...");
// Recommender.Instance = this;
// }
@@ -70,7 +69,6 @@
// if (this._model) {
// if (this.choice === "WV") {
// let similarity = this._model.similarity('father', 'mother');
-// console.log(similarity);
// }
// else if (this.choice === "TF") {
// const model = this._model as use.UniversalSentenceEncoder;
@@ -119,7 +117,6 @@
// }
// // public async trainModel() {
-// // console.log("phrasing...");
// // w2v.word2vec("./node_modules/word2vec/examples/eng_news-typical_2016_1M-sentences.txt", './node_modules/word2vec/examples/my_phrases.txt', {
// // cbow: 1,
// // size: 200,
@@ -131,7 +128,6 @@
// // iter: 200,
// // minCount: 2
// // });
-// // console.log("phrased!!!");
// // }
// }
diff --git a/src/server/apis/google/GoogleApiServerUtils.ts b/src/server/apis/google/GoogleApiServerUtils.ts
index 20f96f432..b0157a85f 100644
--- a/src/server/apis/google/GoogleApiServerUtils.ts
+++ b/src/server/apis/google/GoogleApiServerUtils.ts
@@ -39,7 +39,8 @@ export namespace GoogleApiServerUtils {
*/
export enum Service {
Documents = "Documents",
- Slides = "Slides"
+ Slides = "Slides",
+ Hypothesis = "Hypothesis"
}
/**
diff --git a/src/server/downsize.ts b/src/server/downsize.ts
index cd0d83812..5cd709fa3 100644
--- a/src/server/downsize.ts
+++ b/src/server/downsize.ts
@@ -7,7 +7,7 @@ const jpgTypes = ["jpg", "JPG", "jpeg", "JPEG"];
const smallResizer = sharp().resize(100);
fs.readdir(folder, async (err, files) => {
if (err) {
- console.log(err);
+ console.log("readdir:" + err);
return;
}
// files.forEach(file => {
diff --git a/src/server/index.ts b/src/server/index.ts
index 590affd06..9af4b00bc 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -18,10 +18,10 @@ import PDFManager from "./ApiManagers/PDFManager";
import UploadManager from "./ApiManagers/UploadManager";
import { log_execution } from "./ActionUtilities";
import GeneralGoogleManager from "./ApiManagers/GeneralGoogleManager";
+import HypothesisManager from "./ApiManagers/HypothesisManager";
import GooglePhotosManager from "./ApiManagers/GooglePhotosManager";
import { Logger } from "./ProcessFactory";
import { yellow } from "colors";
-import { DashSessionAgent } from "./DashSession/DashSessionAgent";
import SessionManager from "./ApiManagers/SessionManager";
import { AppliedSessionAgent } from "./DashSession/Session/agents/applied_session_agent";
@@ -72,6 +72,7 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }:
new DeleteManager(),
new UtilManager(),
new GeneralGoogleManager(),
+ new HypothesisManager(),
new GooglePhotosManager(),
];
@@ -104,6 +105,7 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }:
const serve: PublicHandler = ({ req, res }) => {
const detector = new mobileDetect(req.headers['user-agent'] || "");
const filename = detector.mobile() !== null ? 'mobile/image.html' : 'index.html';
+ console.log(detector.is("iPhone"));
res.sendFile(path.join(__dirname, '../../deploy/' + filename));
};
diff --git a/src/server/websocket.ts b/src/server/websocket.ts
index 19c98454c..c80056579 100644
--- a/src/server/websocket.ts
+++ b/src/server/websocket.ts
@@ -180,7 +180,14 @@ export namespace WebSocket {
function barReceived(socket: SocketIO.Socket, userEmail: string) {
clients[userEmail] = new Client(userEmail.toString());
- console.log(green(`user ${userEmail} has connected to the web socket`));
+ const currentdate = new Date();
+ const datetime = currentdate.getDate() + "/"
+ + (currentdate.getMonth() + 1) + "/"
+ + currentdate.getFullYear() + " @ "
+ + currentdate.getHours() + ":"
+ + currentdate.getMinutes() + ":"
+ + currentdate.getSeconds();
+ console.log(green(`user ${userEmail} has connected to the web socket at: ${datetime}`));
socketMap.set(socket, userEmail);
}