@hyperframes/producer 0.10.6 → 0.10.8

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.
package/README.md CHANGED
@@ -55,6 +55,14 @@ server never listens without a token. It listens on `127.0.0.1` unless you pass
55
55
  token yourself. `createProducerApp` without `authToken`, and `createRenderHandlers`
56
56
  always, check no caller: serve them only behind your own authentication.
57
57
 
58
+ `startServer` also answers `GET /health` on a second port, `PRODUCER_HEALTH_PORT` (default
59
+ `9848`), from its own thread, so a health probe is answered while a render keeps the main
60
+ thread busy. That port listens on the same address as the server itself, so it is loopback
61
+ only by default: a probe from another host needs `hostname` or `PRODUCER_HOST` set to an
62
+ address that host can reach, which also needs a token. A connection there that does not send
63
+ a whole request within a few seconds, or sits idle, is closed, and open connections are
64
+ capped at 64. Set `PRODUCER_DISABLE_HEALTH_WORKER=1` to leave the second port closed.
65
+
58
66
  A request's `projectDir` must resolve, symlinks included, inside
59
67
  `projectsDir` (`PRODUCER_PROJECTS_DIR`, default: the working directory). Its `entryFile`
60
68
  must stay inside that project, and `outputPath` must be inside `rendersDir`
@@ -530,7 +530,8 @@ import {
530
530
  isPrivateUnderAssetRoots as isPrivateUnderAssetRoots3,
531
531
  NotMediaPayloadError as NotMediaPayloadError2,
532
532
  parseMasterFxChain,
533
- probeMediaProfile as probeMediaProfile2
533
+ probeMediaProfile as probeMediaProfile2,
534
+ resolveRestrictPageNetwork
534
535
  } from "@hyperframes/engine";
535
536
 
536
537
  // src/utils/urlDownloader.ts
@@ -1987,7 +1988,7 @@ async function parseSubCompositions(html, projectDir2, downloadDir2, visited = /
1987
1988
  }
1988
1989
  return { subCompositions };
1989
1990
  }
