kopia lustrzana https://github.com/harvard-lil/archive.social
Version bump, nunjucks envs
rodzic
8e30fe2350
commit
65315dcaa6
|
@ -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. |
|
||||
| `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. |
|
||||
| `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. |
|
||||
|
|
|
@ -30,9 +30,11 @@ export const TMP_PATH = `${process.env.PWD}/app/tmp/`;
|
|||
|
||||
/**
|
||||
* Path to the "templates" folder.
|
||||
* Defaults to `./app/templates`
|
||||
* Can be replaced via the `TEMPLATES_PATH` env variable.
|
||||
* @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`.
|
||||
|
|
|
@ -17,6 +17,10 @@ import {
|
|||
REQUIRE_ACCESS_KEY
|
||||
} from "./const.js";
|
||||
|
||||
/**
|
||||
* @type {nunjucks.Environment}
|
||||
*/
|
||||
const nunjucksEnv = new nunjucks.Environment(new nunjucks.FileSystemLoader(TEMPLATES_PATH));
|
||||
|
||||
/**
|
||||
* @type {SuccessLog}
|
||||
|
@ -75,7 +79,7 @@ export default async function (fastify, opts) {
|
|||
reply
|
||||
.code(404)
|
||||
.type('text/html')
|
||||
.send(nunjucks.render(`${TEMPLATES_PATH}404.njk`));
|
||||
.send(nunjucksEnv.render(`404.njk`));
|
||||
});
|
||||
|
||||
fastify.get('/', index);
|
||||
|
@ -96,7 +100,7 @@ export default async function (fastify, opts) {
|
|||
* @returns {Promise<fastify.FastifyReply>}
|
||||
*/
|
||||
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
|
||||
.code(200)
|
||||
|
@ -135,7 +139,7 @@ async function capture(request, reply) {
|
|||
// Check that IP is not in block list
|
||||
//
|
||||
if (ipBlockList.check(ip)) {
|
||||
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, {
|
||||
const html = nunjucksEnv.render(`index.njk`, {
|
||||
error: true,
|
||||
errorReason: "IP",
|
||||
REQUIRE_ACCESS_KEY
|
||||
|
@ -156,7 +160,7 @@ async function capture(request, reply) {
|
|||
assert(accessKeys.check(accessKey));
|
||||
}
|
||||
catch(err) {
|
||||
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, {
|
||||
const html = nunjucksEnv.render(`index.njk`, {
|
||||
error: true,
|
||||
errorReason: "ACCESS-KEY",
|
||||
REQUIRE_ACCESS_KEY
|
||||
|
@ -177,7 +181,7 @@ async function capture(request, reply) {
|
|||
assert(url.origin === "https://twitter.com");
|
||||
}
|
||||
catch(err) {
|
||||
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, {
|
||||
const html = nunjucksEnv.render(`index.njk`, {
|
||||
error: true,
|
||||
errorReason: "URL",
|
||||
REQUIRE_ACCESS_KEY
|
||||
|
@ -197,7 +201,7 @@ async function capture(request, reply) {
|
|||
assert(why.length > 0);
|
||||
}
|
||||
catch(err) {
|
||||
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, {
|
||||
const html = nunjucksEnv.render(`index.njk`, {
|
||||
error: true,
|
||||
errorReason: "WHY",
|
||||
REQUIRE_ACCESS_KEY
|
||||
|
@ -213,7 +217,7 @@ async function capture(request, reply) {
|
|||
// Check that there is still capture capacity (total)
|
||||
//
|
||||
if (CAPTURES_WATCH.currentTotal >= CAPTURES_WATCH.maxTotal) {
|
||||
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, {
|
||||
const html = nunjucksEnv.render(`index.njk`, {
|
||||
error: true,
|
||||
errorReason: "TOO-MANY-CAPTURES-TOTAL",
|
||||
REQUIRE_ACCESS_KEY
|
||||
|
@ -229,7 +233,7 @@ async function capture(request, reply) {
|
|||
// Check that there is still capture capacity (for this IP)
|
||||
//
|
||||
if (CAPTURES_WATCH.currentByIp[ip] >= CAPTURES_WATCH.maxPerIp) {
|
||||
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, {
|
||||
const html = nunjucksEnv.render(`index.njk`, {
|
||||
error: true,
|
||||
errorReason: "TOO-MANY-CAPTURES-USER",
|
||||
REQUIRE_ACCESS_KEY
|
||||
|
@ -281,7 +285,7 @@ async function capture(request, reply) {
|
|||
catch(err) {
|
||||
request.log.error(`Capture failed. ${err}`);
|
||||
|
||||
const html = nunjucks.render(`${TEMPLATES_PATH}index.njk`, {
|
||||
const html = nunjucksEnv.render(`index.njk`, {
|
||||
error: true,
|
||||
errorReason: "CAPTURE-ISSUE",
|
||||
REQUIRE_ACCESS_KEY
|
||||
|
@ -312,7 +316,7 @@ async function capture(request, reply) {
|
|||
* @returns {Promise<fastify.FastifyReply>}
|
||||
*/
|
||||
async function check(request, reply) {
|
||||
const html = nunjucks.render(`${TEMPLATES_PATH}check.njk`, {
|
||||
const html = nunjucksEnv.render(`check.njk`, {
|
||||
signingCertsHistory: CertsHistory.load("signing"),
|
||||
timestampsCertsHistory: CertsHistory.load("timestamping")
|
||||
});
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "thread-keeper",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "thread-keeper",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"hasInstallScript": true,
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "thread-keeper",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"description": "",
|
||||
"main": "app.js",
|
||||
"type": "module",
|
||||
|
|
Ładowanie…
Reference in New Issue