@fedify/cli 2.5.0-dev.2448 → 2.5.0-dev.2494

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/dist/deno.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "temporal-polyfill";
2
2
  //#region deno.json
3
- var version = "2.5.0-dev.2448+756933d0";
3
+ var version = "2.5.0-dev.2494+f2e9b5d3";
4
4
  //#endregion
5
5
  export { version };
package/dist/nodeinfo.js CHANGED
@@ -7,7 +7,7 @@ import { argument, command, constant, flag, group, merge, message, object, strin
7
7
  import { print, printError } from "@optique/run";
8
8
  import os from "node:os";
9
9
  import { bindConfig } from "@optique/config";
10
- import { getUserAgent } from "@fedify/vocab-runtime";
10
+ import { getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
11
11
  import { getNodeInfo } from "@fedify/fedify";
12
12
  import { createJimp } from "@jimp/core";
13
13
  import webp from "@jimp/wasm-webp";
@@ -23,6 +23,29 @@ const logger = getLogger([
23
23
  "cli",
24
24
  "nodeinfo"
25
25
  ]);
26
+ const MAX_FAVICON_REDIRECTS = 5;
27
+ async function fetchFaviconResource(url, userAgent) {
28
+ let current = typeof url === "string" ? new URL(url) : url;
29
+ for (let redirects = 0;; redirects++) {
30
+ await validatePublicUrl(current.href);
31
+ const response = await fetch(current, {
32
+ headers: { "User-Agent": userAgent == null ? getUserAgent() : userAgent },
33
+ redirect: "manual"
34
+ });
35
+ if (response.status !== 301 && response.status !== 302 && response.status !== 303 && response.status !== 307 && response.status !== 308) return {
36
+ response,
37
+ url: current
38
+ };
39
+ const location = response.headers.get("Location");
40
+ if (location == null) return {
41
+ response,
42
+ url: current
43
+ };
44
+ await response.body?.cancel();
45
+ if (redirects >= MAX_FAVICON_REDIRECTS) throw new Error("Too many favicon redirects");
46
+ current = new URL(location, current);
47
+ }
48
+ }
26
49
  const Jimp = createJimp({
27
50
  formats: [...defaultFormats, webp],
28
51
  plugins: defaultPlugins
@@ -132,8 +155,7 @@ async function runNodeInfo(command) {
132
155
  if (!command.noFavicon) {
133
156
  spinner.text = "Fetching the favicon...";
134
157
  try {
135
- const faviconUrl = await getFaviconUrl(url, command.userAgent);
136
- const response = await fetch(faviconUrl, { headers: { "User-Agent": command.userAgent == null ? getUserAgent() : command.userAgent } });
158
+ const { response } = await fetchFaviconResource(await getFaviconUrl(url, command.userAgent), command.userAgent);
137
159
  if (response.ok) {
138
160
  const contentType = response.headers.get("Content-Type");
139
161
  let buffer = await response.arrayBuffer();
@@ -214,7 +236,7 @@ function indent(text, depth) {
214
236
  const LINK_REGEXP = /<link((?:\s+(?:[-a-z]+)=(?:"[^"]*"|'[^']*'|[^\s]+))*)\s*\/?>/gi;
215
237
  const LINK_ATTRS_REGEXP = /(?:\s+([-a-z]+)=("[^"]*"|'[^']*'|[^\s]+))/gi;
216
238
  async function getFaviconUrl(url, userAgent) {
217
- const response = await fetch(url, { headers: { "User-Agent": userAgent == null ? getUserAgent() : userAgent } });
239
+ const { response, url: finalUrl } = await fetchFaviconResource(url, userAgent);
218
240
  const text = await response.text();
219
241
  for (const match of text.matchAll(LINK_REGEXP)) {
220
242
  const attrs = {};
@@ -230,13 +252,13 @@ async function getFaviconUrl(url, userAgent) {
230
252
  return w >= 38 && h >= 19;
231
253
  })) continue;
232
254
  if ("href" in attrs) {
233
- const parsedUrl = new URL(attrs.href, response.url);
255
+ const parsedUrl = new URL(attrs.href, finalUrl);
234
256
  if (parsedUrl.pathname.toLowerCase().endsWith(".svg")) continue;
235
257
  if (attrs.type?.toLowerCase()?.trim() === "image/svg+xml") continue;
236
258
  return parsedUrl;
237
259
  }
238
260
  }
239
- return new URL("/favicon.ico", response.url);
261
+ return new URL("/favicon.ico", finalUrl);
240
262
  }
241
263
  function checkTerminalColorSupport() {
242
264
  const noColor = process.env.NO_COLOR;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cli",
3
- "version": "2.5.0-dev.2448+756933d0",
3
+ "version": "2.5.0-dev.2494+f2e9b5d3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "README.md",
@@ -88,14 +88,14 @@
88
88
  "temporal-polyfill": "^1.0.1",
89
89
  "valibot": "^1.4.0",
90
90
  "yaml": "^2.9.0",
91
- "@fedify/fedify": "2.5.0-dev.2448+756933d0",
92
- "@fedify/relay": "2.5.0-dev.2448+756933d0",
93
- "@fedify/sqlite": "2.5.0-dev.2448+756933d0",
94
- "@fedify/vocab": "2.5.0-dev.2448+756933d0",
95
- "@fedify/init": "2.5.0-dev.2448+756933d0",
96
- "@fedify/vocab-runtime": "2.5.0-dev.2448+756933d0",
97
- "@fedify/webfinger": "2.5.0-dev.2448+756933d0",
98
- "@fedify/vocab-tools": "2.5.0-dev.2448+756933d0"
91
+ "@fedify/fedify": "2.5.0-dev.2494+f2e9b5d3",
92
+ "@fedify/relay": "2.5.0-dev.2494+f2e9b5d3",
93
+ "@fedify/init": "2.5.0-dev.2494+f2e9b5d3",
94
+ "@fedify/sqlite": "2.5.0-dev.2494+f2e9b5d3",
95
+ "@fedify/vocab-tools": "2.5.0-dev.2494+f2e9b5d3",
96
+ "@fedify/vocab": "2.5.0-dev.2494+f2e9b5d3",
97
+ "@fedify/vocab-runtime": "2.5.0-dev.2494+f2e9b5d3",
98
+ "@fedify/webfinger": "2.5.0-dev.2494+f2e9b5d3"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@types/bun": "^1.2.23",