@fedify/cli 2.1.29 → 2.1.31
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
|
@@ -10,7 +10,7 @@ import { bindConfig } from "@optique/config";
|
|
|
10
10
|
import { getNodeInfo } from "@fedify/fedify";
|
|
11
11
|
import { getLogger } from "@logtape/logtape";
|
|
12
12
|
import ora from "ora";
|
|
13
|
-
import { getUserAgent } from "@fedify/vocab-runtime";
|
|
13
|
+
import { getUserAgent, validatePublicUrl } from "@fedify/vocab-runtime";
|
|
14
14
|
import { createJimp } from "@jimp/core";
|
|
15
15
|
import webp from "@jimp/wasm-webp";
|
|
16
16
|
import { isICO, parseICO } from "icojs";
|
|
@@ -21,6 +21,29 @@ const logger = getLogger([
|
|
|
21
21
|
"cli",
|
|
22
22
|
"nodeinfo"
|
|
23
23
|
]);
|
|
24
|
+
const MAX_FAVICON_REDIRECTS = 5;
|
|
25
|
+
async function fetchFaviconResource(url, userAgent) {
|
|
26
|
+
let current = typeof url === "string" ? new URL(url) : url;
|
|
27
|
+
for (let redirects = 0;; redirects++) {
|
|
28
|
+
await validatePublicUrl(current.href);
|
|
29
|
+
const response = await fetch(current, {
|
|
30
|
+
headers: { "User-Agent": userAgent == null ? getUserAgent() : userAgent },
|
|
31
|
+
redirect: "manual"
|
|
32
|
+
});
|
|
33
|
+
if (response.status !== 301 && response.status !== 302 && response.status !== 303 && response.status !== 307 && response.status !== 308) return {
|
|
34
|
+
response,
|
|
35
|
+
url: current
|
|
36
|
+
};
|
|
37
|
+
const location = response.headers.get("Location");
|
|
38
|
+
if (location == null) return {
|
|
39
|
+
response,
|
|
40
|
+
url: current
|
|
41
|
+
};
|
|
42
|
+
await response.body?.cancel();
|
|
43
|
+
if (redirects >= MAX_FAVICON_REDIRECTS) throw new Error("Too many favicon redirects");
|
|
44
|
+
current = new URL(location, current);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
24
47
|
const Jimp = createJimp({
|
|
25
48
|
formats: [...defaultFormats, webp],
|
|
26
49
|
plugins: defaultPlugins
|
|
@@ -91,8 +114,7 @@ async function runNodeInfo(command) {
|
|
|
91
114
|
if (!command.noFavicon) {
|
|
92
115
|
spinner.text = "Fetching the favicon...";
|
|
93
116
|
try {
|
|
94
|
-
const
|
|
95
|
-
const response = await fetch(faviconUrl, { headers: { "User-Agent": command.userAgent == null ? getUserAgent() : command.userAgent } });
|
|
117
|
+
const { response } = await fetchFaviconResource(await getFaviconUrl(url, command.userAgent), command.userAgent);
|
|
96
118
|
if (response.ok) {
|
|
97
119
|
const contentType = response.headers.get("Content-Type");
|
|
98
120
|
let buffer = await response.arrayBuffer();
|
|
@@ -171,7 +193,7 @@ function indent(text, depth) {
|
|
|
171
193
|
const LINK_REGEXP = /<link((?:\s+(?:[-a-z]+)=(?:"[^"]*"|'[^']*'|[^\s]+))*)\s*\/?>/gi;
|
|
172
194
|
const LINK_ATTRS_REGEXP = /(?:\s+([-a-z]+)=("[^"]*"|'[^']*'|[^\s]+))/gi;
|
|
173
195
|
async function getFaviconUrl(url, userAgent) {
|
|
174
|
-
const response
|
|
196
|
+
const { response, url: finalUrl } = await fetchFaviconResource(url, userAgent);
|
|
175
197
|
const text = await response.text();
|
|
176
198
|
for (const match of text.matchAll(LINK_REGEXP)) {
|
|
177
199
|
const attrs = {};
|
|
@@ -186,12 +208,12 @@ async function getFaviconUrl(url, userAgent) {
|
|
|
186
208
|
if (w < 38 || h < 19) continue;
|
|
187
209
|
}
|
|
188
210
|
if ("href" in attrs) {
|
|
189
|
-
const parsedUrl = new URL(attrs.href,
|
|
211
|
+
const parsedUrl = new URL(attrs.href, finalUrl);
|
|
190
212
|
if (parsedUrl.pathname.toLowerCase().endsWith(".svg")) continue;
|
|
191
213
|
return parsedUrl;
|
|
192
214
|
}
|
|
193
215
|
}
|
|
194
|
-
return new URL("/favicon.ico",
|
|
216
|
+
return new URL("/favicon.ico", finalUrl);
|
|
195
217
|
}
|
|
196
218
|
function checkTerminalColorSupport() {
|
|
197
219
|
const noColor = process.env.NO_COLOR;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/cli",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.31",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"README.md",
|
|
@@ -86,14 +86,14 @@
|
|
|
86
86
|
"smol-toml": "^1.6.0",
|
|
87
87
|
"srvx": "^0.8.7",
|
|
88
88
|
"valibot": "^1.2.0",
|
|
89
|
-
"@fedify/fedify": "2.1.
|
|
90
|
-
"@fedify/init": "2.1.
|
|
91
|
-
"@fedify/relay": "2.1.
|
|
92
|
-
"@fedify/sqlite": "2.1.
|
|
93
|
-
"@fedify/vocab": "2.1.
|
|
94
|
-
"@fedify/vocab
|
|
95
|
-
"@fedify/
|
|
96
|
-
"@fedify/
|
|
89
|
+
"@fedify/fedify": "2.1.31",
|
|
90
|
+
"@fedify/init": "2.1.31",
|
|
91
|
+
"@fedify/relay": "2.1.31",
|
|
92
|
+
"@fedify/sqlite": "2.1.31",
|
|
93
|
+
"@fedify/vocab-tools": "2.1.31",
|
|
94
|
+
"@fedify/vocab": "2.1.31",
|
|
95
|
+
"@fedify/webfinger": "2.1.31",
|
|
96
|
+
"@fedify/vocab-runtime": "2.1.31"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@types/bun": "^1.2.23",
|