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/project/data.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Paths to temporary files used by the project.7*/89import { join } from "path";10import { data } from "@cocalc/backend/data";11import { is_valid_uuid_string } from "@cocalc/util/misc";12import { pidFilename } from "@cocalc/util/project-info";1314export const infoJson = join(data, "info.json");15export const hubPortFile = join(data, "hub-server.port");16export const apiServerPortFile = join(data, "api-server.port");17export const browserPortFile = join(data, "browser-server.port");18export const projectPidFile = join(data, pidFilename);19export const startTimestampFile = join(data, "start-timestamp.txt");20export const sessionIDFile = join(data, "session-id.txt");21export const rootSymlink = join(data, "root");22export const SSH_LOG = join(data, "sshd.log");23export const SSH_ERR = join(data, "sshd.err");24export const secretToken =25process.env.COCALC_SECRET_TOKEN ?? join(data, "secret_token");2627// note that the "username" need not be the output of `whoami`, e.g.,28// when using a cc-in-cc dev project where users are "virtual".29function getIDs() {30let project_id, username;31if (process.env.COCALC_PROJECT_ID && process.env.COCALC_USERNAME) {32project_id = process.env.COCALC_PROJECT_ID;33username = process.env.COCALC_USERNAME;34} else {35if (!process.env.HOME) {36throw Error("HOME not defined, so no way to determine project_id");37}38const v = process.env.HOME.split("/");39project_id = v[v.length - 1];40if (!is_valid_uuid_string(project_id)) {41throw Error("unable to determine project_id from HOME directory path");42}43username = project_id.replace(/-/g, "");44}45// Throw in some consistency checks:46if (!is_valid_uuid_string(project_id)) {47throw Error(`project_id=${project_id} is not a valid UUID`);48}49if (!username) {50throw Error("unable to determine username");51}52return { project_id, username };53}5455export const { project_id, username } = getIDs();565758