crossnote 0.9.36 → 0.9.38

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.
Files changed (41) hide show
  1. package/README.md +27 -14
  2. package/out/cjs/index.cjs +321 -295
  3. package/out/cli/index.cjs +753 -135
  4. package/out/esm/index.mjs +334 -308
  5. package/out/server-app/server-app.css +1 -1
  6. package/out/server-app/server-app.js +115 -7
  7. package/out/types/src/markdown-engine/index.d.ts +34 -3
  8. package/out/types/src/notebook/types.d.ts +1 -0
  9. package/out/types/src/serve/graph-host-shim.d.ts +6 -0
  10. package/out/types/src/serve/markdown-files.d.ts +1 -0
  11. package/out/types/src/serve/preview-host-shim.d.ts +1 -0
  12. package/out/types/src/server-app/components/FilePicker.d.ts +3 -1
  13. package/out/types/src/server-app/components/LayoutView.d.ts +4 -0
  14. package/out/types/src/server-app/components/PreviewFrame.d.ts +2 -1
  15. package/out/types/src/server-app/components/TabStrip.d.ts +3 -1
  16. package/out/types/src/server-app/components/TitleBar.d.ts +3 -1
  17. package/out/types/src/server-app/components/Welcome.d.ts +2 -1
  18. package/out/types/src/server-app/lib/api.d.ts +70 -10
  19. package/out/types/src/server-app/lib/preview-theme.d.ts +1 -0
  20. package/out/types/src/server-app/lib/wiki.d.ts +20 -0
  21. package/out/types/src/server-app/types.d.ts +4 -0
  22. package/out/types/src/utility.d.ts +1 -1
  23. package/out/types/src/webview/containers/preview.d.ts +1 -0
  24. package/out/types/src/webview/lib/utility.d.ts +4 -0
  25. package/out/types/src/wiki/index.d.ts +49 -1
  26. package/out/types/test/nul-character.test.d.ts +1 -0
  27. package/out/types/test/serve/markdown-files.test.d.ts +1 -0
  28. package/out/types/test/server-app/preview-theme.test.d.ts +1 -0
  29. package/out/types/test/server-app/types.test.d.ts +1 -0
  30. package/out/types/test/server-app/wiki.test.d.ts +1 -0
  31. package/out/types/tsconfig.tsbuildinfo +1 -1
  32. package/out/webview/backlinks.css +1 -1
  33. package/out/webview/backlinks.js +4 -4
  34. package/out/webview/graph-view.css +1 -1
  35. package/out/webview/graph-view.js +6 -6
  36. package/out/webview/preview.css +1 -1
  37. package/out/webview/preview.js +189 -189
  38. package/package.json +1 -1
  39. package/out/types/src/wiki-app/wiki-app.d.ts +0 -17
  40. package/out/wiki-app/wiki-app.css +0 -1
  41. package/out/wiki-app/wiki-app.js +0 -18
package/out/cli/index.cjs CHANGED
@@ -23371,6 +23371,7 @@ var fs21 = __toESM(require("fs"));
23371
23371
  var http = __toESM(require("http"));
23372
23372
  var path25 = __toESM(require("path"));
23373
23373
  var import_url2 = require("url");
23374
+ var import_crypto_js2 = require("crypto-js");
23374
23375
 
23375
23376
  // src/markdown-engine/heading-id-generator.ts
23376
23377
  var import_uslug = __toESM(require("uslug"));
@@ -23825,7 +23826,13 @@ function getCrossnoteBuildDirectory() {
23825
23826
  }
23826
23827
  var _externalAddFileProtocolFunction = null;
23827
23828
  function useExternalAddFileProtocolFunction(func) {
23829
+ const previous = _externalAddFileProtocolFunction;
23828
23830
  _externalAddFileProtocolFunction = func;
23831
+ return () => {
23832
+ if (_externalAddFileProtocolFunction === func) {
23833
+ _externalAddFileProtocolFunction = previous;
23834
+ }
23835
+ };
23829
23836
  }
