2022-11-15 16:53:23 +00:00
|
|
|
/**
|
2022-11-22 19:08:28 +00:00
|
|
|
* thread-keeper
|
2022-11-24 07:20:30 +00:00
|
|
|
* @module const
|
2022-11-15 16:53:23 +00:00
|
|
|
* @author The Harvard Library Innovation Lab
|
|
|
|
* @license MIT
|
|
|
|
*/
|
2022-11-24 07:20:30 +00:00
|
|
|
import fs from "fs";
|
2022-11-15 16:53:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Path to the folder holding the certificates used for signing the PDFs.
|
2022-11-29 20:39:08 +00:00
|
|
|
* Defaults to `./certs`
|
|
|
|
* Can be replaced via the `CERTS_PATH` env variable.
|
2022-11-15 16:53:23 +00:00
|
|
|
* @constant
|
|
|
|
*/
|
2022-11-18 19:18:32 +00:00
|
|
|
export const CERTS_PATH = process.env.CERTS_PATH ? process.env.CERTS_PATH : `${process.env.PWD}/certs/`;
|
2022-11-15 16:53:23 +00:00
|
|
|
|
|
|
|
/**
|
2022-11-18 19:18:32 +00:00
|
|
|
* Path to the "data" folder.
|
2022-11-29 20:39:08 +00:00
|
|
|
* Defaults to `./app/data`
|
|
|
|
* Can be replaced via the `DATA_PATH` env variable.
|
2022-11-21 17:30:34 +00:00
|
|
|
* @constant
|
2022-11-15 16:53:23 +00:00
|
|
|
*/
|
2022-11-18 19:56:50 +00:00
|
|
|
export const DATA_PATH = process.env.DATA_PATH ? process.env.DATA_PATH : `${process.env.PWD}/app/data/`;
|
2022-11-15 16:53:23 +00:00
|
|
|
|
|
|
|
/**
|
2022-11-18 19:18:32 +00:00
|
|
|
* Path to the folder in which temporary files will be written by the app.
|
|
|
|
* @constant
|
2022-11-15 16:53:23 +00:00
|
|
|
*/
|
2022-11-18 19:18:32 +00:00
|
|
|
export const TMP_PATH = `${process.env.PWD}/app/tmp/`;
|
2022-11-15 16:53:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Path to the "templates" folder.
|
2022-11-21 17:30:34 +00:00
|
|
|
* @constant
|
2022-11-15 16:53:23 +00:00
|
|
|
*/
|
|
|
|
export const TEMPLATES_PATH = `${process.env.PWD}/app/templates/`;
|
|
|
|
|
|
|
|
/**
|
2022-11-21 17:30:34 +00:00
|
|
|
* Path to the "executables" folder, for dependencies that are meant to be executed directly, such as `yt-dlp`.
|
|
|
|
* @constant
|
2022-11-15 16:53:23 +00:00
|
|
|
*/
|
2022-11-21 17:30:34 +00:00
|
|
|
export const EXECUTABLES_FOLDER = `${process.env.PWD}/executables/`;
|
2022-11-15 16:53:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Path to the "static" folder.
|
2022-11-21 17:30:34 +00:00
|
|
|
* @constant
|
2022-11-15 16:53:23 +00:00
|
|
|
*/
|
|
|
|
export const STATIC_PATH = `${process.env.PWD}/app/static/`;
|
|
|
|
|
2022-11-29 20:39:08 +00:00
|
|
|
/**
|
|
|
|
* If `true`, users will be required to provide an access key.
|
|
|
|
* Defaults to `false`.
|
|
|
|
* Can be replaced via the `REQUIRE_ACCESS_KEY` env variable, if set to "1".
|
|
|
|
* @constant
|
|
|
|
*/
|
|
|
|
export const REQUIRE_ACCESS_KEY = process.env.REQUIRE_ACCESS_KEY === "1" ? true : false;
|
|
|
|
|
2022-11-15 16:53:23 +00:00
|
|
|
/**
|
|
|
|
* Maximum capture processes that can be run in parallel.
|
2022-11-29 20:39:08 +00:00
|
|
|
* Defaults to 50.
|
|
|
|
* Can be replaced via the `MAX_PARALLEL_CAPTURES_TOTAL` env variable.
|
2022-11-21 17:30:34 +00:00
|
|
|
* @constant
|
2022-11-15 16:53:23 +00:00
|
|
|
*/
|
2022-11-29 20:39:08 +00:00
|
|
|
export const MAX_PARALLEL_CAPTURES_TOTAL = (() => {
|
|
|
|
const fromEnv = parseInt(process.env.MAX_PARALLEL_CAPTURES_TOTAL);
|
|
|
|
|
|
|
|
if (!isNaN(fromEnv) && fromEnv > 0) {
|
|
|
|
return fromEnv;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
})();
|
2022-11-15 16:53:23 +00:00
|
|
|
|
|
|
|
/**
|
2022-11-29 20:39:08 +00:00
|
|
|
* Maximum capture processes that can be run in parallel for a given IP address.
|
|
|
|
* Defaults to:
|
|
|
|
* - 2 if REQUIRE_ACCESS_KEY is `false`
|
|
|
|
* - 10 if REQUIRE_ACCESS_KEY is `true`
|
|
|
|
* Can be replaced via the `MAX_PARALLEL_CAPTURES_PER_IP` env variable.
|
2022-11-21 17:30:34 +00:00
|
|
|
* @constant
|
2022-11-15 16:53:23 +00:00
|
|
|
*/
|
2022-11-29 20:39:08 +00:00
|
|
|
export const MAX_PARALLEL_CAPTURES_PER_IP = (() => {
|
|
|
|
const fromEnv = parseInt(process.env.MAX_PARALLEL_CAPTURES_PER_IP);
|
|
|
|
|
|
|
|
if (!isNaN(fromEnv) && fromEnv > 0) {
|
|
|
|
return fromEnv;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return REQUIRE_ACCESS_KEY ? 10 : 2;
|
|
|
|
}
|
|
|
|
})();
|
2022-11-24 07:20:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* APP version. Pulled from `package.json` by default.
|
|
|
|
* @constant
|
|
|
|
*/
|
|
|
|
export const APP_VERSION = (() => {
|
|
|
|
const appPackage = JSON.parse(fs.readFileSync("./package.json"));
|
|
|
|
return appPackage?.version ? appPackage.version : "0.0.0";
|
|
|
|
})();
|