Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/app/query-params.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// Initialize various things related to the overall page and query params (e.g., fullscreen).6import { redux } from "@cocalc/frontend/app-framework";7import target from "@cocalc/frontend/client/handle-target";8import { appBasePath } from "@cocalc/frontend/customize/app-base-path";9import { COCALC_FULLSCREEN } from "@cocalc/frontend/fullscreen";10import { parse_target } from "@cocalc/frontend/history";11import {12get_local_storage,13set_local_storage,14} from "@cocalc/frontend/misc/local-storage";15import { QueryParams } from "@cocalc/frontend/misc/query-params";16import { is_valid_uuid_string } from "@cocalc/util/misc";1718export function init_query_params(): void {19const actions = redux.getActions("page");20// enable fullscreen mode upon loading a URL like /app?fullscreen and21// additionally kiosk-mode upon /app?fullscreen=kiosk22if (COCALC_FULLSCREEN === "kiosk") {23actions.set_fullscreen("kiosk");24// We also check if user is loading a specific project in kiosk mode25// (which is the only thing they should ever do!), and in that26// case we record the project_id, so that we can make various27// query optimizations elsewhere.28const x = parse_target(target);29if (x.page === "project" && x.target != null) {30const kiosk_project_id = x.target.slice(0, 36);31if (is_valid_uuid_string(kiosk_project_id)) {32actions.setState({ kiosk_project_id });33}34}35} else if (COCALC_FULLSCREEN === "default") {36actions.set_fullscreen("default");37// We no longer need fullscreen in the query parameter:38QueryParams.remove("fullscreen");39} else if (COCALC_FULLSCREEN === "project") {40actions.set_fullscreen("project");41}4243const get_api_key_query_value = QueryParams.get("get_api_key");44if (get_api_key_query_value) {45actions.set_get_api_key(get_api_key_query_value);46actions.set_fullscreen("project");47}4849// configure the session50// This makes it so the default session is 'default' and there is no51// way to NOT have a session, except via session=, which is treated52// as "no session" (also no session for kiosk mode).53// Note that we never have a session in kiosk mode, since you can't54// access the other files.55// If click on link with ?session=, then you get no session, e.g,. this56// is used for doing a pop-out of a single file. Should have no impact57// on sessions at all.58if (COCALC_FULLSCREEN === "kiosk") {59actions.set_session(""); // no session60} else {61const key = `session${appBasePath}`;62const querySession = QueryParams.get("session");63let session: any = querySession ?? get_local_storage(key) ?? "default";6465if (typeof session != "string") {66// should never happen, but of course it could since user could put anything in URL query params67// We just reset to default in this case.68session = "default";69}70actions.set_session(session);71if (session) {72// So when you don't give session= param in this browser in the future73// it defaults to the one you did use (or "default").74set_local_storage(key, session);75}76}77// Do not need or want it in our URL once we've consumed it. Critical to78// not have session in the URL, so we can share url's without infected79// other user's session.80QueryParams.remove("session");81}828384