@rmdes/indiekit-endpoint-activitypub 3.7.2 → 3.7.4
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/index.js +2 -8
- package/lib/controllers/resolve.js +2 -1
- package/lib/lookup-helpers.js +27 -5
- package/lib/mastodon/routes/statuses.js +71 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -721,19 +721,13 @@ export default class ActivityPubEndpoint {
|
|
|
721
721
|
);
|
|
722
722
|
|
|
723
723
|
// Resolve the remote actor to get their inbox
|
|
724
|
-
//
|
|
725
|
-
// fall back to unsigned if that fails (some servers reject signed GETs)
|
|
724
|
+
// lookupWithSecurity handles signed→unsigned fallback automatically
|
|
726
725
|
const documentLoader = await ctx.getDocumentLoader({
|
|
727
726
|
identifier: handle,
|
|
728
727
|
});
|
|
729
|
-
|
|
728
|
+
const remoteActor = await lookupWithSecurity(ctx, actorUrl, {
|
|
730
729
|
documentLoader,
|
|
731
730
|
});
|
|
732
|
-
if (!remoteActor) {
|
|
733
|
-
// Retry without authentication — some servers (e.g., tags.pub)
|
|
734
|
-
// may reject or mishandle signed GET requests
|
|
735
|
-
remoteActor = await lookupWithSecurity(ctx, actorUrl);
|
|
736
|
-
}
|
|
737
731
|
if (!remoteActor) {
|
|
738
732
|
return { ok: false, error: "Could not resolve remote actor" };
|
|
739
733
|
}
|
|
@@ -60,7 +60,8 @@ export function resolveController(mountPath, plugin) {
|
|
|
60
60
|
let object;
|
|
61
61
|
|
|
62
62
|
try {
|
|
63
|
-
|
|
63
|
+
// lookupWithSecurity handles signed→unsigned fallback automatically
|
|
64
|
+
object = await lookupWithSecurity(ctx, lookupInput, { documentLoader });
|
|
64
65
|
} catch (error) {
|
|
65
66
|
console.warn(
|
|
66
67
|
`[resolve] lookupObject failed for "${query}":`,
|
package/lib/lookup-helpers.js
CHANGED
|
@@ -14,14 +14,36 @@
|
|
|
14
14
|
* Using `crossOrigin: "ignore"` tells Fedify to silently discard objects
|
|
15
15
|
* whose id doesn't match the fetch origin, rather than throwing.
|
|
16
16
|
*
|
|
17
|
+
* When an authenticated document loader is provided (for Authorized Fetch
|
|
18
|
+
* compatibility), the lookup is tried with it first. If it fails (some
|
|
19
|
+
* servers like tags.pub return 400 for signed GETs), a fallback to the
|
|
20
|
+
* default unsigned loader is attempted automatically.
|
|
21
|
+
*
|
|
17
22
|
* @param {object} ctx - Fedify Context
|
|
18
23
|
* @param {string|URL} input - URL or handle to look up
|
|
19
24
|
* @param {object} [options] - Additional options passed to lookupObject
|
|
20
25
|
* @returns {Promise<object|null>} Resolved object or null
|
|
21
26
|
*/
|
|
22
|
-
export function lookupWithSecurity(ctx, input, options = {}) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
export async function lookupWithSecurity(ctx, input, options = {}) {
|
|
28
|
+
const baseOptions = { crossOrigin: "ignore", ...options };
|
|
29
|
+
|
|
30
|
+
let result = null;
|
|
31
|
+
try {
|
|
32
|
+
result = await ctx.lookupObject(input, baseOptions);
|
|
33
|
+
} catch {
|
|
34
|
+
// signed lookup threw — fall through to unsigned
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// If signed lookup failed and we used a custom documentLoader,
|
|
38
|
+
// retry without it (unsigned GET)
|
|
39
|
+
if (!result && options.documentLoader) {
|
|
40
|
+
try {
|
|
41
|
+
const { documentLoader: _, ...unsignedOptions } = baseOptions;
|
|
42
|
+
result = await ctx.lookupObject(input, unsignedOptions);
|
|
43
|
+
} catch {
|
|
44
|
+
// unsigned also failed — return null
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return result;
|
|
27
49
|
}
|
|
@@ -247,12 +247,17 @@ router.post("/api/v1/statuses", async (req, res, next) => {
|
|
|
247
247
|
});
|
|
248
248
|
};
|
|
249
249
|
|
|
250
|
+
// Process content: linkify URLs and extract @mentions
|
|
251
|
+
const rawContent = data.properties.content || { text: statusText || "", html: "" };
|
|
252
|
+
const processedContent = processStatusContent(rawContent, statusText || "");
|
|
253
|
+
const mentions = extractMentions(statusText || "");
|
|
254
|
+
|
|
250
255
|
const now = new Date().toISOString();
|
|
251
256
|
const timelineItem = await addTimelineItem(collections, {
|
|
252
257
|
uid: postUrl,
|
|
253
258
|
url: postUrl,
|
|
254
259
|
type: data.properties["post-type"] || "note",
|
|
255
|
-
content:
|
|
260
|
+
content: processedContent,
|
|
256
261
|
summary: spoilerText || "",
|
|
257
262
|
sensitive: sensitive === true || sensitive === "true",
|
|
258
263
|
visibility: visibility || "public",
|
|
@@ -274,7 +279,7 @@ router.post("/api/v1/statuses", async (req, res, next) => {
|
|
|
274
279
|
category: categories,
|
|
275
280
|
counts: { replies: 0, boosts: 0, likes: 0 },
|
|
276
281
|
linkPreviews: [],
|
|
277
|
-
mentions
|
|
282
|
+
mentions,
|
|
278
283
|
emojis: [],
|
|
279
284
|
});
|
|
280
285
|
|
|
@@ -636,4 +641,68 @@ async function loadItemInteractions(collections, item) {
|
|
|
636
641
|
return { favouritedIds, rebloggedIds, bookmarkedIds };
|
|
637
642
|
}
|
|
638
643
|
|
|
644
|
+
/**
|
|
645
|
+
* Process status content: linkify bare URLs and convert @mentions to links.
|
|
646
|
+
*
|
|
647
|
+
* Mastodon clients send plain text — the server is responsible for
|
|
648
|
+
* converting URLs and mentions into HTML links.
|
|
649
|
+
*
|
|
650
|
+
* @param {object} content - { text, html } from Micropub pipeline
|
|
651
|
+
* @param {string} rawText - Original status text from client
|
|
652
|
+
* @returns {object} { text, html } with linkified content
|
|
653
|
+
*/
|
|
654
|
+
function processStatusContent(content, rawText) {
|
|
655
|
+
let html = content.html || content.text || rawText || "";
|
|
656
|
+
|
|
657
|
+
// If the HTML is just plain text wrapped in <p>, process it
|
|
658
|
+
// Don't touch HTML that already has links (from Micropub rendering)
|
|
659
|
+
if (!html.includes("<a ")) {
|
|
660
|
+
// Linkify bare URLs (http/https)
|
|
661
|
+
html = html.replace(
|
|
662
|
+
/(https?:\/\/[^\s<>"')\]]+)/g,
|
|
663
|
+
'<a href="$1" rel="nofollow noopener noreferrer" target="_blank">$1</a>',
|
|
664
|
+
);
|
|
665
|
+
|
|
666
|
+
// Convert @user@domain mentions to profile links
|
|
667
|
+
html = html.replace(
|
|
668
|
+
/(?:^|\s)(@([a-zA-Z0-9_]+)@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,}))/g,
|
|
669
|
+
(match, full, username, domain) =>
|
|
670
|
+
match.replace(
|
|
671
|
+
full,
|
|
672
|
+
`<span class="h-card"><a href="https://${domain}/@${username}" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@${username}@${domain}</a></span>`,
|
|
673
|
+
),
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
return {
|
|
678
|
+
text: content.text || rawText || "",
|
|
679
|
+
html,
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Extract @user@domain mentions from text into mention objects.
|
|
685
|
+
*
|
|
686
|
+
* @param {string} text - Status text
|
|
687
|
+
* @returns {Array<{name: string, url: string}>} Mention objects
|
|
688
|
+
*/
|
|
689
|
+
function extractMentions(text) {
|
|
690
|
+
if (!text) return [];
|
|
691
|
+
const mentionRegex = /@([a-zA-Z0-9_]+)@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/g;
|
|
692
|
+
const mentions = [];
|
|
693
|
+
const seen = new Set();
|
|
694
|
+
let match;
|
|
695
|
+
while ((match = mentionRegex.exec(text)) !== null) {
|
|
696
|
+
const [, username, domain] = match;
|
|
697
|
+
const key = `${username}@${domain}`.toLowerCase();
|
|
698
|
+
if (seen.has(key)) continue;
|
|
699
|
+
seen.add(key);
|
|
700
|
+
mentions.push({
|
|
701
|
+
name: `@${username}@${domain}`,
|
|
702
|
+
url: `https://${domain}/@${username}`,
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
return mentions;
|
|
706
|
+
}
|
|
707
|
+
|
|
639
708
|
export default router;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmdes/indiekit-endpoint-activitypub",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.4",
|
|
4
4
|
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"indiekit",
|