23830
23837
  function addFileProtocol(filePath, vscodePreviewPanel) {
23831
23838
  if (_externalAddFileProtocolFunction && vscodePreviewPanel) {
@@ -31847,6 +31854,58 @@ var Search = class {
31847
31854
  // src/notebook/graph-view.ts
31848
31855
  var import_object_hash = __toESM(require("object-hash"));
31849
31856
  var import_path2 = require("path");
31857
+ function constructGraphView(notebook) {
31858
+ const nodes = [];
31859
+ const links = [];
31860
+ const addedNodes = {};
31861
+ const addNode = (filePath) => {
31862
+ if (filePath in addedNodes) {
31863
+ return;
31864
+ }
31865
+ const note = notebook.notes[filePath];
31866
+ if (note) {
31867
+ nodes.push({
31868
+ id: filePath,
31869
+ label: note.title
31870
+ });
31871
+ } else {
31872
+ const lastIndex = filePath.lastIndexOf(".");
31873
+ let label = filePath;
31874
+ if (lastIndex > 0) {
31875
+ label = filePath.slice(0, lastIndex);
31876
+ }
31877
+ nodes.push({
31878
+ id: filePath,
31879
+ label: (0, import_path2.basename)(label)
31880
+ });
31881
+ }
31882
+ addedNodes[filePath] = true;
31883
+ };
31884
+ for (const filePath in notebook.referenceMap.map) {
31885
+ if (notebook.referenceMap.map.hasOwnProperty(filePath)) {
31886
+ addNode(filePath);
31887
+ for (const referredByFilePath in notebook.referenceMap.map[filePath]) {
31888
+ if (
31889
+ // eslint-disable-next-line no-prototype-builtins
31890
+ notebook.referenceMap.map[filePath].hasOwnProperty(
31891
+ referredByFilePath
31892
+ ) && referredByFilePath !== filePath
31893
+ ) {
31894
+ addNode(referredByFilePath);
31895
+ links.push({
31896
+ source: referredByFilePath,
31897
+ target: filePath
31898
+ });
31899
+ }
31900
+ }
31901
+ }
31902
+ }
31903
+ return {
31904
+ hash: (0, import_object_hash.default)({ nodes, links }),
31905
+ nodes,
31906
+ links
31907
+ };
31908
+ }
31850
31909
 
31851
31910
  // src/notebook/index.ts
31852
31911
  var defaultMarkdownItConfig = {
@@ -34883,11 +34942,11 @@ function isPathInsideDirectory(parentDirectoryPath, filePath) {
34883
34942
  return p;
34884
34943
  }
34885
34944
  };
34886
- const relative10 = path18.relative(
34945
+ const relative11 = path18.relative(
34887
34946
  realpath(parentDirectoryPath),
34888
34947
  realpath(filePath)
34889
34948
  );
34890
- return relative10 !== "" && !relative10.startsWith("..") && !path18.isAbsolute(relative10);
34949
+ return relative11 !== "" && !relative11.startsWith("..") && !path18.isAbsolute(relative11);
34891
34950
  }
34892
34951
  function isExistingFile(filePath) {
34893
34952
  try {
@@ -35379,9 +35438,10 @@ window["initRevealPresentation"] = async function() {
35379
35438
  config,
35380
35439
  vscodePreviewPanel = null,
35381
35440
  contentSecurityPolicy = "",
35382
- isVSCodeWebExtension: isVSCodeWebExtension2
35441
+ isVSCodeWebExtension: isVSCodeWebExtension2,
35442
+ parsedOutput
35383
35443
  }) {
35384
- if (!inputString) {
35444
+ if (!inputString && !parsedOutput) {
35385
35445
  inputString = await this.fs.readFile(this.filePath);
35386
35446
  }
35387
35447
  let webviewCss = "";
@@ -35404,15 +35464,12 @@ window["initRevealPresentation"] = async function() {
35404
35464
  if (!body) {
35405
35465
  body = ``;
35406
35466
  }
35407
- const { yamlConfig, JSAndCssFiles, html } = await this.parseMD(
35408
- inputString,
35409
- {
35410
- isForPreview: true,
35411
- useRelativeFilePath: false,
35412
- hideFrontMatter: false,
35413
- vscodePreviewPanel
35414
- }
35415
- );
35467
+ const { yamlConfig, JSAndCssFiles, html } = parsedOutput ?? await this.parseMD(inputString, {
35468
+ isForPreview: true,
35469
+ useRelativeFilePath: false,
35470
+ hideFrontMatter: false,
35471
+ vscodePreviewPanel
35472
+ });
35416
35473
  const isPresentationMode = yamlConfig["isPresentationMode"];
35417
35474
  const htmlTemplate = `<!DOCTYPE html>
35418
35475
  <html>
@@ -35467,7 +35524,7 @@ window["initRevealPresentation"] = async function() {
35467
35524
  )}
35468
35525
  ${head}
35469
35526
  </head>
35470
- <body class="preview-container ${isVSCodeWebExtension2 ? "vscode-web-extension" : ""}" data-html="${(0, import_html_escaper13.escape)(html)}" ${isPresentationMode ? "data-presentation-mode" : ""}>
35527
+ <body class="preview-container ${isVSCodeWebExtension2 ? "vscode-web-extension" : ""} ${config.isWiki ? "wiki-readonly" : ""}" data-html="${(0, import_html_escaper13.escape)(html)}" ${isPresentationMode ? "data-presentation-mode" : ""}>
35471
35528
  ${body}
35472
35529
  </body>
35473
35530
  ${this.generateScriptsForPreview(
@@ -36717,11 +36774,11 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36717
36774
  * @param filePath
36718
36775
  * @param relative: whether to use the path relative to filePath or not.
36719
36776
  */
36720
- resolveFilePath(filePath = "", relative10, fileDirectoryPath = "") {
36777
+ resolveFilePath(filePath = "", relative11, fileDirectoryPath = "") {
36721
36778
  if (filePath.match(this.protocolsWhiteListRegExp) || filePath.startsWith("data:image/") || filePath.startsWith("tag://") || filePath[0] === "#") {
36722
36779
  return filePath;
36723
36780
  } else if (filePath[0] === "/") {
36724
- if (relative10) {
36781
+ if (relative11) {
36725
36782
  return path18.relative(
36726
36783
  fileDirectoryPath || this.fileDirectoryPath,
36727
36784
  path18.resolve(this.projectDirectoryPath.fsPath, "." + filePath)
@@ -36733,7 +36790,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
36733
36790
  );
36734
36791
  }
36735
36792
  } else {
36736
- if (relative10) {
36793
+ if (relative11) {
36737
36794
  return filePath;
36738
36795
  } else {
36739
36796
  return addFileProtocol(
@@ -37356,6 +37413,64 @@ var cheerio4 = __toESM(require("cheerio"));
37356
37413
  var fs18 = __toESM(require("fs"));
37357
37414
  var path22 = __toESM(require("path"));
37358
37415
 
37416
+ // src/serve/preview-host-shim.ts
37417
+ function previewHostShimScript(targetOriginExpression) {
37418
+ return `<script>
37419
+ (function () {
37420
+ if (window.acquireVsCodeApi) { return; }
37421
+ var api = null;
37422
+ window.acquireVsCodeApi = function () {
37423
+ if (api) { return api; }
37424
+ api = {
37425
+ postMessage: function (message) {
37426
+ window.parent.postMessage(message, ${targetOriginExpression});
37427
+ },
37428
+ getState: function () {
37429
+ try {
37430
+ return JSON.parse(localStorage.getItem('crossnote-preview-state') || 'null');
37431
+ } catch (error) { return null; }
37432
+ },
37433
+ setState: function (state) {
37434
+ try {
37435
+ localStorage.setItem('crossnote-preview-state', JSON.stringify(state));
37436
+ } catch (error) { /* storage unavailable */ }
37437
+ },
37438
+ };
37439
+ return api;
37440
+ };
37441
+ // The shell tells the frames when zen mode is on: Esc must then exit zen
37442
+ // (the welcome card and the exit button both promise that), instead of the
37443
+ // preview's own Esc behavior of toggling the sidebar TOC.
37444
+ var zenMode = false;
37445
+ window.addEventListener('message', function (event) {
37446
+ if (event.data && event.data.command === '__serverAppZenMode') {
37447
+ zenMode = !!event.data.enabled;
37448
+ }
37449
+ });
37450
+ document.addEventListener('keydown', function (event) {
37451
+ var key = event.key.toLowerCase();
37452
+ var action = null;
37453
+ if ((event.metaKey || event.ctrlKey) && !event.altKey && key === 'p') {
37454
+ action = 'open-file-picker';
37455
+ } else if ((event.metaKey || event.ctrlKey) && !event.altKey && key === '\\\\') {
37456
+ action = 'split-pane';
37457
+ } else if (event.altKey && key === 'w') {
37458
+ action = 'close-tab';
37459
+ } else if (key === 'escape' && zenMode) {
37460
+ action = 'exit-zen-mode';
37461
+ }
37462
+ if (action) {
37463
+ event.preventDefault();
37464
+ window.parent.postMessage(
37465
+ { command: '__serverAppShortcut', args: [action] },
37466
+ ${targetOriginExpression}
37467
+ );
37468
+ }
37469
+ }, true);
37470
+ })();
37471
+ </script>`;
37472
+ }
37473
+
37359
37474
  // src/serve/config.ts
37360
37475
  var fs16 = __toESM(require("fs"));
37361
37476
  var os3 = __toESM(require("os"));
@@ -37615,7 +37730,16 @@ function encodePathSegments(relativePath) {
37615
37730
  return relativePath.split("/").map((segment) => encodeURIComponent(segment)).join("/");
37616
37731
  }
37617
37732
  function isPathWithinRoot(root, candidate) {
37618
- return candidate === root || candidate.startsWith(root + path21.sep);
37733
+ return isPathWithinRootOn(process.platform, root, candidate);
37734
+ }
37735
+ function isPathWithinRootOn(platform, root, candidate) {
37736
+ if (platform === "win32") {
37737
+ const separator = "\\";
37738
+ const lowercaseRoot = root.toLowerCase();
37739
+ const lowercaseCandidate = candidate.toLowerCase();
37740
+ return lowercaseCandidate === lowercaseRoot || lowercaseCandidate.startsWith(lowercaseRoot + separator);
37741
+ }
37742
+ return candidate === root || candidate.startsWith(root + "/");
37619
37743
  }
37620
37744
  async function listMarkdownFiles(rootDirectory, limit = 5e3) {
37621
37745
  const gitignorePath = path21.join(rootDirectory, ".gitignore");
@@ -37666,35 +37790,28 @@ async function listMarkdownFiles(rootDirectory, limit = 5e3) {
37666
37790
  }
37667
37791
 
37668
37792
  // src/wiki/index.ts
37669
- var WIKI_RELAY_SCRIPT = `(function () {
37670
- document.addEventListener('click', function (event) {
37671
- var node = event.target;
37672
- var anchor = node && node.closest ? node.closest('a') : null;
37673
- if (!anchor) {
37674
- if (node && node.classList && node.classList.contains('task-list-item-checkbox')) {
37675
- event.preventDefault();
37676
- }
37677
- return;
37678
- }
37679
- var href = anchor.getAttribute('href');
37680
- if (!href || href.charAt(0) === '#') {
37681
- return;
37682
- }
37683
- if (anchor.target === '_blank') {
37684
- return;
37685
- }
37686
- event.preventDefault();
37687
- if (/^https?:/i.test(href)) {
37688
- window.open(anchor.href, '_blank', 'noopener');
37689
- return;
37690
- }
37691
- if (/^(mailto:|tel:)/i.test(href)) {
37692
- window.location.href = href;
37693
- return;
37694
- }
37695
- parent.postMessage({ command: 'wiki-navigate', href: href }, '*');
37696
- }, true);
37697
- })();`;
37793
+ var ASSET_TOKEN_PREFIX = "crossnote-wiki-asset:";
37794
+ var THEME_TOKEN_PREFIX = "crossnote-wiki-theme:";
37795
+ var WIKI_PREVIEW_HOST_SHIM = previewHostShimScript("'*'");
37796
+ var IMAGE_MIME_TYPES = {
37797
+ avif: "image/avif",
37798
+ bmp: "image/bmp",
37799
+ gif: "image/gif",
37800
+ ico: "image/x-icon",
37801
+ jpeg: "image/jpeg",
37802
+ jpg: "image/jpeg",
37803
+ png: "image/png",
37804
+ svg: "image/svg+xml",
37805
+ webp: "image/webp"
37806
+ };
37807
+ var SCRIPT_STYLE_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs", ".css"]);
37808
+ function isImagePath(filePath) {
37809
+ const extension = path22.extname(filePath).toLowerCase().slice(1);
37810
+ return extension in IMAGE_MIME_TYPES;
37811
+ }
37812
+ function toPosixPath(filePath) {
37813
+ return filePath.split(path22.sep).join("/");
37814
+ }
37698
37815
  async function buildWiki(options) {
37699
37816
  const buildDirectory = path22.resolve(
37700
37817
  options.crossnoteBuildDirectory ?? getCrossnoteBuildDirectory()
@@ -37708,73 +37825,425 @@ async function buildWiki(options) {
37708
37825
  globalConfigDirectory: options.globalConfigDirectory
37709
37826
  }
37710
37827
  );
37711
- const files = [];
37712
- const failures = [];
37713
- for (let rootIndex = 0; rootIndex < rootDirectories.length; rootIndex++) {
37714
- const root = rootDirectories[rootIndex];
37715
- const notebook = notebooks[rootIndex];
37716
- const markdownFiles = await listMarkdownFiles(root);
37717
- let processedInRoot = 0;
37718
- for (const file of markdownFiles) {
37828
+ const multiRoot = rootDirectories.length > 1;
37829
+ const rootNames = rootDirectories.map((root) => path22.basename(root) || root);
37830
+ const noteKeyFor = (absolutePath, rootIndex) => {
37831
+ const relative11 = toPosixPath(
37832
+ path22.relative(rootDirectories[rootIndex], absolutePath)
37833
+ );
37834
+ return multiRoot ? `${rootNames[rootIndex]}/${relative11}` : relative11;
37835
+ };
37836
+ const assetIds = /* @__PURE__ */ new Map();
37837
+ let assetCounter = 0;
37838
+ const tokenFor = (filePath) => {
37839
+ const resolved = path22.resolve(filePath);
37840
+ let id = assetIds.get(resolved);
37841
+ if (id === void 0) {
37842
+ id = String(assetCounter++);
37843
+ assetIds.set(resolved, id);
37844
+ }
37845
+ return `${ASSET_TOKEN_PREFIX}${id}`;
37846
+ };
37847
+ const dataUriForImage = (filePath) => {
37848
+ const extension = path22.extname(filePath).toLowerCase().slice(1);
37849
+ const mime = IMAGE_MIME_TYPES[extension];
37850
+ if (!mime) {
37851
+ return null;
37852
+ }
37853
+ const cleanPath = resolvedPath(filePath);
37854
+ const candidates = [cleanPath];
37855
+ try {
37856
+ const decoded = decodeURIComponent(cleanPath);
37857
+ if (decoded !== cleanPath) {
37858
+ candidates.push(decoded);
37859
+ }
37860
+ } catch {
37861
+ }
37862
+ for (const candidate of candidates) {
37719
37863
  try {
37720
- const engine = notebook.getNoteMarkdownEngine(file.absolutePath);
37721
- let html2 = await engine.htmlExportDocument({
37722
- offline: false,
37723
- // A wiki is meant to be shared, so local images/SVGs travel with
37724
- // it as data URIs (front matter can still turn this off).
37725
- embedLocalImages: true,
37726
- embedSVG: true
37727
- });
37728
- let title = path22.basename(
37729
- file.absolutePath,
37730
- path22.extname(file.absolutePath)
37864
+ const base64 = fs18.readFileSync(candidate).toString("base64");
37865
+ return `data:${mime};base64,${base64}`;
37866
+ } catch {
37867
+ }
37868
+ }
37869
+ return null;
37870
+ };
37871
+ function resolvedPath(filePath) {
37872
+ return filePath.replace(/\?.+$/, "");
37873
+ }
37874
+ const dummyPanel = {};
37875
+ const restoreMapper = useExternalAddFileProtocolFunction(
37876
+ (filePath) => {
37877
+ const cleanPath = resolvedPath(filePath);
37878
+ if (isPathWithinRoot(buildDirectory, cleanPath)) {
37879
+ const relativeToBuild = toPosixPath(
37880
+ path22.relative(buildDirectory, cleanPath)
37731
37881
  );
37732
- const $ = cheerio4.load(html2);
37733
- $("head").prepend(`<script>${WIKI_RELAY_SCRIPT}</script>`);
37734
- const titleElement = $("title").first().text().trim();
37735
- if (titleElement) {
37736
- title = titleElement;
37737
- }
37738
- html2 = $.html();
37739
- files.push({ path: file.absolutePath, root, title, html: html2 });
37740
- } catch (error) {
37741
- failures.push({
37742
- path: file.absolutePath,
37743
- error: String(error)
37882
+ if (relativeToBuild.startsWith("styles/preview_theme/")) {
37883
+ return `${THEME_TOKEN_PREFIX}preview`;
37884
+ }
37885
+ if (relativeToBuild.startsWith("styles/prism_theme/")) {
37886
+ return `${THEME_TOKEN_PREFIX}codeBlock`;
37887
+ }
37888
+ if (relativeToBuild.startsWith("dependencies/reveal/css/theme/")) {
37889
+ return `${THEME_TOKEN_PREFIX}reveal`;
37890
+ }
37891
+ return tokenFor(cleanPath);
37892
+ }
37893
+ for (const root of rootDirectories) {
37894
+ if (!isPathWithinRoot(root, cleanPath)) {
37895
+ continue;
37896
+ }
37897
+ if (isImagePath(cleanPath)) {
37898
+ const dataUri = dataUriForImage(cleanPath);
37899
+ if (dataUri) {
37900
+ return dataUri;
37901
+ }
37902
+ return addFileProtocol(cleanPath);
37903
+ }
37904
+ if (SCRIPT_STYLE_EXTENSIONS.has(path22.extname(cleanPath).toLowerCase())) {
37905
+ return tokenFor(cleanPath);
37906
+ }
37907
+ const relative11 = path22.relative(root, cleanPath);
37908
+ return `/${toPosixPath(relative11)}`;
37909
+ }
37910
+ return addFileProtocol(cleanPath);
37911
+ }
37912
+ );
37913
+ const files = [];
37914
+ const failures = [];
37915
+ const remoteImageCache = /* @__PURE__ */ new Map();
37916
+ try {
37917
+ for (let rootIndex = 0; rootIndex < rootDirectories.length; rootIndex++) {
37918
+ const root = rootDirectories[rootIndex];
37919
+ const notebook = notebooks[rootIndex];
37920
+ const markdownFiles = await listMarkdownFiles(root);
37921
+ let processedInRoot = 0;
37922
+ for (const file of markdownFiles) {
37923
+ try {
37924
+ const text = await fs18.promises.readFile(file.absolutePath, "utf-8");
37925
+ const engine = notebook.getNoteMarkdownEngine(file.absolutePath);
37926
+ const output = await engine.parseMD(text, {
37927
+ isForPreview: true,
37928
+ useRelativeFilePath: false,
37929
+ hideFrontMatter: false,
37930
+ vscodePreviewPanel: dummyPanel
37931
+ });
37932
+ output.html = await embedRemoteImages(output.html, remoteImageCache);
37933
+ const noteKey = noteKeyFor(file.absolutePath, rootIndex);
37934
+ const html2 = await engine.generateHTMLTemplateForPreview({
37935
+ inputString: text,
37936
+ parsedOutput: output,
37937
+ vscodePreviewPanel: dummyPanel,
37938
+ config: {
37939
+ sourceUri: noteKey,
37940
+ isVSCode: false,
37941
+ isServerApp: true,
37942
+ isWiki: true
37943
+ },
37944
+ scripts: WIKI_PREVIEW_HOST_SHIM,
37945
+ // No <base>: same-document `#anchor` links must keep resolving to
37946
+ // the note document itself.
37947
+ head: ""
37948
+ });
37949
+ const yamlConfig = output.yamlConfig;
37950
+ const title = typeof yamlConfig["title"] === "string" && yamlConfig["title"].trim() || path22.basename(file.absolutePath, path22.extname(file.absolutePath));
37951
+ const mtimeMs = (await fs18.promises.stat(file.absolutePath)).mtimeMs;
37952
+ files.push({
37953
+ path: noteKey,
37954
+ root: rootNames[rootIndex],
37955
+ title,
37956
+ mtimeMs,
37957
+ html: html2,
37958
+ update: {
37959
+ markdown: text,
37960
+ html: output.html,
37961
+ tocHTML: output.tocHTML,
37962
+ totalLineCount: text.split("\n").length,
37963
+ sourceUri: noteKey,
37964
+ sourceScheme: "file",
37965
+ id: yamlConfig["id"] || "",
37966
+ class: yamlConfig["class"] || "",
37967
+ jsAndCssFiles: output.JSAndCssFiles
37968
+ }
37969
+ });
37970
+ } catch (error) {
37971
+ failures.push({
37972
+ path: file.absolutePath,
37973
+ error: String(error)
37974
+ });
37975
+ }
37976
+ processedInRoot += 1;
37977
+ options.onProgress?.({
37978
+ rendered: processedInRoot,
37979
+ total: markdownFiles.length,
37980
+ root
37744
37981
  });
37745
37982
  }
37746
- processedInRoot += 1;
37747
- options.onProgress?.({
37748
- rendered: processedInRoot,
37749
- total: markdownFiles.length,
37750
- root
37751
- });
37752
37983
  }
37984
+ } finally {
37985
+ restoreMapper();
37753
37986
  }
37754
37987
  if (files.length === 0) {
37755
37988
  throw new Error(
37756
37989
  "no markdown notes found to build a wiki from" + (failures.length > 0 ? ` (${failures.length} notes failed to render)` : "")
37757
37990
  );
37758
37991
  }
37992
+ const assets = {};
37993
+ for (const [filePath, id] of assetIds) {
37994
+ assets[id] = path22.extname(filePath).toLowerCase() === ".css" ? await readStylesheetWithInlinedUrls(filePath) : await fs18.promises.readFile(filePath, "utf-8").catch(() => "");
37995
+ }
37996
+ assets["graph-view.js"] = await fs18.promises.readFile(path22.join(buildDirectory, "webview", "graph-view.js"), "utf-8").catch(() => "");
37997
+ assets["graph-view.css"] = await readStylesheetWithInlinedUrls(
37998
+ path22.join(buildDirectory, "webview", "graph-view.css")
37999
+ ).catch(() => "");
38000
+ const themes = await collectThemeAssets(buildDirectory, notebooks[0]);
38001
+ const graph = {};
38002
+ const backlinks = {};
38003
+ for (let rootIndex = 0; rootIndex < rootDirectories.length; rootIndex++) {
38004
+ const notebook = notebooks[rootIndex];
38005
+ try {
38006
+ await notebook.refreshNotesIfNotLoaded({
38007
+ dir: ".",
38008
+ includeSubdirectories: true
38009
+ });
38010
+ graph[rootNames[rootIndex]] = constructGraphView(
38011
+ notebook
38012
+ );
38013
+ } catch (error) {
38014
+ console.error(
38015
+ `crossnote build-wiki: failed to build graph data for ${rootDirectories[rootIndex]}:`,
38016
+ error
38017
+ );
38018
+ }
38019
+ for (const file of files) {
38020
+ if (file.root !== rootNames[rootIndex]) {
38021
+ continue;
38022
+ }
38023
+ try {
38024
+ backlinks[file.path] = (await notebook.getNoteBacklinks(
38025
+ path22.join(rootDirectories[rootIndex], ...file.path.split("/"))
38026
+ ) ?? []).map(
38027
+ (backlink) => scrubBacklinkForWiki(backlink, rootDirectories[rootIndex])
38028
+ );
38029
+ } catch {
38030
+ backlinks[file.path] = [];
38031
+ }
38032
+ }
38033
+ }
37759
38034
  const html = buildShellHTML({
37760
- rootDirectories,
38035
+ rootNames,
37761
38036
  files,
38037
+ assets,
38038
+ themes,
38039
+ graph,
38040
+ backlinks,
37762
38041
  buildDirectory
37763
38042
  });
37764
38043
  return {
37765
38044
  html,
37766
- files: files.map(({ path: path27, root, title }) => ({ path: path27, root, title })),
38045
+ files: files.map(({ path: path27, root, title, mtimeMs }) => ({
38046
+ path: path27,
38047
+ root,
38048
+ title,
38049
+ mtimeMs
38050
+ })),
37767
38051
  rootDirectories,
37768
38052
  failures
37769
38053
  };
37770
38054
  }
