Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Te server refactor 1 #1864

Open
wants to merge 12 commits into
base: edge
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
build/
prod.env
xids.csv
preprod.env
preprod.env
.venv
jigsaw-vertex-integration-92ef30330cf7.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems oddly specific, but ok.
alternatively try a wildcard like jigsaw-vertex-integration*.json

1 change: 1 addition & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
logs/
node_modules/
npm-debug.log*
.venv/
50 changes: 50 additions & 0 deletions server/src/routes/dataExport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

import User from "../user";
import { doAddDataExportTask } from "../utils/common";
import Config from "../config";
import fail from "../utils/fail";
import AWS from "aws-sdk";

AWS.config.update({ region: Config.awsRegion });
const s3Client = new AWS.S3({ apiVersion: "2006-03-01" });

function handle_GET_dataExport(
req: { p: { uid?: any; zid: any; unixTimestamp: number; format: any } },
res: { json: (arg0: {}) => void }
) {
const getUserInfoForUid2 = User.getUserInfoForUid2;
getUserInfoForUid2(req.p.uid)
.then((user: { email: any }) => {
return doAddDataExportTask(
Config.mathEnv,
user.email,
req.p.zid,
req.p.unixTimestamp * 1000,
req.p.format,
Math.abs((Math.random() * 999999999999) >> 0)
)
.then(() => {
res.json({});
})
.catch((err: any) => {
fail(res, 500, "polis_err_data_export123", err);
});
})
.catch((err: any) => {
fail(res, 500, "polis_err_data_export123b", err);
});
}

function handle_GET_dataExport_results(
req: { p: { filename: string } },
res: { redirect: (arg0: any) => void }
) {
var url = s3Client.getSignedUrl("getObject", {
Bucket: "polis-datadump",
Key: Config.mathEnv + "/" + req.p.filename,
Expires: 60 * 60 * 24 * 7,
});
res.redirect(url);
}

export { handle_GET_dataExport, handle_GET_dataExport_results }
36 changes: 36 additions & 0 deletions server/src/routes/launchPrep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Utils from "../utils/common";
import cookies from "../utils/cookies";
import Session from "../session";
const COOKIES = cookies.COOKIES;

const setPermanentCookie = cookies.setPermanentCookie;
const setCookieTestCookie = cookies.setCookieTestCookie;
const makeSessionToken = Session.makeSessionToken;

function handle_GET_launchPrep(
req: {
headers?: { origin: string };
cookies: { [x: string]: any };
p: { dest: any };
},
res: { redirect: (arg0: any) => void }
) {
if (!req.cookies[COOKIES.PERMANENT_COOKIE]) {
setPermanentCookie(req, res, makeSessionToken());
}
setCookieTestCookie(req, res);

// Argument of type '{ redirect: (arg0: any) => void; }' is not assignable to parameter of type '{ cookie: (arg0: any, arg1: any, arg2: any) => void; }'.
// Property 'cookie' is missing in type '{ redirect: (arg0: any) => void; }' but required in type '{ cookie: (arg0: any, arg1: any, arg2: any) => void; }'.ts(2345)
// @ts-ignore
setCookie(req, res, "top", "ok", {
httpOnly: false, // not httpOnly - needed by JS
});

// using hex since it doesn't require escaping like base64.
const dest = Utils.hexToStr(req.p.dest);
const url = new URL(dest);
res.redirect(url.pathname + url.search + url.hash);
}

export default handle_GET_launchPrep;
Loading
Loading