nerdgram1337 1.4.6 → 1.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,111 +1,17 @@
1
1
  import {
2
- diagramInitConfig,
3
2
  locateParseError
4
- } from "./chunk-KO565WWM.js";
3
+ } from "./chunk-54BVSMKR.js";
4
+ import {
5
+ httpFail,
6
+ sanitizeThumbnailSvg
7
+ } from "./chunk-ULY5YEBR.js";
8
+ import {
9
+ diagramInitConfig
10
+ } from "./chunk-AFGGIQ22.js";
5
11
 
6
12
  // server/src/renderDiagram.ts
7
13
  import { createRequire } from "node:module";
8
14
  import puppeteer from "puppeteer";
9
-
10
- // server/src/paths.ts
11
- import path from "node:path";
12
- import { fileURLToPath } from "node:url";
13
-
14
- // server/src/instanceConfig.ts
15
- var processStartDataDir = process.env.NERDGRAM_DATA_DIR?.trim() || null;
16
-
17
- // server/src/paths.ts
18
- var __dirname = path.dirname(fileURLToPath(import.meta.url));
19
- var REPO_ROOT = path.resolve(__dirname, "../..");
20
-
21
- // server/src/storage.ts
22
- function httpFail(status, message, code, details) {
23
- return Object.assign(new Error(message), { status, code, details });
24
- }
25
-
26
- // server/src/thumbnails.ts
27
- import * as cheerio from "cheerio";
28
-
29
- // server/src/readError.ts
30
- var READ_REASONS = {
31
- EIO: "The file may still be syncing or the folder may be unavailable on this computer",
32
- EACCES: "This computer does not have permission to read the file",
33
- EPERM: "This computer does not have permission to read the file",
34
- ENOENT: "The file was removed or renamed before it could be read",
35
- EBUSY: "The file is busy and could not be read",
36
- ETIMEDOUT: "Reading the file timed out. The folder may be slow or unavailable"
37
- };
38
- var KNOWN_READ_ERRNOS = new Set(Object.keys(READ_REASONS));
39
-
40
- // server/src/svgImage.ts
41
- function svgForImage(svg) {
42
- if (!/xlink:/i.test(svg) || /xmlns:xlink\s*=/i.test(svg)) return svg;
43
- return svg.replace(/<svg\b/i, '<svg xmlns:xlink="http://www.w3.org/1999/xlink"');
44
- }
45
-
46
- // server/src/thumbnails.ts
47
- var URL_ATTRS = /* @__PURE__ */ new Set(["href", "xlink:href", "src"]);
48
- function decodeUrl(value) {
49
- return value.replace(/&#x([0-9a-f]+);/gi, (_, hex) => {
50
- const code = Number.parseInt(hex, 16);
51
- return Number.isFinite(code) ? String.fromCodePoint(code) : "";
52
- }).replace(/&#(\d+);/g, (_, num) => {
53
- const code = Number.parseInt(num, 10);
54
- return Number.isFinite(code) ? String.fromCodePoint(code) : "";
55
- }).replace(/[\u0000-\u0020]+/g, "").trim().toLowerCase();
56
- }
57
- function isDangerousUrl(value) {
58
- const decoded = decodeUrl(value);
59
- return decoded.startsWith("javascript:") || decoded.startsWith("vbscript:") || decoded.startsWith("data:text/html") || decoded.startsWith("data:application/xhtml");
60
- }
61
- function sanitizeThumbnailSvg(svg) {
62
- const trimmed = svg.trim();
63
- if (!trimmed) return svg;
64
- let changed = false;
65
- const $ = cheerio.load(trimmed, { xml: true });
66
- $("*").each((_, el) => {
67
- if (el.type !== "tag" && el.type !== "script") return;
68
- const name = el.name.toLowerCase();
69
- if (name === "script" || name === "iframe" || name === "object" || name === "embed" || name === "link" || name === "meta" || name === "base") {
70
- $(el).remove();
71
- changed = true;
72
- return;
73
- }
74
- const attribs = el.attribs;
75
- for (const [attr, raw] of Object.entries(attribs)) {
76
- const lower = attr.toLowerCase();
77
- const value = raw ?? "";
78
- if (lower.startsWith("on")) {
79
- $(el).removeAttr(attr);
80
- changed = true;
81
- continue;
82
- }
83
- if (URL_ATTRS.has(lower) || lower.endsWith(":href")) {
84
- if (isDangerousUrl(value)) {
85
- $(el).removeAttr(attr);
86
- changed = true;
87
- }
88
- }
89
- if (lower === "style" && /javascript\s*:|expression\s*\(|behavior\s*:|-moz-binding|@import/i.test(value)) {
90
- $(el).removeAttr(attr);
91
- changed = true;
92
- }
93
- if ((name === "set" || name === "animate" || name === "animatetransform") && lower === "attributename" && (value.toLowerCase().startsWith("on") || value.toLowerCase() === "href" || value.toLowerCase().endsWith(":href"))) {
94
- $(el).remove();
95
- changed = true;
96
- }
97
- }
98
- });
99
- const structured = changed ? $.xml().trim() : trimmed;
100
- const swept = structured.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<script\b[^>]*\/?>/gi, "").replace(/\s+on[a-z]+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi, "").replace(
101
- /(\s(?:href|xlink:href|src)\s*=\s*)(["'])\s*(?:javascript|vbscript):[^"']*\2/gi,
102
- "$1$2#$2"
103
- );
104
- const cleaned = swept === svg || swept === trimmed ? svg : swept;
105
- return svgForImage(cleaned);
106
- }
107
-
108
- // server/src/renderDiagram.ts
109
15
  var require2 = createRequire(import.meta.url);
110
16
  var MAX_RENDER_SOURCE_CHARS = 512 * 1024;
111
17
  var MAX_RENDER_SVG_CHARS = 2e6;