@fedify/cli 2.4.5-dev.2476 → 2.4.5
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 +1 -1
- package/dist/nodeinfo.js +28 -6
- package/package.json +9 -9
package/dist/deno.js
CHANGED
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
|
|
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
|
|
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 = {};
|
|
@@ -229,12 +251,12 @@ async function getFaviconUrl(url, userAgent) {
|
|
|
229
251
|
if (w < 38 || h < 19) continue;
|
|
230
252
|
}
|
|
231
253
|
if ("href" in attrs) {
|
|
232
|
-
const parsedUrl = new URL(attrs.href,
|
|
254
|
+
const parsedUrl = new URL(attrs.href, finalUrl);
|
|
233
255
|
if (parsedUrl.pathname.toLowerCase().endsWith(".svg")) continue;
|
|
234
256
|
return parsedUrl;
|
|
235
257
|
}
|
|
236
258
|
}
|
|
237
|
-
return new URL("/favicon.ico",
|
|
259
|
+
return new URL("/favicon.ico", finalUrl);
|
|
238
260
|
}
|
|
239
261
|
function checkTerminalColorSupport() {
|
|
240
262
|
const noColor = process.env.NO_COLOR;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/cli",
|
|
3
|
-
"version": "2.4.5
|
|
3
|
+
"version": "2.4.5",
|
|
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.4.5
|
|
92
|
-
"@fedify/
|
|
93
|
-
"@fedify/
|
|
94
|
-
"@fedify/
|
|
95
|
-
"@fedify/vocab": "2.4.5
|
|
96
|
-
"@fedify/
|
|
97
|
-
"@fedify/
|
|
98
|
-
"@fedify/webfinger": "2.4.5
|
|
91
|
+
"@fedify/fedify": "2.4.5",
|
|
92
|
+
"@fedify/init": "2.4.5",
|
|
93
|
+
"@fedify/vocab": "2.4.5",
|
|
94
|
+
"@fedify/relay": "2.4.5",
|
|
95
|
+
"@fedify/vocab-runtime": "2.4.5",
|
|
96
|
+
"@fedify/sqlite": "2.4.5",
|
|
97
|
+
"@fedify/vocab-tools": "2.4.5",
|
|
98
|
+
"@fedify/webfinger": "2.4.5"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@types/bun": "^1.2.23",
|