@fedify/cli 2.3.15-dev.2482 → 2.3.15

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 "@js-temporal/polyfill";
2
2
  //#region deno.json
3
- var version = "2.3.15-dev.2482+41d364a2";
3
+ var version = "2.3.15";
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();
@@ -212,7 +234,7 @@ function indent(text, depth) {
212
234
  const LINK_REGEXP = /<link((?:\s+(?:[-a-z]+)=(?:"[^"]*"|'[^']*'|[^\s]+))*)\s*\/?>/gi;
213
235
  const LINK_ATTRS_REGEXP = /(?:\s+([-a-z]+)=("[^"]*"|'[^']*'|[^\s]+))/gi;
214
236
  async function getFaviconUrl(url, userAgent) {
215
- const response = await fetch(url, { headers: { "User-Agent": userAgent == null ? getUserAgent() : userAgent } });
237
+ const { response, url: finalUrl } = await fetchFaviconResource(url, userAgent);
216
238
  const text = await response.text();
217
239
  for (const match of text.matchAll(LINK_REGEXP)) {
218
240
  const attrs = {};
@@ -227,12 +249,12 @@ async function getFaviconUrl(url, userAgent) {
227
249
  if (w < 38 || h < 19) continue;
228
250
  }
229
251
  if ("href" in attrs) {
230
- const parsedUrl = new URL(attrs.href, response.url);
252
+ const parsedUrl = new URL(attrs.href, finalUrl);
231
253
  if (parsedUrl.pathname.toLowerCase().endsWith(".svg")) continue;
232
254
  return parsedUrl;
233
255
  }
234
256
  }
235
- return new URL("/favicon.ico", response.url);
257
+ return new URL("/favicon.ico", finalUrl);
236
258
  }
237
259
  function checkTerminalColorSupport() {
238
260
  const noColor = process.env.NO_COLOR;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/cli",
3
- "version": "2.3.15-dev.2482+41d364a2",
3
+ "version": "2.3.15",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "README.md",
@@ -91,14 +91,14 @@
91
91
  "srvx": "^0.8.7",
92
92
  "valibot": "^1.4.0",
93
93
  "yaml": "^2.9.0",
94
- "@fedify/fedify": "2.3.15-dev.2482+41d364a2",
95
- "@fedify/sqlite": "2.3.15-dev.2482+41d364a2",
96
- "@fedify/vocab-tools": "2.3.15-dev.2482+41d364a2",
97
- "@fedify/vocab": "2.3.15-dev.2482+41d364a2",
98
- "@fedify/relay": "2.3.15-dev.2482+41d364a2",
99
- "@fedify/webfinger": "2.3.15-dev.2482+41d364a2",
100
- "@fedify/vocab-runtime": "2.3.15-dev.2482+41d364a2",
101
- "@fedify/init": "2.3.15-dev.2482+41d364a2"
94
+ "@fedify/fedify": "2.3.15",
95
+ "@fedify/init": "2.3.15",
96
+ "@fedify/vocab-runtime": "2.3.15",
97
+ "@fedify/sqlite": "2.3.15",
98
+ "@fedify/vocab-tools": "2.3.15",
99
+ "@fedify/webfinger": "2.3.15",
100
+ "@fedify/vocab": "2.3.15",
101
+ "@fedify/relay": "2.3.15"
102
102
  },
103
103
  "devDependencies": {
104
104
  "@types/bun": "^1.2.23",