@rmdes/indiekit-endpoint-webmention-io 1.0.3 → 1.0.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.
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { getBlocklist, unblockDomain } from "../storage/blocklist.js";
|
|
6
6
|
import { unhideByDomain } from "../storage/webmentions.js";
|
|
7
|
+
import { ensureISOString } from "../utils.js";
|
|
7
8
|
|
|
8
9
|
export const blocklistController = {
|
|
9
10
|
/**
|
|
@@ -19,7 +20,10 @@ export const blocklistController = {
|
|
|
19
20
|
if (db) {
|
|
20
21
|
const collection = db.collection("webmentionBlocklist");
|
|
21
22
|
const raw = await getBlocklist(collection);
|
|
22
|
-
entries = raw
|
|
23
|
+
entries = raw.map((entry) => ({
|
|
24
|
+
...entry,
|
|
25
|
+
blockedAt: ensureISOString(entry.blockedAt),
|
|
26
|
+
}));
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
response.render("webmentions-blocklist", {
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "../storage/webmentions.js";
|
|
14
14
|
import { blockDomain } from "../storage/blocklist.js";
|
|
15
15
|
import { getSyncState } from "../sync.js";
|
|
16
|
-
import { getMentionType, getMentionTitle, getAuthorName } from "../utils.js";
|
|
16
|
+
import { getMentionType, getMentionTitle, getAuthorName, ensureISOString } from "../utils.js";
|
|
17
17
|
|
|
18
18
|
export const dashboardController = {
|
|
19
19
|
/**
|
|
@@ -82,7 +82,7 @@ export const dashboardController = {
|
|
|
82
82
|
locale: application.locale,
|
|
83
83
|
title: getMentionTitle({ name: item.name, "wm-property": item.wmProperty }),
|
|
84
84
|
description: html ? { html } : undefined,
|
|
85
|
-
published: item.published || item.wmReceived,
|
|
85
|
+
published: ensureISOString(item.published) || ensureISOString(item.wmReceived),
|
|
86
86
|
url: item.sourceUrl,
|
|
87
87
|
user: {
|
|
88
88
|
avatar: { src: item.authorPhoto },
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Webmentions MongoDB storage
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { extractDomain, sanitiseHtml } from "../utils.js";
|
|
5
|
+
import { extractDomain, ensureISOString, sanitiseHtml } from "../utils.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Ensure indexes exist
|
|
@@ -36,7 +36,7 @@ export function jf2ToDocument(item) {
|
|
|
36
36
|
|
|
37
37
|
return {
|
|
38
38
|
wmId: item["wm-id"],
|
|
39
|
-
wmReceived: item["wm-received"] || new Date().toISOString(),
|
|
39
|
+
wmReceived: ensureISOString(item["wm-received"]) || new Date().toISOString(),
|
|
40
40
|
wmProperty: item["wm-property"],
|
|
41
41
|
wmTarget: item["wm-target"],
|
|
42
42
|
authorName: item.author?.name || null,
|
|
@@ -44,7 +44,7 @@ export function jf2ToDocument(item) {
|
|
|
44
44
|
authorPhoto: item.author?.photo || null,
|
|
45
45
|
sourceUrl: item.url || null,
|
|
46
46
|
sourceDomain: extractDomain(item.author?.url || item.url || ""),
|
|
47
|
-
published: item.published
|
|
47
|
+
published: ensureISOString(item.published),
|
|
48
48
|
contentHtml,
|
|
49
49
|
contentText,
|
|
50
50
|
name: item.name || null,
|
|
@@ -65,7 +65,7 @@ export function documentToJf2(doc) {
|
|
|
65
65
|
const jf2 = {
|
|
66
66
|
type: "entry",
|
|
67
67
|
"wm-id": doc.wmId,
|
|
68
|
-
"wm-received": doc.wmReceived,
|
|
68
|
+
"wm-received": ensureISOString(doc.wmReceived),
|
|
69
69
|
"wm-property": doc.wmProperty,
|
|
70
70
|
"wm-target": doc.wmTarget,
|
|
71
71
|
author: {
|
|
@@ -75,7 +75,7 @@ export function documentToJf2(doc) {
|
|
|
75
75
|
photo: doc.authorPhoto || "",
|
|
76
76
|
},
|
|
77
77
|
url: doc.sourceUrl || "",
|
|
78
|
-
published: doc.published || doc.wmReceived,
|
|
78
|
+
published: ensureISOString(doc.published) || ensureISOString(doc.wmReceived),
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
if (doc.name) {
|
package/lib/utils.js
CHANGED
|
@@ -101,6 +101,21 @@ export const sanitiseHtml = (html) => {
|
|
|
101
101
|
return html;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Ensure a value is an ISO 8601 date string.
|
|
106
|
+
* MongoDB may auto-convert ISO strings to Date objects (BSON Date).
|
|
107
|
+
* The Nunjucks `| date` filter calls `parseISO(string)` which crashes
|
|
108
|
+
* on Date objects with `dateString.split is not a function`.
|
|
109
|
+
* @param {*} value - Date object, ISO string, or null
|
|
110
|
+
* @returns {string|null} ISO string or null
|
|
111
|
+
*/
|
|
112
|
+
export const ensureISOString = (value) => {
|
|
113
|
+
if (!value) return null;
|
|
114
|
+
if (value instanceof Date) return value.toISOString();
|
|
115
|
+
if (typeof value === "string") return value;
|
|
116
|
+
return null;
|
|
117
|
+
};
|
|
118
|
+
|
|
104
119
|
/**
|
|
105
120
|
* Extract domain from a URL string
|
|
106
121
|
* @param {string} url - URL
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmdes/indiekit-endpoint-webmention-io",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Webmention moderation endpoint for Indiekit. Syncs webmentions from webmention.io into MongoDB with delete, block, and privacy removal capabilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"indiekit",
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
</span>
|
|
159
159
|
</td>
|
|
160
160
|
<td>{{ entry.mentionsHidden or 0 }}</td>
|
|
161
|
-
<td>{{ entry.blockedAt | date("PPp") }}</td>
|
|
161
|
+
<td>{% if entry.blockedAt %}{{ entry.blockedAt | date("PPp") }}{% endif %}</td>
|
|
162
162
|
<td>
|
|
163
163
|
<form method="post" action="{{ wmEndpoint }}/blocklist/{{ entry.domain | urlencode }}/delete" style="display:inline">
|
|
164
164
|
<button type="submit" class="button button--small button--secondary"
|