38055
+ function scrubBacklinkForWiki(backlink, rootDirectory) {
38056
+ return {
38057
+ note: {
38058
+ notebookPath: { scheme: "file", path: "/" },
38059
+ filePath: (backlink.note?.filePath ?? "").replace(/\\/g, "/"),
38060
+ title: backlink.note?.title ?? "",
38061
+ config: backlink.note?.config
38062
+ },
38063
+ references: (backlink.references ?? []).map((reference) => ({
38064
+ ...reference,
38065
+ html: typeof reference["html"] === "string" ? scrubWikiHtmlLinks(reference["html"], rootDirectory) : reference["html"]
38066
+ })),
38067
+ referenceHtmls: (backlink.referenceHtmls ?? []).map(
38068
+ (html) => scrubWikiHtmlLinks(html, rootDirectory)
38069
+ )
38070
+ };
38071
+ }
38072
+ function scrubWikiHtmlLinks(html, rootDirectory) {
38073
+ try {
38074
+ const $ = cheerio4.load(html);
38075
+ $("a[href], img[src]").each((_, element) => {
38076
+ for (const attribute of ["href", "src"]) {
38077
+ const value = $(element).attr(attribute);
38078
+ if (!value) {
38079
+ continue;
38080
+ }
38081
+ let decoded = value;
38082
+ try {
38083
+ decoded = decodeURIComponent(value);
38084
+ } catch {
38085
+ }
38086
+ const fileUrlMatch = decoded.match(/^file:\/\/\/+(.*)$/i);
38087
+ if (fileUrlMatch) {
38088
+ decoded = fileUrlMatch[1];
38089
+ if (!/^[A-Za-z]:/.test(decoded)) {
38090
+ decoded = "/" + decoded;
38091
+ }
38092
+ }
38093
+ const normalized = decoded.replace(/\//g, path22.sep);
38094
+ if (!isPathWithinRoot(rootDirectory, normalized)) {
38095
+ continue;
38096
+ }
38097
+ const relative11 = path22.relative(rootDirectory, normalized).split(path22.sep).join("/");
38098
+ $(element).attr(attribute, `file:///${relative11}`);
38099
+ }
38100
+ });
38101
+ return $.html();
38102
+ } catch {
38103
+ return html;
38104
+ }
38105
+ }
38106
+ async function collectThemeAssets(buildDirectory, notebook) {
38107
+ const readThemeDirectory = async (relativeDirectory) => {
38108
+ const absoluteDirectory = path22.join(
38109
+ buildDirectory,
38110
+ ...relativeDirectory.split("/")
38111
+ );
38112
+ const entries = await fs18.promises.readdir(absoluteDirectory).catch(() => []);
38113
+ const map = {};
38114
+ for (const entry of entries) {
38115
+ if (!entry.toLowerCase().endsWith(".css")) {
38116
+ continue;
38117
+ }
38118
+ map[entry] = await readStylesheetWithInlinedUrls(
38119
+ path22.join(absoluteDirectory, entry)
38120
+ );
38121
+ }
38122
+ return map;
38123
+ };
38124
+ return {
38125
+ preview: await readThemeDirectory("styles/preview_theme"),
38126
+ codeBlock: await readThemeDirectory("styles/prism_theme"),
38127
+ reveal: await readThemeDirectory("dependencies/reveal/css/theme"),
38128
+ codeBlockAuto: { ...MarkdownEngine.AutoPrismThemeMap },
38129
+ build: {
38130
+ preview: notebook.config.previewTheme,
38131
+ codeBlock: notebook.config.codeBlockTheme,
38132
+ reveal: notebook.config.revealjsTheme
38133
+ }
38134
+ };
38135
+ }
38136
+ var REMOTE_IMAGE_TIMEOUT_MS = 1e4;
38137
+ var REMOTE_IMAGE_MAX_BYTES = 8 * 1024 * 1024;
38138
+ async function embedRemoteImages(html, cache) {
38139
+ const urls = /* @__PURE__ */ new Set();
38140
+ for (const match of html.matchAll(/<img[^>]*\ssrc="(https?:[^"]+)"/g)) {
38141
+ urls.add(match[1]);
38142
+ }
38143
+ if (urls.size === 0) {
38144
+ return html;
38145
+ }
38146
+ const replacements = /* @__PURE__ */ new Map();
38147
+ await Promise.all(
38148
+ Array.from(urls).map(async (url) => {
38149
+ let cached = cache.get(url);
38150
+ if (cached === void 0) {
38151
+ cached = await fetchRemoteImage(url);
38152
+ cache.set(url, cached);
38153
+ }
38154
+ if (cached) {
38155
+ replacements.set(url, cached);
38156
+ }
38157
+ })
38158
+ );
38159
+ if (replacements.size === 0) {
38160
+ return html;
38161
+ }
38162
+ return html.replace(
38163
+ /(<img[^>]*\ssrc=")(https?:[^"]+)(")/g,
38164
+ (match, prefix, url, suffix) => replacements.has(url) ? `${prefix}${replacements.get(url)}${suffix}` : match
38165
+ );
38166
+ }
38167
+ async function fetchRemoteImage(url) {
38168
+ try {
38169
+ const response = await fetch(url, {
38170
+ signal: AbortSignal.timeout(REMOTE_IMAGE_TIMEOUT_MS),
38171
+ redirect: "follow"
38172
+ });
38173
+ if (!response.ok) {
38174
+ return null;
38175
+ }
38176
+ const declaredLength = parseInt(
38177
+ response.headers.get("content-length") ?? "",
38178
+ 10
38179
+ );
38180
+ if (Number.isInteger(declaredLength) && declaredLength > REMOTE_IMAGE_MAX_BYTES) {
38181
+ return null;
38182
+ }
38183
+ const buffer = Buffer.from(await response.arrayBuffer());
38184
+ if (buffer.length === 0 || buffer.length > REMOTE_IMAGE_MAX_BYTES) {
38185
+ return null;
38186
+ }
38187
+ const mime = (response.headers.get("content-type") ?? "").split(";")[0];
38188
+ if (!mime.startsWith("image/")) {
38189
+ return null;
38190
+ }
38191
+ return `data:${mime};base64,${buffer.toString("base64")}`;
38192
+ } catch {
38193
+ return null;
38194
+ }
38195
+ }
38196
+ async function readStylesheetWithInlinedUrls(cssPath) {
38197
+ let css;
38198
+ try {
38199
+ css = await fs18.promises.readFile(cssPath, "utf-8");
38200
+ } catch {
38201
+ return "";
38202
+ }
38203
+ const directory = path22.dirname(cssPath);
38204
+ const cache = /* @__PURE__ */ new Map();
38205
+ return css.replace(
38206
+ /url\(\s*(['"]?)([^'")]+)\1\s*\)/g,
38207
+ (match, _quote, ref) => {
38208
+ if (ref.startsWith("data:") || ref.startsWith("#") || /^[a-z][a-z0-9+.-]*:/i.test(ref) || ref.startsWith("//")) {
38209
+ return match;
38210
+ }
38211
+ let dataUri = cache.get(ref);
38212
+ if (dataUri === void 0) {
38213
+ dataUri = "";
38214
+ try {
38215
+ const assetPath = path22.resolve(directory, decodeURIComponent(ref));
38216
+ const extension = path22.extname(assetPath).toLowerCase().slice(1);
38217
+ const mime = IMAGE_MIME_TYPES[extension] ?? (extension === "woff2" ? "font/woff2" : extension === "woff" ? "font/woff" : extension === "ttf" ? "font/ttf" : extension === "otf" ? "font/otf" : extension === "eot" ? "application/vnd.ms-fontobject" : "application/octet-stream");
38218
+ const base64 = fs18.readFileSync(assetPath).toString("base64");
38219
+ dataUri = `data:${mime};base64,${base64}`;
38220
+ } catch {
38221
+ }
38222
+ cache.set(ref, dataUri);
38223
+ }
38224
+ return dataUri ? `url("${dataUri}")` : match;
38225
+ }
38226
+ );
38227
+ }
37771
38228
  function buildShellHTML({
37772
- rootDirectories,
38229
+ rootNames,
37773
38230
  files,
38231
+ assets,
38232
+ themes,
38233
+ graph,
38234
+ backlinks,
37774
38235
  buildDirectory
37775
38236
  }) {
37776
- const appScriptPath = path22.join(buildDirectory, "wiki-app", "wiki-app.js");
37777
- const appStylePath = path22.join(buildDirectory, "wiki-app", "wiki-app.css");
38237
+ const appScriptPath = path22.join(
38238
+ buildDirectory,
38239
+ "server-app",
38240
+ "server-app.js"
38241
+ );
38242
+ const appStylePath = path22.join(
38243
+ buildDirectory,
38244
+ "server-app",
38245
+ "server-app.css"
38246
+ );
37778
38247
  let appScript;
37779
38248
  let appStyle;
37780
38249
  try {
@@ -37782,17 +38251,21 @@ function buildShellHTML({
37782
38251
  appStyle = fs18.readFileSync(appStylePath, "utf-8");
37783
38252
  } catch (error) {
37784
38253
  throw new Error(
37785
- `the wiki app bundle is missing (looked at ${appScriptPath}); rebuild crossnote so out/wiki-app/ exists`,
38254
+ `the server app bundle is missing (looked at ${appScriptPath}); rebuild crossnote so out/server-app/ exists`,
37786
38255
  { cause: error }
37787
38256
  );
37788
38257
  }
37789
38258
  const payload = JSON.stringify({
37790
- rootDirectories,
38259
+ rootDirectories: rootNames,
38260
+ assets,
38261
+ themes,
38262
+ graph,
38263
+ backlinks,
37791
38264
  files
37792
38265
  }).replace(/</g, "\\u003c");
37793
38266
  const safeAppScript = appScript.replace(/<\/script/g, "<\\/script");
37794
38267
  const safeAppStyle = appStyle.replace(/<\/style/g, "<\\/style");
37795
- const title = `wiki \u2014 ${path22.basename(rootDirectories[0] ?? "")}`;
38268
+ const title = `wiki \u2014 ${rootNames[0] ?? ""}`;
37796
38269
  return `<!DOCTYPE html>
37797
38270
  <html>
37798
38271
  <head>
@@ -37822,6 +38295,89 @@ var utility = {
37822
38295
  uploadImage
37823
38296
  };
37824
38297
 
38298
+ // src/serve/graph-host-shim.ts
38299
+ function graphHostShimScript(options) {
38300
+ const isFetch = options.source === "fetch";
38301
+ const fileExpression = isFetch ? options.fileExpression ?? "''" : options.embeddedFileExpression ?? "''";
38302
+ const dataUrl = options.dataUrl ?? "/api/graph";
38303
+ const targetOrigin = isFetch ? "window.location.origin" : "'*'";
38304
+ const loadData = isFetch ? `fetch(${JSON.stringify(dataUrl)} + '?file=' + encodeURIComponent(FILE))
38305
+ .then(function (response) {
38306
+ if (!response.ok) { throw new Error('graph request failed'); }
38307
+ return response.json();
38308
+ })` : `Promise.resolve(globalThis.__CROSSNOTE_WIKI_GRAPH__ || null)`;
38309
+ return `<script>
38310
+ (function () {
38311
+ if (globalThis.acquireVsCodeApi) { return; }
38312
+ var api = null;
38313
+ var FILE = ${fileExpression};
38314
+ globalThis.acquireVsCodeApi = function () {
38315
+ if (api) { return api; }
38316
+ api = {
38317
+ postMessage: function (message) {
38318
+ if (!message || typeof message.command !== 'string') { return; }
38319
+ if (message.command === 'graphViewReady') {
38320
+ ${loadData}
38321
+ .then(function (payload) {
38322
+ if (!payload) { throw new Error('no graph data'); }
38323
+ globalThis.postMessage({
38324
+ command: 'graphData',
38325
+ data: payload.data,
38326
+ activeFilePath: payload.activeFilePath,
38327
+ }, '*');
38328
+ })
38329
+ .catch(function () {
38330
+ globalThis.postMessage({
38331
+ command: 'graphData',
38332
+ data: { hash: '', nodes: [], links: [] },
38333
+ activeFilePath: '',
38334
+ }, '*');
38335
+ });
38336
+ return;
38337
+ }
38338
+ if (message.command === 'openFile') {
38339
+ var rel = message.args && message.args[0];
38340
+ if (typeof rel === 'string') {
38341
+ globalThis.parent.postMessage(
38342
+ {
38343
+ command: '__serverAppOpenFile',
38344
+ args: [FILE, String(rel).replace(/\\\\/g, '/')],
38345
+ },
38346
+ ${targetOrigin}
38347
+ );
38348
+ }
38349
+ return;
38350
+ }
38351
+ if (message.command === 'saveSetting') {
38352
+ var setting = message.args && message.args[0];
38353
+ if (setting && typeof setting.key === 'string') {
38354
+ try {
38355
+ localStorage.setItem(
38356
+ 'crossnote.graphView.' + setting.key,
38357
+ JSON.stringify(setting.value === undefined ? null : setting.value)
38358
+ );
38359
+ } catch (error) { /* storage unavailable */ }
38360
+ }
38361
+ return;
38362
+ }
38363
+ },
38364
+ getState: function () {
38365
+ try {
38366
+ return JSON.parse(localStorage.getItem('crossnote.graphView.state') || 'null');
38367
+ } catch (error) { return null; }
38368
+ },
38369
+ setState: function (state) {
38370
+ try {
38371
+ localStorage.setItem('crossnote.graphView.state', JSON.stringify(state));
38372
+ } catch (error) { /* storage unavailable */ }
38373
+ },
38374
+ };
38375
+ return api;
38376
+ };
38377
+ })();
38378
+ </script>`;
38379
+ }
38380
+
37825
38381
  // src/serve/sse.ts
37826
38382
  var SSEHub = class {
37827
38383
  constructor() {
@@ -38104,49 +38660,11 @@ async function nonConflictingWikiPath(rootDirectory) {
38104
38660
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").replace(/\..+$/, "").replace("T", "-");
38105
38661
  return path25.join(rootDirectory, `crossnote-wiki-${stamp}.html`);
38106
38662
  }
38107
- var PREVIEW_HOST_SHIM = `<script>
38108
- (function () {
38109
- if (window.acquireVsCodeApi) { return; }
38110
- var api = null;
38111
- window.acquireVsCodeApi = function () {
38112
- if (api) { return api; }
38113
- api = {
38114
- postMessage: function (message) {
38115
- window.parent.postMessage(message, window.location.origin);
38116
- },
38117
- getState: function () {
38118
- try {
38119
- return JSON.parse(localStorage.getItem('crossnote-preview-state') || 'null');
38120
- } catch (error) { return null; }
38121
- },
38122
- setState: function (state) {
38123
- try {
38124
- localStorage.setItem('crossnote-preview-state', JSON.stringify(state));
38125
- } catch (error) { /* storage unavailable */ }
38126
- },
38127
- };
38128
- return api;
38129
- };
38130
- document.addEventListener('keydown', function (event) {
38131
- var key = event.key.toLowerCase();
38132
- var action = null;
38133
- if ((event.metaKey || event.ctrlKey) && !event.altKey && key === 'p') {
38134
- action = 'open-file-picker';
38135
- } else if ((event.metaKey || event.ctrlKey) && !event.altKey && key === '\\\\') {
38136
- action = 'split-pane';
38137
- } else if (event.altKey && key === 'w') {
38138
- action = 'close-tab';
38139
- }
38140
- if (action) {
38141
- event.preventDefault();
38142
- window.parent.postMessage(
38143
- { command: '__serverAppShortcut', args: [action] },
38144
- window.location.origin
38145
- );
38146
- }
38147
- }, true);
38148
- })();
38149
- </script>`;
38663
+ var PREVIEW_HOST_SHIM = previewHostShimScript("window.location.origin");
38664
+ var GRAPH_HOST_SHIM = graphHostShimScript({
38665
+ source: "fetch",
38666
+ fileExpression: "new URLSearchParams(window.location.search).get('file') || ''"
38667
+ });
38150
38668
  function appShellHTML(serverInfo) {
38151
38669
  const serialized = JSON.stringify(serverInfo).replace(/</g, "\\u003c");
38152
38670
  return `<!DOCTYPE html>
@@ -38419,6 +38937,49 @@ async function startServeServer(options) {
38419
38937
  await renderFile(sourceUri, { triggeredBySave: true });
38420
38938
  return;
38421
38939
  }
38940
+ case "showBacklinks": {
38941
+ const info = args[0];
38942
+ const file = assertFileWithinRoots(String(info?.uri ?? ""));
38943
+ if (!file || !isMarkdownFile(file)) {
38944
+ return;
38945
+ }
38946
+ const fileNotebook = notebookForFile(file);
38947
+ if (!fileNotebook) {
38948
+ return;
38949
+ }
38950
+ try {
38951
+ if (info?.forceRefreshingNotes) {
38952
+ await fileNotebook.refreshNotesIncremental({
38953
+ dir: ".",
38954
+ includeSubdirectories: true
38955
+ });
38956
+ } else {
38957
+ await fileNotebook.refreshNotesIfNotLoaded({
38958
+ dir: ".",
38959
+ includeSubdirectories: true
38960
+ });
38961
+ }
38962
+ const backlinks = await fileNotebook.getNoteBacklinks(file);
38963
+ const sha = (0, import_crypto_js2.SHA256)(JSON.stringify(backlinks)).toString();
38964
+ const hasUpdate = sha !== info?.backlinksSha;
38965
+ sse.broadcast({
38966
+ type: "iframeMessage",
38967
+ file,
38968
+ iframeMessage: {
38969
+ command: "backlinks",
38970
+ sourceUri: file,
38971
+ backlinks: hasUpdate ? backlinks : null,
38972
+ hasUpdate
38973
+ }
38974
+ });
38975
+ } catch (error) {
38976
+ console.error(
38977
+ `crossnote serve: failed to compute backlinks for ${file}:`,
38978
+ error
38979
+ );
38980
+ }
38981
+ return;
38982
+ }
38422
38983
  case "exportStandaloneWiki": {
38423
38984
  try {
38424
38985
  const result = await buildWiki({
@@ -38543,6 +39104,63 @@ async function startServeServer(options) {
38543
39104
  }
38544
39105
  return;
38545
39106
  }
39107
+ if (request.method === "GET" && urlPath === "/graph-view") {
39108
+ const file = assertFileWithinRoots(
39109
+ requestUrl.searchParams.get("file") ?? "/"
39110
+ );
39111
+ if (!file || !isMarkdownFile(file)) {
39112
+ response.writeHead(400, { "content-type": "text/plain" });
39113
+ response.end("invalid file");
39114
+ return;
39115
+ }
39116
+ const graphNotebook = notebookForFile(file);
39117
+ if (!graphNotebook) {
39118
+ response.writeHead(404, { "content-type": "text/plain" });
39119
+ response.end("not found");
39120
+ return;
39121
+ }
39122
+ try {
39123
+ const engine = graphNotebook.getNoteMarkdownEngine(file);
39124
+ let html = engine.generateHTMLTemplateForGraphView({
39125
+ vscodePreviewPanel: dummyPanel
39126
+ });
39127
+ html = html.replace(/<script\b/, `${GRAPH_HOST_SHIM}<script`);
39128
+ response.writeHead(200, {
39129
+ "content-type": "text/html; charset=utf-8",
39130
+ ...BASE_SECURITY_HEADERS
39131
+ });
39132
+ response.end(html);
39133
+ } catch (error) {
39134
+ console.error("crossnote serve: failed to build graph view:", error);
39135
+ response.writeHead(500, { "content-type": "text/plain" });
39136
+ response.end("internal error");
39137
+ }
39138
+ return;
39139
+ }
39140
+ if (request.method === "GET" && urlPath === "/api/graph") {
39141
+ const file = assertFileWithinRoots(
39142
+ requestUrl.searchParams.get("file") ?? "/"
39143
+ );
39144
+ const graphNotebook = file ? notebookForFile(file) : null;
39145
+ if (!file || !graphNotebook) {
39146
+ sendJSON(response, 400, { error: "invalid file" });
39147
+ return;
39148
+ }
39149
+ try {
39150
+ await graphNotebook.refreshNotesIfNotLoaded({
39151
+ dir: ".",
39152
+ includeSubdirectories: true
39153
+ });
39154
+ const data = constructGraphView(graphNotebook);
39155
+ const rootIndex = rootIndexOf(file);
39156
+ const relativePath = rootIndex === -1 ? "" : path25.relative(rootDirectories[rootIndex], file).split(path25.sep).join("/");
39157
+ sendJSON(response, 200, { data, activeFilePath: relativePath });
39158
+ } catch (error) {
39159
+ console.error("crossnote serve: failed to build graph data:", error);
39160
+ sendJSON(response, 500, { error: "failed to build graph data" });
39161
+ }
39162
+ return;
39163
+ }
38546
39164
  if (request.method === "GET" && urlPath === "/api/events") {
38547
39165
  sse.addClient(response);
38548
39166
  return;