import { to_json, trunc } from "@cocalc/util/misc";
import { getLogger } from "./logger";
const winston = getLogger("common");
function envVarToInt(name: string, fallback: number): number {
const x = process.env[name];
if (x == null) {
return fallback;
}
const y = parseInt(x);
if (isNaN(y)) {
return fallback;
}
return y;
}
const MAX_FILE_SIZE =
1000 * 1000 * envVarToInt("COCALC_PROJECT_MAX_FILE_SIZE_MB", 10);
winston.debug(`MAX_FILE_SIZE = ${MAX_FILE_SIZE} bytes`);
export function check_file_size(size): string | undefined {
if (size != null && size > MAX_FILE_SIZE) {
const e = `Attempt to open large file of size ${Math.round(
size / 1000000
)}MB; the maximum allowed size is ${Math.round(
MAX_FILE_SIZE / 1000000
)}MB. Use vim, emacs, or pico from a terminal instead.`;
winston.debug(e);
return e;
}
}
export function json(out): string {
return trunc(to_json(out), 500);
}