Spaces:
Running
Running
JOHN SILLVESTOR commited on
Upgrade disk slice cache limit to 24 GB per node
Browse files
server.js
CHANGED
|
@@ -56,8 +56,8 @@ const UID_TITLE_MAX = 48;
|
|
| 56 |
const TITLE_PIPE_MAX = 15000;
|
| 57 |
const GLOBAL_PIPE_MAX = 15000;
|
| 58 |
const DISK_SLICE_DIR = "/tmp/dlk_slice";
|
| 59 |
-
const DISK_MAX_BYTES =
|
| 60 |
-
const DISK_FREE_MIN_BYTES =
|
| 61 |
const HOT_BYTES_MAX = Math.min(1536 * MB, Math.max(512 * MB, Math.floor(RAM_BYTES * 0.1)));
|
| 62 |
const BODY_MAX = 262144;
|
| 63 |
const FILE_TTL = 20 * 60 * 1000;
|
|
@@ -738,6 +738,42 @@ function handleBrand(req, res) {
|
|
| 738 |
res.end(buf);
|
| 739 |
}
|
| 740 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 741 |
async function accessLevel(uid) {
|
| 742 |
if (!uid) return "anonymous";
|
| 743 |
const hit = lvlCache.get(uid);
|
|
@@ -2846,6 +2882,7 @@ async function onReq(req, res) {
|
|
| 2846 |
try {
|
| 2847 |
if (url.pathname === "/") return handleHome(req, res);
|
| 2848 |
if (url.pathname === "/health") return handleHealth(req, res);
|
|
|
|
| 2849 |
if (url.pathname === "/public/brand.png" && (req.method === "GET" || req.method === "HEAD")) return handleBrand(req, res);
|
| 2850 |
if (url.pathname === "/public/bootstrap") return handleBootstrap(req, res, url);
|
| 2851 |
if (url.pathname === "/admin/tg-meta" && (req.method === "GET" || req.method === "POST")) return handleTgMeta(req, res, url);
|
|
|
|
| 56 |
const TITLE_PIPE_MAX = 15000;
|
| 57 |
const GLOBAL_PIPE_MAX = 15000;
|
| 58 |
const DISK_SLICE_DIR = "/tmp/dlk_slice";
|
| 59 |
+
const DISK_MAX_BYTES = 24 * 1024 * 1024 * 1024;
|
| 60 |
+
const DISK_FREE_MIN_BYTES = 4 * 1024 * 1024 * 1024;
|
| 61 |
const HOT_BYTES_MAX = Math.min(1536 * MB, Math.max(512 * MB, Math.floor(RAM_BYTES * 0.1)));
|
| 62 |
const BODY_MAX = 262144;
|
| 63 |
const FILE_TTL = 20 * 60 * 1000;
|
|
|
|
| 738 |
res.end(buf);
|
| 739 |
}
|
| 740 |
|
| 741 |
+
const POSTER_DIR = path.join(__dirname, "posters");
|
| 742 |
+
const POSTER_RE = /^[a-z0-9][a-z0-9-]{0,90}\.webp$/;
|
| 743 |
+
const posterMemCache = new Map();
|
| 744 |
+
|
| 745 |
+
async function handlePoster(req, res, url) {
|
| 746 |
+
const m = /^\/public\/posters\/([a-zA-Z0-9-]+\.webp)$/.exec(url.pathname);
|
| 747 |
+
if (!m || !POSTER_RE.test(m[1])) {
|
| 748 |
+
res.writeHead(404);
|
| 749 |
+
return res.end();
|
| 750 |
+
}
|
| 751 |
+
const name = m[1];
|
| 752 |
+
let buf = posterMemCache.get(name);
|
| 753 |
+
if (!buf) {
|
| 754 |
+
try {
|
| 755 |
+
buf = await fs.promises.readFile(path.join(POSTER_DIR, name));
|
| 756 |
+
if (buf && buf.length) posterMemCache.set(name, buf);
|
| 757 |
+
} catch {
|
| 758 |
+
res.writeHead(404);
|
| 759 |
+
return res.end();
|
| 760 |
+
}
|
| 761 |
+
}
|
| 762 |
+
res.writeHead(200, {
|
| 763 |
+
"Content-Type": "image/webp",
|
| 764 |
+
"Content-Length": String(buf.length),
|
| 765 |
+
"Cache-Control": "public, max-age=31536000, immutable",
|
| 766 |
+
"Cross-Origin-Resource-Policy": "cross-origin",
|
| 767 |
+
"Access-Control-Allow-Origin": "*",
|
| 768 |
+
"X-Content-Type-Options": "nosniff",
|
| 769 |
+
"X-Robots-Tag": "noindex, nofollow",
|
| 770 |
+
"Referrer-Policy": "no-referrer",
|
| 771 |
+
"Strict-Transport-Security": "max-age=15552000; includeSubDomains"
|
| 772 |
+
});
|
| 773 |
+
if (req.method === "HEAD") return res.end();
|
| 774 |
+
res.end(buf);
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
async function accessLevel(uid) {
|
| 778 |
if (!uid) return "anonymous";
|
| 779 |
const hit = lvlCache.get(uid);
|
|
|
|
| 2882 |
try {
|
| 2883 |
if (url.pathname === "/") return handleHome(req, res);
|
| 2884 |
if (url.pathname === "/health") return handleHealth(req, res);
|
| 2885 |
+
if (url.pathname.startsWith("/public/posters/")) return handlePoster(req, res, url);
|
| 2886 |
if (url.pathname === "/public/brand.png" && (req.method === "GET" || req.method === "HEAD")) return handleBrand(req, res);
|
| 2887 |
if (url.pathname === "/public/bootstrap") return handleBootstrap(req, res, url);
|
| 2888 |
if (url.pathname === "/admin/tg-meta" && (req.method === "GET" || req.method === "POST")) return handleTgMeta(req, res, url);
|