From 6e259192e4a6b03c0c70957fe9397fb56e8d1dc8 Mon Sep 17 00:00:00 2001 From: tevko Date: Wed, 18 Dec 2024 13:58:48 -0600 Subject: [PATCH] move launchPrep route --- server/src/routes/launchPrep.ts | 36 +++++++++++++++++++++++ server/src/server.ts | 51 ++------------------------------- 2 files changed, 38 insertions(+), 49 deletions(-) create mode 100644 server/src/routes/launchPrep.ts diff --git a/server/src/routes/launchPrep.ts b/server/src/routes/launchPrep.ts new file mode 100644 index 000000000..5a19f8d15 --- /dev/null +++ b/server/src/routes/launchPrep.ts @@ -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; diff --git a/server/src/server.ts b/server/src/server.ts index c56805b37..d55bb43dc 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -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, @@ -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; @@ -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 = @@ -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: { @@ -12543,10 +12500,6 @@ Thanks for using Polis! handle_PUT_ptptois, handle_PUT_reports, handle_PUT_users, - - // Debugging - //getNextPrioritizedComment, - //getPca }; return returnObject; }