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/client/handle-target.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { hasRememberMe } from "@cocalc/frontend/misc/remember-me";6import { join } from "path";7import { appBasePath } from "@cocalc/frontend/customize/app-base-path";8import { encode_path } from "@cocalc/util/misc";910export const IS_EMBEDDED = new URL(location.href).pathname.endsWith(11"embed.html"12);1314function handleTarget(): string {15// See src/packages/hub/servers/app/app-redirect.ts where if16// there is a path after the base url, we redirect to static/app.html17// and put that path in a query param called 'target'.18const u = new URL(location.href);19let t = u.searchParams.get("target") ?? "";20// We use the URL object and a fake host to parse things, since it's much21// more secure/robust than parsing it directly.22const url = new URL("http://" + join("host", t));23let target = decodeURIComponent(url.pathname.slice(1));24if (!target) {25// if no target is encoded in the url:26if (hasRememberMe(appBasePath)) {27// probably signed in -- show user their list of projects28target = "projects";29} else {30// not signed in -- show sign in page (which is currently part of "settings", which is dumb)31target = "settings";32}33}34if (!IS_EMBEDDED) {35u.searchParams.delete("target");36u.searchParams.forEach((val, key) => {37url.searchParams.set(key, val);38});39// Write the full url for the given target, preserving any search (except target) and fragment parts of the url.40const fullUrl =41document.location.origin +42join(appBasePath, encode_path(target)) +43url.search +44u.hash;45history.pushState({}, "", fullUrl);46}47return target;48}4950const target: string = handleTarget();5152export default target;535455