@fedify/fedify 0.15.0-dev.375 → 0.15.0-dev.377
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGES.md +11 -0
- package/esm/runtime/docloader.js +54 -8
- package/package.json +1 -1
- package/types/runtime/docloader.d.ts.map +1 -1
package/CHANGES.md
CHANGED
@@ -10,10 +10,21 @@ To be released.
|
|
10
10
|
|
11
11
|
- Removed `expand` option of `Object.toJsonLd()` method, which was deprecated
|
12
12
|
in version 0.14.0. Use `format: "expand"` option instead.
|
13
|
+
|
13
14
|
- Added `Context.lookupObject()` method.
|
15
|
+
|
16
|
+
- Default document loaders now recognize ActivityStream objects in more ways:
|
17
|
+
|
18
|
+
- Loaders now recognize `alternate` ActivityStreams objects in the `Link`
|
19
|
+
header.
|
20
|
+
- Loaders now recognize `alternate` ActivityStreams objects in
|
21
|
+
the `<link>`/`<a>` HTML elements.
|
22
|
+
|
14
23
|
- Added `allowPrivateAddress` option to `CreateFederationOptions` interface.
|
24
|
+
|
15
25
|
- Renamed the short option `-c` for `--compact` of `fedify lookup` command to
|
16
26
|
`-C` to avoid conflict with the short option `-c` for `--cache-dir`.
|
27
|
+
|
17
28
|
- Added `-r`/`--raw` option to `fedify lookup` command to output the raw JSON
|
18
29
|
object.
|
19
30
|
|
package/esm/runtime/docloader.js
CHANGED
@@ -41,7 +41,7 @@ function logRequest(request) {
|
|
41
41
|
headers: Object.fromEntries(request.headers.entries()),
|
42
42
|
});
|
43
43
|
}
|
44
|
-
async function getRemoteDocument(url, response) {
|
44
|
+
async function getRemoteDocument(url, response, fetch) {
|
45
45
|
const documentUrl = response.url === "" ? url : response.url;
|
46
46
|
if (!response.ok) {
|
47
47
|
logger.error("Failed to fetch document: {status} {url} {headers}", {
|
@@ -51,15 +51,61 @@ async function getRemoteDocument(url, response) {
|
|
51
51
|
});
|
52
52
|
throw new FetchError(documentUrl, `HTTP ${response.status}: ${documentUrl}`);
|
53
53
|
}
|
54
|
+
const contentType = response.headers.get("Content-Type");
|
55
|
+
const jsonLd = contentType == null ||
|
56
|
+
contentType === "application/activity+json" ||
|
57
|
+
contentType === "application/ld+json" ||
|
58
|
+
contentType.startsWith("application/ld+json;");
|
54
59
|
const linkHeader = response.headers.get("Link");
|
55
60
|
let contextUrl = null;
|
56
61
|
if (linkHeader != null) {
|
57
62
|
const link = new HTTPHeaderLink(linkHeader);
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
if (jsonLd) {
|
64
|
+
const entries = link.getByRel("http://www.w3.org/ns/json-ld#context");
|
65
|
+
for (const [uri, params] of entries) {
|
66
|
+
if ("type" in params && params.type === "application/ld+json") {
|
67
|
+
contextUrl = uri;
|
68
|
+
break;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
const entries = link.getByRel("alternate");
|
74
|
+
for (const [uri, params] of entries) {
|
75
|
+
if ("type" in params &&
|
76
|
+
(params.type === "application/activity+json" ||
|
77
|
+
params.type === "application/ld+json" ||
|
78
|
+
params.type.startsWith("application/ld+json;"))) {
|
79
|
+
logger.debug("Found alternate document: {alternateUrl} from {url}", { alternateUrl: uri, url: documentUrl });
|
80
|
+
return await fetch(uri);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
if (!jsonLd &&
|
86
|
+
(contentType === "text/html" || contentType?.startsWith("text/html;") ||
|
87
|
+
contentType === "application/xhtml+xml" ||
|
88
|
+
contentType?.startsWith("application/xhtml+xml;"))) {
|
89
|
+
const p = /<(a|link)((\s+[a-z][a-z:_-]*=("[^"]*"|'[^']*'|[^\s>]+))+)\/?>/ig;
|
90
|
+
const p2 = /\s+([a-z][a-z:_-]*)=("([^"]*)"|'([^']*)'|([^\s>]+))/ig;
|
91
|
+
const html = await response.text();
|
92
|
+
let m;
|
93
|
+
const rawAttribs = [];
|
94
|
+
while ((m = p.exec(html)) !== null)
|
95
|
+
rawAttribs.push(m[2]);
|
96
|
+
for (const rawAttrs of rawAttribs) {
|
97
|
+
let m2;
|
98
|
+
const attribs = {};
|
99
|
+
while ((m2 = p2.exec(rawAttrs)) !== null) {
|
100
|
+
const key = m2[1].toLowerCase();
|
101
|
+
const value = m2[3] ?? m2[4] ?? m2[5] ?? "";
|
102
|
+
attribs[key] = value;
|
103
|
+
}
|
104
|
+
if (attribs.rel === "alternate" && "type" in attribs && (attribs.type === "application/activity+json" ||
|
105
|
+
attribs.type === "application/ld+json" ||
|
106
|
+
attribs.type.startsWith("application/ld+json;")) && "href" in attribs) {
|
107
|
+
logger.debug("Found alternate document: {alternateUrl} from {url}", { alternateUrl: attribs.href, url: documentUrl });
|
108
|
+
return await fetch(attribs.href);
|
63
109
|
}
|
64
110
|
}
|
65
111
|
}
|
@@ -122,7 +168,7 @@ export async function fetchDocumentLoader(url, allowPrivateAddress = false) {
|
|
122
168
|
response.headers.has("Location")) {
|
123
169
|
return fetchDocumentLoader(response.headers.get("Location"));
|
124
170
|
}
|
125
|
-
return getRemoteDocument(url, response);
|
171
|
+
return getRemoteDocument(url, response, (url) => fetchDocumentLoader(url, allowPrivateAddress));
|
126
172
|
}
|
127
173
|
/**
|
128
174
|
* Gets an authenticated {@link DocumentLoader} for the given identity.
|
@@ -164,7 +210,7 @@ export function getAuthenticatedDocumentLoader(identity, allowPrivateAddress = f
|
|
164
210
|
response.headers.has("Location")) {
|
165
211
|
return load(response.headers.get("Location"));
|
166
212
|
}
|
167
|
-
return getRemoteDocument(url, response);
|
213
|
+
return getRemoteDocument(url, response, load);
|
168
214
|
}
|
169
215
|
return load;
|
170
216
|
}
|
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"docloader.d.ts","sourceRoot":"","sources":["../../src/runtime/docloader.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAG5C,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAQ1D;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;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