import { join } from "path" ; import { data } from "@cocalc/backend/data" ; import { is_valid_uuid_string } from "@cocalc/util/misc" ; export const infoJson = join ( data , "info.json" ) ; export const hubPortFile = join ( data , "hub-server.port" ) ; export const apiServerPortFile = join ( data , "api-server.port" ) ; export const browserPortFile = join ( data , "browser-server.port" ) ; export const projectPidFile = join ( data , "project.pid" ) ; export const rootSymlink = join ( data , "root" ) ; export const secretToken = process . env . COCALC_SECRET_TOKEN ?? join ( data , "secret_token" ) ; function getIDs ( ) { let project_id , username ; if ( process . env . COCALC_PROJECT_ID && process . env . COCALC_USERNAME ) { project_id = process . env . COCALC_PROJECT_ID ; username = process . env . COCALC_USERNAME ; } else { if ( ! process . env . HOME ) { throw Error ( "HOME not defined, so no way to determine project_id" ) ; } const v = process . env . HOME . split ( "/" ) ; project_id = v [ v . length - 1 ] ; if ( ! is_valid_uuid_string ( project_id ) ) { throw Error ( "unable to determine project_id from HOME directory path" ) ; } username = project_id . replace ( /-/g , "" ) ; } if ( ! is_valid_uuid_string ( project_id ) ) { throw Error ( `project_id=${ project_id } is not a valid UUID` ) ; } if ( ! username ) { throw Error ( "unable to determine username" ) ; } return { project_id , username } ; } export const { project_id , username } = getIDs ( ) ;