1990
- function promoteCssImportsToLinkTags(html) {
1991
+ function promoteCssImportsToLinkTags(html, budget) {
1991
1992
  const { document: document2 } = parseHTML4(html);
1992
1993
  const head = document2.querySelector("head");
1993
1994
  if (!head) return html;
@@ -1996,18 +1997,16 @@ function promoteCssImportsToLinkTags(html) {
1996
1997
  const styleEls = document2.querySelectorAll("style");
1997
1998
  for (const styleEl of styleEls) {
1998
1999
  const original = styleEl.textContent || "";
1999
- let modified = original;
2000
- let match;
2001
- importRe.lastIndex = 0;
2002
- while ((match = importRe.exec(original)) !== null) {
2000
+ const rulesBetweenImports = [];
2001
+ let keptTo = 0;
2002
+ for (const match of original.matchAll(importRe)) {
2003
2003
  const url = match[1] ?? "";
2004
2004
  if (!url.startsWith("http://") && !url.startsWith("https://")) continue;
2005
- if (seenUrls.has(url)) {
2006
- modified = modified.replace(match[0], "");
2007
- continue;
2008
- }
2005
+ rulesBetweenImports.push(original.slice(keptTo, match.index));
2006
+ keptTo = match.index + match[0].length;
2007
+ if (seenUrls.has(url)) continue;
2009
2008
  seenUrls.add(url);
2010
- modified = modified.replace(match[0], "");
2009
+ budget.chargeElements(ENTRY_PAGE, 2);
2011
2010
  const preload = document2.createElement("link");
2012
2011
  preload.setAttribute("rel", "preload");
2013
2012
  preload.setAttribute("href", url);
@@ -2018,8 +2017,8 @@ function promoteCssImportsToLinkTags(html) {
2018
2017
  link.setAttribute("href", url);
2019
2018
  head.appendChild(link);
2020
2019
  }
2021
- if (modified !== original) {
2022
- styleEl.textContent = modified;
2020
+ if (keptTo > 0) {
2021
+ styleEl.textContent = rulesBetweenImports.join("") + original.slice(keptTo);
2023
2022
  }
2024
2023
  }
2025
2024
  return document2.toString();
@@ -2331,16 +2330,61 @@ function operatorGsapMirror() {
2331
2330
  return void 0;
2332
2331
  }
2333
2332
  }
2333
+ var MIRROR_GSAP_FILE = /^gsap@\d+(?:\.\d+)*\/dist\/[A-Za-z0-9][\w-]*(?:\.[\w-]+)*\.js$/;
2334
+ function isOperatorMirrorGsapUrl(src, mirror) {
2335
+ if (!mirror || /[?#%\\]/.test(src) || !URL.canParse(src)) return false;
2336
+ const url = new URL(src);
2337
+ if (url.search || url.hash || !url.href.startsWith(mirror)) return false;
2338
+ return MIRROR_GSAP_FILE.test(url.href.slice(mirror.length));
2339
+ }
2340
+ var warnedRestrictedMirror = false;
2341
+ function mirrorExemptionAllowed() {
2342
+ if (!resolveRestrictPageNetwork()) return true;
2343
+ if (!warnedRestrictedMirror) {
2344
+ warnedRestrictedMirror = true;
2345
+ defaultLogger.warn(
2346
+ "[Compiler] PRODUCER_RESTRICT_PAGE_NETWORK is on, so HYPERFRAMES_GSAP_BASE_URL is fetched only from a public HTTPS address."
2347
+ );
2348
+ }
2349
+ return false;
2350
+ }
2351
+ async function readCappedBody(response, src) {
2352
+ const tooLarge = () => new Error(`Script over 16 MiB: ${src}`);
2353
+ const declared = Number(response.headers.get("content-length"));
2354
+ if (Number.isFinite(declared) && declared > MAX_SCRIPT_BYTES) {
2355
+ await response.body?.cancel().catch(() => {
2356
+ });
2357
+ throw tooLarge();
2358
+ }
2359
+ if (!response.body) return new Uint8Array();
2360
+ const reader = response.body.getReader();
2361
+ const chunks = [];
2362
+ let received = 0;
2363
+ for (; ; ) {
2364
+ const { done, value } = await reader.read();
2365
+ if (done) break;
2366
+ received += value.byteLength;
2367
+ if (received > MAX_SCRIPT_BYTES) {
2368
+ await reader.cancel().catch(() => {
2369
+ });
2370
+ throw tooLarge();
2371
+ }
2372
+ chunks.push(value);
2373
+ }
2374
+ return Buffer.concat(chunks);
2375
+ }
2334
2376
  async function downloadScript(src, mirror, signal) {
2335
- if (mirror && new URL(src).href.startsWith(mirror)) {
2336
- const response = await fetch(src, {
2377
+ if (isOperatorMirrorGsapUrl(src, mirror) && mirrorExemptionAllowed()) {
2378
+ const response = await fetch(new URL(src).href, {
2337
2379
  redirect: "error",
2338
2380
  signal: AbortSignal.any([AbortSignal.timeout(15e3), signal])
2339
2381
  });
2340
- if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
2341
- const bytes = new Uint8Array(await response.arrayBuffer());
2342
- if (bytes.byteLength > MAX_SCRIPT_BYTES) throw new Error(`Script over 16 MiB: ${src}`);
2343
- return bytes;
2382
+ if (!response.ok) {
2383
+ await response.body?.cancel().catch(() => {
2384
+ });
2385
+ throw new Error(`HTTP ${response.status} for ${src}`);
2386
+ }
2387
+ return readCappedBody(response, src);
2344
2388
  }
2345
2389
  return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3, signal });
2346
2390
  }
@@ -2664,15 +2708,22 @@ function matchingBraces(css) {
2664
2708
  }
2665
2709
  return closes;
2666
2710
  }
2667
- function remoteFontStylesheetHref(tag) {
2668
- const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
2711
+ var attributeInAnyCase = (el, name) => [...el.attributes].find((attribute) => attribute.name.toLowerCase() === name)?.value;
2712
+ var WHERE_A_BROWSER_LOADS_NO_LINK = "noscript, iframe, noembed, noframes, plaintext, svg, math";
2713
+ function remoteFontStylesheetHref(link) {
2714
+ if (attributeInAnyCase(link, "rel")?.toLowerCase() !== "stylesheet") return void 0;
2715
+ if (link.closest(WHERE_A_BROWSER_LOADS_NO_LINK)) return void 0;
2716
+ const href = attributeInAnyCase(link, "href");
2669
2717
  if (!href || !/^https?:\/\//i.test(href) || isGoogleFontsUrl(href)) return void 0;
2670
2718
  return href;
2671
2719
  }
2672
2720
  async function inlineExternalFontStylesheets(html, budget = new CompositionExpansionBudget(), signal) {
2721
+ if (!/<link\b/i.test(html)) return html;
2722
+ const { document: document2 } = parseHTML4(html);
2723
+ const linkElements = [...document2.querySelectorAll("link")];
2673
2724
  const hrefs = /* @__PURE__ */ new Set();
2674
- for (const { parts } of stylesheetLinkMatches(html)) {
2675
- const href = remoteFontStylesheetHref(parts[0]);
2725
+ for (const link of linkElements) {
2726
+ const href = remoteFontStylesheetHref(link);
2676
2727
  if (href) hrefs.add(href);
2677
2728
  }
2678
2729
  if (hrefs.size === 0) return html;
@@ -2687,9 +2738,9 @@ async function inlineExternalFontStylesheets(html, budget = new CompositionExpan
2687
2738
  const fontFaceBlocks = css ? extractFontFaceBlocks(css) : [];
2688
2739
  if (fontFaceBlocks.length === 0) return;
2689
2740
  const fontCssWithLtAsCssEscape = fontFaceBlocks.join("\n").replace(/</g, "\\3c ");
2690
- const inlineStyle = `<style>/* Inlined external font stylesheet */
2741
+ const inlineStyle = `/* Inlined external font stylesheet */
2691
2742
  ${fontCssWithLtAsCssEscape}
2692
- </style>`;
2743
+ `;
2693
2744
  try {
2694
2745
  budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
2695
2746
  } catch (error) {
@@ -2707,14 +2758,17 @@ ${fontCssWithLtAsCssEscape}
2707
2758
  await Promise.allSettled([...hrefs].map((href) => limit(() => inlineSheet(href), fetchSignal)));
2708
2759
  if (stop.signal.aborted) throw stop.signal.reason;
2709
2760
  const placed = /* @__PURE__ */ new Set();
2710
- return replaceMatches(html, stylesheetLinkMatches(html), (tag) => {
2711
- const href = remoteFontStylesheetHref(tag);
2761
+ for (const link of linkElements) {
2762
+ const href = remoteFontStylesheetHref(link);
2712
2763
  const inlineStyle = href ? inlineByHref.get(href) : void 0;
2713
- if (!href || !inlineStyle) return tag;
2764
+ if (!href || !inlineStyle) continue;
2714
2765
  if (placed.has(href)) budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
2715
2766
  placed.add(href);
2716
- return inlineStyle;
2717
- });
2767
+ const style = document2.createElement("style");
2768
+ style.textContent = inlineStyle;
2769
+ link.replaceWith(style);
2770
+ }
2771
+ return placed.size === 0 ? html : document2.toString();
2718
2772
  }
2719
2773
  function projectStylesheetFontFamilies(html, projectDir2) {
2720
2774
  const families = [];
@@ -3066,7 +3120,7 @@ async function compileWithAssets(projectDir2, htmlPath2, downloadDir2, options2,
3066
3120
  ...options2.abortSignal ? [options2.abortSignal] : []
3067
3121
  ]);
3068
3122
  const fontSheetHtml = await inlineExternalFontStylesheets(
3069
- promoteCssImportsToLinkTags(sanitizedHtml),
3123
+ promoteCssImportsToLinkTags(sanitizedHtml, budget),
3070
3124
  budget,
3071
3125
  remoteFetches
3072
3126
  );
@@ -1769,6 +1769,9 @@ import { isPathInside as isPathInside3 } from "@hyperframes/parsers/asset-paths"
1769
1769
  import { previewToken } from "@hyperframes/core/preview-proof";
1770
1770
  import { replaceFileAtomically } from "@hyperframes/core/atomic-file";
1771
1771
 
1772
+ // src/services/render/segmentRecycle.ts
1773
+ import { isTransientScreenshotRefusal } from "@hyperframes/engine";
1774
+
1772
1775
  // src/services/render/stages/captureStreamingStage.ts
1773
1776
  import {
1774
1777
  DrawElementVerificationError,
@@ -2816,7 +2819,8 @@ import {
2816
2819
  isPrivateUnderAssetRoots as isPrivateUnderAssetRoots3,
2817
2820
  NotMediaPayloadError as NotMediaPayloadError2,
2818
2821
  parseMasterFxChain,
2819
- probeMediaProfile as probeMediaProfile2
2822
+ probeMediaProfile as probeMediaProfile2,
2823
+ resolveRestrictPageNetwork
2820
2824
  } from "@hyperframes/engine";
2821
2825
 
2822
2826
  // src/utils/urlDownloader.ts
@@ -4314,7 +4318,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
4314
4318
  }
4315
4319
  return { subCompositions };
4316
4320
  }
4317
- function promoteCssImportsToLinkTags(html) {
4321
+ function promoteCssImportsToLinkTags(html, budget) {
4318
4322
  const { document: document2 } = parseHTML5(html);
4319
4323
  const head = document2.querySelector("head");
4320
4324
  if (!head) return html;
@@ -4323,18 +4327,16 @@ function promoteCssImportsToLinkTags(html) {
4323
4327
  const styleEls = document2.querySelectorAll("style");
4324
4328
  for (const styleEl of styleEls) {
4325
4329
  const original = styleEl.textContent || "";
4326
- let modified = original;
4327
- let match;
4328
- importRe.lastIndex = 0;
4329
- while ((match = importRe.exec(original)) !== null) {
4330
+ const rulesBetweenImports = [];
4331
+ let keptTo = 0;
4332
+ for (const match of original.matchAll(importRe)) {
4330
4333
  const url = match[1] ?? "";
4331
4334
  if (!url.startsWith("http://") && !url.startsWith("https://")) continue;
4332
- if (seenUrls.has(url)) {
4333
- modified = modified.replace(match[0], "");
4334
- continue;
4335
- }
4335
+ rulesBetweenImports.push(original.slice(keptTo, match.index));
4336
+ keptTo = match.index + match[0].length;
4337
+ if (seenUrls.has(url)) continue;
4336
4338
  seenUrls.add(url);
4337
- modified = modified.replace(match[0], "");
4339
+ budget.chargeElements(ENTRY_PAGE, 2);
4338
4340
  const preload = document2.createElement("link");
4339
4341
  preload.setAttribute("rel", "preload");
4340
4342
  preload.setAttribute("href", url);
@@ -4345,8 +4347,8 @@ function promoteCssImportsToLinkTags(html) {
4345
4347
  link.setAttribute("href", url);
4346
4348
  head.appendChild(link);
4347
4349
  }
4348
- if (modified !== original) {
4349
- styleEl.textContent = modified;
4350
+ if (keptTo > 0) {
4351
+ styleEl.textContent = rulesBetweenImports.join("") + original.slice(keptTo);
4350
4352
  }
4351
4353
  }
4352
4354
  return document2.toString();
@@ -4658,16 +4660,61 @@ function operatorGsapMirror() {
4658
4660
  return void 0;
4659
4661
  }
4660
4662
  }
4663
+ var MIRROR_GSAP_FILE = /^gsap@\d+(?:\.\d+)*\/dist\/[A-Za-z0-9][\w-]*(?:\.[\w-]+)*\.js$/;
4664
+ function isOperatorMirrorGsapUrl(src, mirror) {
4665
+ if (!mirror || /[?#%\\]/.test(src) || !URL.canParse(src)) return false;
4666
+ const url = new URL(src);
4667
+ if (url.search || url.hash || !url.href.startsWith(mirror)) return false;
4668
+ return MIRROR_GSAP_FILE.test(url.href.slice(mirror.length));
4669
+ }
4670
+ var warnedRestrictedMirror = false;
4671
+ function mirrorExemptionAllowed() {
4672
+ if (!resolveRestrictPageNetwork()) return true;
4673
+ if (!warnedRestrictedMirror) {
4674
+ warnedRestrictedMirror = true;
4675
+ defaultLogger.warn(
4676
+ "[Compiler] PRODUCER_RESTRICT_PAGE_NETWORK is on, so HYPERFRAMES_GSAP_BASE_URL is fetched only from a public HTTPS address."
4677
+ );
4678
+ }
4679
+ return false;
4680
+ }
4681
+ async function readCappedBody(response, src) {
4682
+ const tooLarge = () => new Error(`Script over 16 MiB: ${src}`);
4683
+ const declared = Number(response.headers.get("content-length"));
4684
+ if (Number.isFinite(declared) && declared > MAX_SCRIPT_BYTES) {
4685
+ await response.body?.cancel().catch(() => {
4686
+ });
4687
+ throw tooLarge();
4688
+ }
4689
+ if (!response.body) return new Uint8Array();
4690
+ const reader = response.body.getReader();
4691
+ const chunks = [];
4692
+ let received = 0;
4693
+ for (; ; ) {
4694
+ const { done, value } = await reader.read();
4695
+ if (done) break;
4696
+ received += value.byteLength;
4697
+ if (received > MAX_SCRIPT_BYTES) {
4698
+ await reader.cancel().catch(() => {
4699
+ });
4700
+ throw tooLarge();
4701
+ }
4702
+ chunks.push(value);
4703
+ }
4704
+ return Buffer.concat(chunks);
4705
+ }
4661
4706
  async function downloadScript(src, mirror, signal) {
4662
- if (mirror && new URL(src).href.startsWith(mirror)) {
4663
- const response = await fetch(src, {
4707
+ if (isOperatorMirrorGsapUrl(src, mirror) && mirrorExemptionAllowed()) {
4708
+ const response = await fetch(new URL(src).href, {
4664
4709
  redirect: "error",
4665
4710
  signal: AbortSignal.any([AbortSignal.timeout(15e3), signal])
4666
4711
  });
4667
- if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
4668
- const bytes = new Uint8Array(await response.arrayBuffer());
4669
- if (bytes.byteLength > MAX_SCRIPT_BYTES) throw new Error(`Script over 16 MiB: ${src}`);
4670
- return bytes;
4712
+ if (!response.ok) {
4713
+ await response.body?.cancel().catch(() => {
4714
+ });
4715
+ throw new Error(`HTTP ${response.status} for ${src}`);
4716
+ }
4717
+ return readCappedBody(response, src);
4671
4718
  }
4672
4719
  return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3, signal });
4673
4720
  }
@@ -4991,15 +5038,22 @@ function matchingBraces(css) {
4991
5038
  }
4992
5039
  return closes;
4993
5040
  }
4994
- function remoteFontStylesheetHref(tag) {
4995
- const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
5041
+ var attributeInAnyCase = (el, name) => [...el.attributes].find((attribute) => attribute.name.toLowerCase() === name)?.value;
5042
+ var WHERE_A_BROWSER_LOADS_NO_LINK = "noscript, iframe, noembed, noframes, plaintext, svg, math";
5043
+ function remoteFontStylesheetHref(link) {
5044
+ if (attributeInAnyCase(link, "rel")?.toLowerCase() !== "stylesheet") return void 0;
5045
+ if (link.closest(WHERE_A_BROWSER_LOADS_NO_LINK)) return void 0;
5046
+ const href = attributeInAnyCase(link, "href");
4996
5047
  if (!href || !/^https?:\/\//i.test(href) || isGoogleFontsUrl(href)) return void 0;
4997
5048
  return href;
4998
5049
  }
4999
5050
  async function inlineExternalFontStylesheets(html, budget = new CompositionExpansionBudget(), signal) {
5051
+ if (!/<link\b/i.test(html)) return html;
5052
+ const { document: document2 } = parseHTML5(html);
5053
+ const linkElements = [...document2.querySelectorAll("link")];
5000
5054
  const hrefs = /* @__PURE__ */ new Set();
5001
- for (const { parts } of stylesheetLinkMatches(html)) {
5002
- const href = remoteFontStylesheetHref(parts[0]);
5055
+ for (const link of linkElements) {
5056
+ const href = remoteFontStylesheetHref(link);
5003
5057
  if (href) hrefs.add(href);
5004
5058
  }
5005
5059
  if (hrefs.size === 0) return html;
@@ -5014,9 +5068,9 @@ async function inlineExternalFontStylesheets(html, budget = new CompositionExpan
5014
5068
  const fontFaceBlocks = css ? extractFontFaceBlocks(css) : [];
5015
5069
  if (fontFaceBlocks.length === 0) return;
5016
5070
  const fontCssWithLtAsCssEscape = fontFaceBlocks.join("\n").replace(/</g, "\\3c ");
5017
- const inlineStyle = `<style>/* Inlined external font stylesheet */
5071
+ const inlineStyle = `/* Inlined external font stylesheet */
5018
5072
  ${fontCssWithLtAsCssEscape}
5019
- </style>`;
5073
+ `;
5020
5074
  try {
5021
5075
  budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
5022
5076
  } catch (error) {
@@ -5034,14 +5088,17 @@ ${fontCssWithLtAsCssEscape}
5034
5088
  await Promise.allSettled([...hrefs].map((href) => limit(() => inlineSheet(href), fetchSignal)));
5035
5089
  if (stop.signal.aborted) throw stop.signal.reason;
5036
5090
  const placed = /* @__PURE__ */ new Set();
5037
- return replaceMatches(html, stylesheetLinkMatches(html), (tag) => {
5038
- const href = remoteFontStylesheetHref(tag);
5091
+ for (const link of linkElements) {
5092
+ const href = remoteFontStylesheetHref(link);
5039
5093
  const inlineStyle = href ? inlineByHref.get(href) : void 0;
5040
- if (!href || !inlineStyle) return tag;
5094
+ if (!href || !inlineStyle) continue;
5041
5095
  if (placed.has(href)) budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
5042
5096
  placed.add(href);
5043
- return inlineStyle;
5044
- });
5097
+ const style = document2.createElement("style");
5098
+ style.textContent = inlineStyle;
5099
+ link.replaceWith(style);
5100
+ }
5101
+ return placed.size === 0 ? html : document2.toString();
5045
5102
  }
5046
5103
  function projectStylesheetFontFamilies(html, projectDir) {
5047
5104
  const families = [];
@@ -5393,7 +5450,7 @@ async function compileWithAssets(projectDir, htmlPath, downloadDir, options, ass
5393
5450
  ...options.abortSignal ? [options.abortSignal] : []
5394
5451
  ]);
5395
5452
  const fontSheetHtml = await inlineExternalFontStylesheets(
5396
- promoteCssImportsToLinkTags(sanitizedHtml),
5453
+ promoteCssImportsToLinkTags(sanitizedHtml, budget),
5397
5454
  budget,
5398
5455
  remoteFetches
5399
5456
  );
@@ -7419,7 +7476,7 @@ import {
7419
7476
  assetRootsRefusal,
7420
7477
  assertPublicHttpsUrl,
7421
7478
  downloadToTemp as downloadToTemp2,
7422
- resolveRestrictPageNetwork,
7479
+ resolveRestrictPageNetwork as resolveRestrictPageNetwork2,
7423
7480
  isUrlNotPermittedError,
7424
7481
  writeUrlDownloadTelemetry as writeUrlDownloadTelemetry2,
7425
7482
  resolveProjectRelativeSrc as resolveProjectRelativeSrc5,
@@ -7872,7 +7929,7 @@ function localProbeSource(src, input) {
7872
7929
  }
7873
7930
  async function remoteProbeSource(video, input) {
7874
7931
  if (!isPublicHttpsUrl(video.src)) return null;
7875
- if (!resolveRestrictPageNetwork()) return video.src;
7932
+ if (!resolveRestrictPageNetwork2()) return video.src;
7876
7933
  if (!video.hasAudio || video.hidden) return null;
7877
7934
  const downloadDir = input.downloadDir ?? join14(input.compiledDir, REMOTE_MEDIA_SUBDIR);
7878
7935
  try {
@@ -3,10 +3,14 @@ import { createServer } from "node:http";
3
3
  import { parentPort, workerData } from "node:worker_threads";
4
4
  var startTime = Date.now();
5
5
  var port = Number(workerData?.port ?? 9848);
6
+ var hostname = typeof workerData?.hostname === "string" && workerData.hostname ? workerData.hostname : "127.0.0.1";
7
+ var closeAfterMs = Number(workerData?.closeAfterMs) > 0 ? Number(workerData.closeAfterMs) : 5e3;
8
+ var MAX_CONNECTIONS = 64;
6
9
  if (!parentPort) {
7
10
  throw new Error("[healthWorkerThread] must run inside a worker_thread");
8
11
  }
9
- var server = createServer((req, res) => {
12
+ var options = { connectionsCheckingInterval: Math.min(1e3, closeAfterMs) };
13
+ var server = createServer(options, (req, res) => {
10
14
  if (req.method === "GET" && (req.url === "/health" || req.url?.startsWith("/health?"))) {
11
15
  const body = JSON.stringify({
12
16
  status: "ok",
@@ -25,9 +29,11 @@ var server = createServer((req, res) => {
25
29
  res.writeHead(404, { "Content-Type": "text/plain" });
26
30
  res.end("Not found");
27
31
  });
28
- server.keepAliveTimeout = 0;
29
- server.requestTimeout = 0;
30
- server.headersTimeout = 0;
32
+ server.headersTimeout = closeAfterMs;
33
+ server.requestTimeout = closeAfterMs;
34
+ server.keepAliveTimeout = closeAfterMs;
35
+ server.setTimeout(closeAfterMs * 2);
36
+ server.maxConnections = MAX_CONNECTIONS;
31
37
  server.on("error", (err) => {
32
38
  parentPort?.postMessage({
33
39
  type: "listen-error",
@@ -35,7 +41,7 @@ server.on("error", (err) => {
35
41
  });
36
42
  setTimeout(() => parentPort?.close(), 50);
37
43
  });
38
- server.listen(port, "0.0.0.0", () => {
44
+ server.listen(port, hostname, () => {
39
45
  parentPort?.postMessage({ type: "listening", port });
40
46
  });
41
47
  parentPort.on("message", (msg) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": "0.1.0",
3
3
  "buildId": "dev",
4
- "sha256": "902af35de9e8d59903bf866fd6e0dec48f5430b88d3bc93f79f1129bd2153560",
4
+ "sha256": "8cd6cfc653504d62a4c77d19ff00377b60b8a9a4ef66ee7ac4d84d1d17855c7c",
5
5
  "artifacts": {
6
6
  "iife": "hyperframe.runtime.iife.js",
7
7
  "esm": "hyperframe.runtime.mjs"