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/next/lib/share/edit-url.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { join } from "path";6import basePath from "lib/base-path";78interface AnonymousOptions {9id: string;10path: string;11relativePath: string;12type: "anonymous";13}1415interface CollaboratorOptions {16project_id: string;17path?: string; // no path means link to project18relativePath?: string;19type?: "collaborator";20}2122type Options = AnonymousOptions | CollaboratorOptions;2324export default function editURL(options: Options): string {25const type = options["type"];26switch (type) {27case "anonymous":28return anonymousURL(options);29case "collaborator":30default:31return collaboratorURL(options);32}33}3435// needed since we're making a link outside of the nextjs server.36function withBasePath(url: string): string {37return join(basePath, url);38}3940function anonymousURL({ id, path, relativePath }): string {41const app = "/static/app.html";42return withBasePath(43encodeURI(44`${app}?anonymous=true&launch=share/${id}/${join(45path,46relativePath ?? ""47)}`48)49);50}5152function collaboratorURL({53project_id,54path,55relativePath,56}: {57project_id: string;58path?: string;59relativePath?: string;60}): string {61const projectURL = join("/projects", project_id);62if (!path) {63return withBasePath(projectURL);64}65return withBasePath(join(projectURL, "files", path, relativePath ?? ""));66}676869