diff options
author | usodhi <61431818+usodhi@users.noreply.github.com> | 2020-07-16 13:06:55 +0530 |
---|---|---|
committer | usodhi <61431818+usodhi@users.noreply.github.com> | 2020-07-16 13:06:55 +0530 |
commit | f6cfb6f68fdf6e987b867b9ece37b53845ff426e (patch) | |
tree | 9e2ccba4aa319b13e353ee86b2b369c8578879f2 /src/server/ApiManagers/HypothesisManager.ts | |
parent | b442fc347abc267697575c517949ca0ee0dad2f1 (diff) | |
parent | 21284a84b6d9930b5ddfddaa600b6916613748c4 (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into grid_view_secondary
Diffstat (limited to 'src/server/ApiManagers/HypothesisManager.ts')
-rw-r--r-- | src/server/ApiManagers/HypothesisManager.ts | 44 |
1 files changed, 44 insertions, 0 deletions
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 |