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/common.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { to_json, trunc } from "@cocalc/util/misc";67import { getLogger } from "./logger";8const winston = getLogger("common");910function envVarToInt(name: string, fallback: number): number {11const x = process.env[name];12if (x == null) {13return fallback;14}15const y = parseInt(x);16if (isNaN(y)) {17return fallback;18}19return y;20}2122// We make it an error for a client to try to edit a file larger than MAX_FILE_SIZE.23// I decided on this, because attempts to open a much larger file leads24// to disaster. Opening a 10MB file works but is a just a little slow.25const MAX_FILE_SIZE =261000 * 1000 * envVarToInt("COCALC_PROJECT_MAX_FILE_SIZE_MB", 10); // in bytes27winston.debug(`MAX_FILE_SIZE = ${MAX_FILE_SIZE} bytes`);2829export function check_file_size(size): string | undefined {30if (size != null && size > MAX_FILE_SIZE) {31const e = `Attempt to open large file of size ${Math.round(32size / 100000033)}MB; the maximum allowed size is ${Math.round(34MAX_FILE_SIZE / 100000035)}MB. Use vim, emacs, or pico from a terminal instead.`;36winston.debug(e);37return e;38}39}4041export function json(out): string {42return trunc(to_json(out), 500);43}444546