Version bump, nunjucks envs

pull/16/head
Matteo Cargnelutti 2022-11-29 16:00:38 -05:00
rodzic 8e30fe2350
commit 65315dcaa6
5 zmienionych plików z 21 dodań i 14 usunięć

Wyświetl plik

@ -136,6 +136,7 @@ Runs the test suite. Requires test fixtures _(see `fixtures` folder)_.
| --- | --- | --- | | --- | --- | --- |
| `CERTS_PATH` | No | If set, will be used as path to `.pem` files used for signing .PDF files. | | `CERTS_PATH` | No | If set, will be used as path to `.pem` files used for signing .PDF files. |
| `DATA_PATH` | No | If set, will be used as path to folder used for storing app data. | | `DATA_PATH` | No | If set, will be used as path to folder used for storing app data. |
| `TEMPLATES_PATH` | No | If set, will be used as a templates path. Can be used to replace the website's UI with a custom one. |
| `REQUIRE_ACCESS_KEY` | No | If set and `"1"`, an access key will be required to make capture. | | `REQUIRE_ACCESS_KEY` | No | If set and `"1"`, an access key will be required to make capture. |
| `MAX_PARALLEL_CAPTURES_TOTAL` | No | If set and contains an integer, determines the maximum of captures that the server can run in parallel. | | `MAX_PARALLEL_CAPTURES_TOTAL` | No | If set and contains an integer, determines the maximum of captures that the server can run in parallel. |
| `MAX_PARALLEL_CAPTURES_PER_IP` | No | If set and contains an integer, determines the maximum of captures that a single client can run in parallel. | | `MAX_PARALLEL_CAPTURES_PER_IP` | No | If set and contains an integer, determines the maximum of captures that a single client can run in parallel. |

Wyświetl plik

