diff options
author | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-06 23:43:41 -0700 |
---|---|---|
committer | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-06 23:43:41 -0700 |
commit | 4fc843a84a3f3001f749d5152bdc491d8efe7f94 (patch) | |
tree | ade4c015b65635febbb5eebdd5a48281df6aa1a0 /src/server/ApiManagers/HypothesisManager.ts | |
parent | fbc7a328016af60052dd3f33c2d906e6c6447a5f (diff) | |
parent | 0438137cd435c47ce334b15a4ad00cbd70d80662 (diff) |
merge with master
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 |