@rmdes/indiekit-endpoint-microsub 1.0.0-beta.9 → 1.0.1
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 +14 -0
- package/lib/cache/redis.js +53 -5
- package/lib/controllers/block.js +4 -3
- package/lib/controllers/channels.js +4 -3
- package/lib/controllers/events.js +2 -1
- package/lib/controllers/follow.js +27 -7
- package/lib/controllers/mute.js +4 -3
- package/lib/controllers/reader.js +141 -16
- package/lib/controllers/search.js +2 -1
- package/lib/controllers/timeline.js +12 -2
- package/lib/feeds/fetcher.js +118 -7
- package/lib/feeds/normalizer.js +62 -2
- package/lib/feeds/parser.js +12 -1
- package/lib/media/proxy.js +219 -0
- package/lib/polling/processor.js +30 -2
- package/lib/storage/channels.js +18 -2
- package/lib/storage/feeds.js +15 -2
- package/lib/storage/items.js +87 -29
- package/lib/utils/auth.js +36 -0
- package/lib/webmention/receiver.js +3 -1
- package/locales/en.json +6 -1
- package/package.json +4 -1
- package/views/compose.njk +10 -1
- package/views/settings.njk +14 -0
package/lib/storage/items.js
CHANGED
|
@@ -195,7 +195,7 @@ export async function getItemsByUids(application, uids, userId) {
|
|
|
195
195
|
* Mark items as read
|
|
196
196
|
* @param {object} application - Indiekit application
|
|
197
197
|
* @param {ObjectId|string} channelId - Channel ObjectId
|
|
198
|
-
* @param {Array} entryIds - Array of entry IDs to mark as read
|
|
198
|
+
* @param {Array} entryIds - Array of entry IDs to mark as read (can be ObjectId, uid, or URL)
|
|
199
199
|
* @param {string} userId - User ID
|
|
200
200
|
* @returns {Promise<number>} Number of items updated
|
|
201
201
|
*/
|
|
@@ -204,6 +204,12 @@ export async function markItemsRead(application, channelId, entryIds, userId) {
|
|
|
204
204
|
const channelObjectId =
|
|
205
205
|
typeof channelId === "string" ? new ObjectId(channelId) : channelId;
|
|
206
206
|
|
|
207
|
+
console.info(
|
|
208
|
+
`[Microsub] markItemsRead called for channel ${channelId}, entries:`,
|
|
209
|
+
entryIds,
|
|
210
|
+
`userId: ${userId}`,
|
|
211
|
+
);
|
|
212
|
+
|
|
207
213
|
// Handle "last-read-entry" special value
|
|
208
214
|
if (entryIds.includes("last-read-entry")) {
|
|
209
215
|
// Mark all items in channel as read
|
|
@@ -211,26 +217,39 @@ export async function markItemsRead(application, channelId, entryIds, userId) {
|
|
|
211
217
|
{ channelId: channelObjectId },
|
|
212
218
|
{ $addToSet: { readBy: userId } },
|
|
213
219
|
);
|
|
220
|
+
console.info(
|
|
221
|
+
`[Microsub] Marked all items as read: ${result.modifiedCount} updated`,
|
|
222
|
+
);
|
|
214
223
|
return result.modifiedCount;
|
|
215
224
|
}
|
|
216
225
|
|
|
217
226
|
// Convert string IDs to ObjectIds where possible
|
|
218
|
-
const objectIds = entryIds
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
227
|
+
const objectIds = entryIds
|
|
228
|
+
.map((id) => {
|
|
229
|
+
try {
|
|
230
|
+
return new ObjectId(id);
|
|
231
|
+
} catch {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
.filter(Boolean);
|
|
225
236
|
|
|
237
|
+
// Build query to match by _id, uid, or url (Microsub spec uses URLs as entry identifiers)
|
|
226
238
|
const result = await collection.updateMany(
|
|
227
239
|
{
|
|
228
240
|
channelId: channelObjectId,
|
|
229
|
-
$or: [
|
|
241
|
+
$or: [
|
|
242
|
+
...(objectIds.length > 0 ? [{ _id: { $in: objectIds } }] : []),
|
|
243
|
+
{ uid: { $in: entryIds } },
|
|
244
|
+
{ url: { $in: entryIds } },
|
|
245
|
+
],
|
|
230
246
|
},
|
|
231
247
|
{ $addToSet: { readBy: userId } },
|
|
232
248
|
);
|
|
233
249
|
|
|
250
|
+
console.info(
|
|
251
|
+
`[Microsub] markItemsRead result: ${result.modifiedCount} items updated`,
|
|
252
|
+
);
|
|
234
253
|
return result.modifiedCount;
|
|
235
254
|
}
|
|
236
255
|
|
|
@@ -238,7 +257,7 @@ export async function markItemsRead(application, channelId, entryIds, userId) {
|
|
|
238
257
|
* Mark items as unread
|
|
239
258
|
* @param {object} application - Indiekit application
|
|
240
259
|
* @param {ObjectId|string} channelId - Channel ObjectId
|
|
241
|
-
* @param {Array} entryIds - Array of entry IDs to mark as unread
|
|
260
|
+
* @param {Array} entryIds - Array of entry IDs to mark as unread (can be ObjectId, uid, or URL)
|
|
242
261
|
* @param {string} userId - User ID
|
|
243
262
|
* @returns {Promise<number>} Number of items updated
|
|
244
263
|
*/
|
|
@@ -252,18 +271,26 @@ export async function markItemsUnread(
|
|
|
252
271
|
const channelObjectId =
|
|
253
272
|
typeof channelId === "string" ? new ObjectId(channelId) : channelId;
|
|
254
273
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
274
|
+
// Convert string IDs to ObjectIds where possible
|
|
275
|
+
const objectIds = entryIds
|
|
276
|
+
.map((id) => {
|
|
277
|
+
try {
|
|
278
|
+
return new ObjectId(id);
|
|
279
|
+
} catch {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
.filter(Boolean);
|
|
262
284
|
|
|
285
|
+
// Match by _id, uid, or url
|
|
263
286
|
const result = await collection.updateMany(
|
|
264
287
|
{
|
|
265
288
|
channelId: channelObjectId,
|
|
266
|
-
$or: [
|
|
289
|
+
$or: [
|
|
290
|
+
...(objectIds.length > 0 ? [{ _id: { $in: objectIds } }] : []),
|
|
291
|
+
{ uid: { $in: entryIds } },
|
|
292
|
+
{ url: { $in: entryIds } },
|
|
293
|
+
],
|
|
267
294
|
},
|
|
268
295
|
{ $pull: { readBy: userId } },
|
|
269
296
|
);
|
|
@@ -275,7 +302,7 @@ export async function markItemsUnread(
|
|
|
275
302
|
* Remove items from channel
|
|
276
303
|
* @param {object} application - Indiekit application
|
|
277
304
|
* @param {ObjectId|string} channelId - Channel ObjectId
|
|
278
|
-
* @param {Array} entryIds - Array of entry IDs to remove
|
|
305
|
+
* @param {Array} entryIds - Array of entry IDs to remove (can be ObjectId, uid, or URL)
|
|
279
306
|
* @returns {Promise<number>} Number of items removed
|
|
280
307
|
*/
|
|
281
308
|
export async function removeItems(application, channelId, entryIds) {
|
|
@@ -283,17 +310,25 @@ export async function removeItems(application, channelId, entryIds) {
|
|
|
283
310
|
const channelObjectId =
|
|
284
311
|
typeof channelId === "string" ? new ObjectId(channelId) : channelId;
|
|
285
312
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
313
|
+
// Convert string IDs to ObjectIds where possible
|
|
314
|
+
const objectIds = entryIds
|
|
315
|
+
.map((id) => {
|
|
316
|
+
try {
|
|
317
|
+
return new ObjectId(id);
|
|
318
|
+
} catch {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
})
|
|
322
|
+
.filter(Boolean);
|
|
293
323
|
|
|
324
|
+
// Match by _id, uid, or url
|
|
294
325
|
const result = await collection.deleteMany({
|
|
295
326
|
channelId: channelObjectId,
|
|
296
|
-
$or: [
|
|
327
|
+
$or: [
|
|
328
|
+
...(objectIds.length > 0 ? [{ _id: { $in: objectIds } }] : []),
|
|
329
|
+
{ uid: { $in: entryIds } },
|
|
330
|
+
{ url: { $in: entryIds } },
|
|
331
|
+
],
|
|
297
332
|
});
|
|
298
333
|
|
|
299
334
|
return result.deletedCount;
|
|
@@ -411,11 +446,34 @@ export async function deleteItemsByAuthorUrl(application, userId, authorUrl) {
|
|
|
411
446
|
export async function createIndexes(application) {
|
|
412
447
|
const collection = getCollection(application);
|
|
413
448
|
|
|
449
|
+
// Primary query indexes
|
|
414
450
|
await collection.createIndex({ channelId: 1, published: -1 });
|
|
415
451
|
await collection.createIndex({ channelId: 1, uid: 1 }, { unique: true });
|
|
416
452
|
await collection.createIndex({ feedId: 1 });
|
|
453
|
+
|
|
454
|
+
// URL matching index for mark_read operations
|
|
455
|
+
await collection.createIndex({ channelId: 1, url: 1 });
|
|
456
|
+
|
|
457
|
+
// Full-text search index with weights
|
|
458
|
+
// Higher weight = more importance in relevance scoring
|
|
417
459
|
await collection.createIndex(
|
|
418
|
-
{
|
|
419
|
-
|
|
460
|
+
{
|
|
461
|
+
name: "text",
|
|
462
|
+
"content.text": "text",
|
|
463
|
+
"content.html": "text",
|
|
464
|
+
summary: "text",
|
|
465
|
+
"author.name": "text",
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
name: "text_search",
|
|
469
|
+
weights: {
|
|
470
|
+
name: 10, // Titles most important
|
|
471
|
+
summary: 5, // Summaries second
|
|
472
|
+
"content.text": 3, // Content third
|
|
473
|
+
"content.html": 2, // HTML content lower
|
|
474
|
+
"author.name": 1, // Author names lowest
|
|
475
|
+
},
|
|
476
|
+
default_language: "english",
|
|
477
|
+
},
|
|
420
478
|
);
|
|
421
479
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication utilities for Microsub
|
|
3
|
+
* @module utils/auth
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get the user ID from request context
|
|
8
|
+
*
|
|
9
|
+
* In Indiekit, the userId can come from:
|
|
10
|
+
* 1. request.session.userId (if explicitly set)
|
|
11
|
+
* 2. request.session.me (from token introspection)
|
|
12
|
+
* 3. application.publication.me (single-user fallback)
|
|
13
|
+
* @param {object} request - Express request
|
|
14
|
+
* @returns {string|undefined} User ID
|
|
15
|
+
*/
|
|
16
|
+
export function getUserId(request) {
|
|
17
|
+
// Check session for explicit userId
|
|
18
|
+
if (request.session?.userId) {
|
|
19
|
+
return request.session.userId;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Check session for me URL from token introspection
|
|
23
|
+
if (request.session?.me) {
|
|
24
|
+
return request.session.me;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Fall back to publication me URL (single-user mode)
|
|
28
|
+
const { application } = request.app.locals;
|
|
29
|
+
if (application?.publication?.me) {
|
|
30
|
+
return application.publication.me;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Final fallback: use "default" as user ID for single-user instances
|
|
34
|
+
// This ensures read state is tracked even without explicit user identity
|
|
35
|
+
return "default";
|
|
36
|
+
}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* @module webmention/receiver
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { getUserId } from "../utils/auth.js";
|
|
7
|
+
|
|
6
8
|
import { processWebmention } from "./processor.js";
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -33,7 +35,7 @@ export async function receive(request, response) {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
const { application } = request.app.locals;
|
|
36
|
-
const userId = request
|
|
38
|
+
const userId = getUserId(request);
|
|
37
39
|
|
|
38
40
|
// Return 202 Accepted immediately (processing asynchronously)
|
|
39
41
|
response.status(202).json({
|
package/locales/en.json
CHANGED
|
@@ -46,7 +46,8 @@
|
|
|
46
46
|
"cancel": "Cancel",
|
|
47
47
|
"replyTo": "Replying to",
|
|
48
48
|
"likeOf": "Liking",
|
|
49
|
-
"repostOf": "Reposting"
|
|
49
|
+
"repostOf": "Reposting",
|
|
50
|
+
"bookmarkOf": "Bookmarking"
|
|
50
51
|
},
|
|
51
52
|
"settings": {
|
|
52
53
|
"title": "{{channel}} settings",
|
|
@@ -55,6 +56,10 @@
|
|
|
55
56
|
"excludeRegex": "Exclude pattern",
|
|
56
57
|
"excludeRegexHelp": "Regular expression to filter out matching content",
|
|
57
58
|
"save": "Save settings",
|
|
59
|
+
"dangerZone": "Danger zone",
|
|
60
|
+
"deleteWarning": "Deleting this channel will permanently remove all feeds and items. This action cannot be undone.",
|
|
61
|
+
"deleteConfirm": "Are you sure you want to delete this channel and all its content?",
|
|
62
|
+
"delete": "Delete channel",
|
|
58
63
|
"types": {
|
|
59
64
|
"like": "Likes",
|
|
60
65
|
"repost": "Reposts",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmdes/indiekit-endpoint-microsub",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Microsub endpoint for Indiekit. Enables subscribing to feeds and reading content using the Microsub protocol.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"indiekit",
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
},
|
|
22
22
|
"type": "module",
|
|
23
23
|
"main": "index.js",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "node --test test/unit/*.js"
|
|
26
|
+
},
|
|
24
27
|
"files": [
|
|
25
28
|
"lib",
|
|
26
29
|
"locales",
|
package/views/compose.njk
CHANGED
|
@@ -24,6 +24,12 @@
|
|
|
24
24
|
</div>
|
|
25
25
|
{% endif %}
|
|
26
26
|
|
|
27
|
+
{% if bookmarkOf %}
|
|
28
|
+
<div class="compose__context">
|
|
29
|
+
{{ icon("bookmark") }} {{ __("microsub.compose.bookmarkOf") }}: <a href="{{ bookmarkOf }}">{{ bookmarkOf }}</a>
|
|
30
|
+
</div>
|
|
31
|
+
{% endif %}
|
|
32
|
+
|
|
27
33
|
<form method="post" action="{{ baseUrl }}/compose">
|
|
28
34
|
{% if replyTo %}
|
|
29
35
|
<input type="hidden" name="in-reply-to" value="{{ replyTo }}">
|
|
@@ -34,8 +40,11 @@
|
|
|
34
40
|
{% if repostOf %}
|
|
35
41
|
<input type="hidden" name="repost-of" value="{{ repostOf }}">
|
|
36
42
|
{% endif %}
|
|
43
|
+
{% if bookmarkOf %}
|
|
44
|
+
<input type="hidden" name="bookmark-of" value="{{ bookmarkOf }}">
|
|
45
|
+
{% endif %}
|
|
37
46
|
|
|
38
|
-
{% if not likeOf and not repostOf %}
|
|
47
|
+
{% if not likeOf and not repostOf and not bookmarkOf %}
|
|
39
48
|
{{ textarea({
|
|
40
49
|
label: __("microsub.compose.content"),
|
|
41
50
|
id: "content",
|
package/views/settings.njk
CHANGED
|
@@ -55,5 +55,19 @@
|
|
|
55
55
|
</a>
|
|
56
56
|
</div>
|
|
57
57
|
</form>
|
|
58
|
+
|
|
59
|
+
{% if channel.uid !== "notifications" %}
|
|
60
|
+
<hr class="divider">
|
|
61
|
+
<div class="danger-zone">
|
|
62
|
+
<h3>{{ __("microsub.settings.dangerZone") }}</h3>
|
|
63
|
+
<p class="hint">{{ __("microsub.settings.deleteWarning") }}</p>
|
|
64
|
+
<form method="post" action="{{ baseUrl }}/channels/{{ channel.uid }}/delete" onsubmit="return confirm('{{ __("microsub.settings.deleteConfirm") }}');">
|
|
65
|
+
{{ button({
|
|
66
|
+
text: __("microsub.settings.delete"),
|
|
67
|
+
classes: "button--danger"
|
|
68
|
+
}) }}
|
|
69
|
+
</form>
|
|
70
|
+
</div>
|
|
71
|
+
{% endif %}
|
|
58
72
|
</div>
|
|
59
73
|
{% endblock %}
|