@ -30,9 +30,11 @@ export const TMP_PATH = `${process.env.PWD}/app/tmp/`;
/** /**
* Path to the "templates" folder. * Path to the "templates" folder.
* Defaults to `./app/templates`
* Can be replaced via the `TEMPLATES_PATH` env variable.
* @constant * @constant
*/ */
export const TEMPLATES_PATH = `${process.env.PWD}/app/templates/`; export const TEMPLATES_PATH = process.env.TEMPLATES_PATH ? process.env.TEMPLATES_PATH : `${process.env.PWD}/app/templates/`;
/** /**
* Path to the "executables" folder, for dependencies that are meant to be executed directly, such as `yt-dlp`. * Path to the "executables" folder, for dependencies that are meant to be executed directly, such as `yt-dlp`.

Wyświetl plik

@ -17,6 +17,10 @@ import {
REQUIRE_ACCESS_KEY REQUIRE_ACCESS_KEY
} from "./const.js"; } from "./const.js";
/**
* @type {nunjucks.Environment}
*/
const nunjucksEnv = new nunjucks.Environment(new nunjucks.FileSystemLoader(TEMPLATES_PATH));
/** /**
* @type {SuccessLog} * @type {SuccessLog}
@ -75,7 +79,7 @@ export default async function (fastify, opts) {
reply reply
.code(404) .code(404)
.type('text/html') .type('text/html')
.send(nunjucks.render(`${TEMPLATES_PATH}404.njk`)); .send(nunjucksEnv.render(`404.njk`));
}); });
fastify.get('/', index); fastify.get('/', index);
@ -96,7 +100,7 @@ export default async function (fastify, opts) {
* @returns {Promise<fastify.FastifyReply>} * @returns {Promise<fastify.FastifyReply>}
*/ */
async function index(request, reply) { async function index(request, reply) {
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, {REQUIRE_ACCESS_KEY}); const html = nunjucksEnv.render(`index.njk`, {REQUIRE_ACCESS_KEY});
return reply return reply
.code(200) .code(200)
@ -135,7 +139,7 @@ async function capture(request, reply) {
// Check that IP is not in block list // Check that IP is not in block list
// //
if (ipBlockList.check(ip)) { if (ipBlockList.check(ip)) {
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, { const html = nunjucksEnv.render(`index.njk`, {
error: true, error: true,
errorReason: "IP", errorReason: "IP",
REQUIRE_ACCESS_KEY REQUIRE_ACCESS_KEY
@ -156,7 +160,7 @@ async function capture(request, reply) {
assert(accessKeys.check(accessKey)); assert(accessKeys.check(accessKey));
} }
catch(err) { catch(err) {
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, { const html = nunjucksEnv.render(`index.njk`, {
error: true, error: true,
errorReason: "ACCESS-KEY", errorReason: "ACCESS-KEY",
REQUIRE_ACCESS_KEY REQUIRE_ACCESS_KEY
@ -177,7 +181,7 @@ async function capture(request, reply) {
assert(url.origin === "https://twitter.com"); assert(url.origin === "https://twitter.com");
} }
catch(err) { catch(err) {
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, { const html = nunjucksEnv.render(`index.njk`, {
error: true, error: true,
errorReason: "URL", errorReason: "URL",
REQUIRE_ACCESS_KEY REQUIRE_ACCESS_KEY
@ -197,7 +201,7 @@ async function capture(request, reply) {
assert(why.length > 0); assert(why.length > 0);
} }
catch(err) { catch(err) {
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, { const html = nunjucksEnv.render(`index.njk`, {
error: true, error: true,
errorReason: "WHY", errorReason: "WHY",
REQUIRE_ACCESS_KEY REQUIRE_ACCESS_KEY
@ -213,7 +217,7 @@ async function capture(request, reply) {
// Check that there is still capture capacity (total) // Check that there is still capture capacity (total)
// //
if (CAPTURES_WATCH.currentTotal >= CAPTURES_WATCH.maxTotal) { if (CAPTURES_WATCH.currentTotal >= CAPTURES_WATCH.maxTotal) {
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, { const html = nunjucksEnv.render(`index.njk`, {
error: true, error: true,
errorReason: "TOO-MANY-CAPTURES-TOTAL", errorReason: "TOO-MANY-CAPTURES-TOTAL",
REQUIRE_ACCESS_KEY REQUIRE_ACCESS_KEY
@ -229,7 +233,7 @@ async function capture(request, reply) {
// Check that there is still capture capacity (for this IP) // Check that there is still capture capacity (for this IP)
// //
if (CAPTURES_WATCH.currentByIp[ip] >= CAPTURES_WATCH.maxPerIp) { if (CAPTURES_WATCH.currentByIp[ip] >= CAPTURES_WATCH.maxPerIp) {
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, { const html = nunjucksEnv.render(`index.njk`, {
error: true, error: true,
errorReason: "TOO-MANY-CAPTURES-USER", errorReason: "TOO-MANY-CAPTURES-USER",
REQUIRE_ACCESS_KEY REQUIRE_ACCESS_KEY
@ -281,7 +285,7 @@ async function capture(request, reply) {
catch(err) { catch(err) {
request.log.error(`Capture failed. ${err}`); request.log.error(`Capture failed. ${err}`);
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, { const html = nunjucksEnv.render(`index.njk`, {
error: true, error: true,
errorReason: "CAPTURE-ISSUE", errorReason: "CAPTURE-ISSUE",
REQUIRE_ACCESS_KEY REQUIRE_ACCESS_KEY
@ -312,7 +316,7 @@ async function capture(request, reply) {
* @returns {Promise<fastify.FastifyReply>} * @returns {Promise<fastify.FastifyReply>}
*/ */
async function check(request, reply) { async function check(request, reply) {
const html = nunjucks.render(`${TEMPLATES_PATH}check.njk`, { const html = nunjucksEnv.render(`check.njk`, {
signingCertsHistory: CertsHistory.load("signing"), signingCertsHistory: CertsHistory.load("signing"),
timestampsCertsHistory: CertsHistory.load("timestamping") timestampsCertsHistory: CertsHistory.load("timestamping")
}); });

4
package-lock.json wygenerowano
Wyświetl plik

@ -1,12 +1,12 @@
{ {
"name": "thread-keeper", "name": "thread-keeper",
"version": "0.0.2", "version": "0.0.3",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "thread-keeper", "name": "thread-keeper",
"version": "0.0.2", "version": "0.0.3",
"hasInstallScript": true, "hasInstallScript": true,
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {

Wyświetl plik

@ -1,6 +1,6 @@
{ {
"name": "thread-keeper", "name": "thread-keeper",
"version": "0.0.2", "version": "0.0.3",
"description": "", "description": "",
"main": "app.js", "main": "app.js",
"type": "module", "type": "module",