Skip to content

Commit

Permalink
move launchPrep route
Browse files Browse the repository at this point in the history
  • Loading branch information
tevko committed Dec 18, 2024
1 parent 2046c4e commit 6e25919
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 49 deletions.
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;
51 changes: 2 additions & 49 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { getBidIndexToPidMapping, getPidsForGid } from "./utils/participants";
import { handle_GET_reportExport } from "./routes/export";
import { handle_GET_reportNarrative } from "./routes/reportNarrative";
import handle_DELETE_metadata_answers from "./routes/metadataAnswers";
import handle_GET_launchPrep from "./routes/launchPrep";

import {
Body,
Expand Down Expand Up @@ -209,7 +210,7 @@ const sql_reports = SQL.sql_reports;
const sql_users = SQL.sql_users;

const encrypt = Session.encrypt;
const makeSessionToken = Session.makeSessionToken;

const getUserInfoForSessionToken = Session.getUserInfoForSessionToken;
const startSession = Session.startSession;
const endSession = Session.endSession;
Expand Down Expand Up @@ -378,29 +379,11 @@ function doHeaderAuth(
});
}

// Property 'hashCode' does not exist on type 'String'.ts(2339)
// @ts-ignore
String.prototype.hashCode = function () {
let hash = 0;
let i;
let character;
if (this.length === 0) {
return hash;
}
for (i = 0; i < this.length; i++) {
character = this.charCodeAt(i);
hash = (hash << 5) - hash + character;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
};

function initializePolisHelpers() {
const polisTypes = Utils.polisTypes;
const setCookie = cookies.setCookie;
const setParentReferrerCookie = cookies.setParentReferrerCookie;
const setParentUrlCookie = cookies.setParentUrlCookie;
const setPermanentCookie = cookies.setPermanentCookie;
const setCookieTestCookie = cookies.setCookieTestCookie;
const addCookies = cookies.addCookies;
const getPermanentCookieAndEnsureItIsSet =
Expand Down Expand Up @@ -1041,32 +1024,6 @@ function initializePolisHelpers() {
////////////////////////////////////////////
////////////////////////////////////////////

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);
}

function handle_GET_tryCookie(
req: { headers?: { origin: string }; cookies: { [x: string]: any } },
res: {
Expand Down Expand Up @@ -12543,10 +12500,6 @@ Thanks for using Polis!
handle_PUT_ptptois,
handle_PUT_reports,
handle_PUT_users,

// Debugging
//getNextPrioritizedComment,
//getPca
};
return returnObject;
}
Expand Down

0 comments on commit 6e25919

Please sign in to comment.