@rmdes/indiekit-endpoint-rss 1.2.0 → 1.2.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.
@@ -207,7 +207,10 @@ export async function resetPublishState(db, id) {
207
207
 
208
208
  const result = await db.collection("rssItems").updateMany(
209
209
  { feedId },
210
- { $unset: { postedAt: "", postUrl: "", postSkipped: "", postError: "", postErrorAt: "", postAttempts: "" } },
210
+ // postUrl is kept on purpose: it tells the publisher the post already
211
+ // exists, so the next attempt updates it instead of issuing a create the
212
+ // file store would silently ignore.
213
+ { $unset: { postedAt: "", postSkipped: "", postError: "", postErrorAt: "", postAttempts: "" } },
211
214
  );
212
215
 
213
216
  return { status: 200, reset: result.modifiedCount };
package/lib/publisher.js CHANGED
@@ -41,10 +41,18 @@ export async function postToMicropub(
41
41
  micropubEndpoint,
42
42
  accessToken,
43
43
  properties,
44
- { fetchImpl = fetch } = {},
44
+ { fetchImpl = fetch, replaces } = {},
45
45
  ) {
46
46
  const mf2 = jf2ToMf2({ properties: { ...properties } });
47
47
 
48
+ // A post that already exists must be updated, not created again. The file
49
+ // system store's createFile returns silently when the path exists, so a
50
+ // second create updates the database row and leaves the published file
51
+ // untouched — the two then disagree with nothing to show for it.
52
+ const body = replaces
53
+ ? { action: "update", url: replaces, replace: mf2.properties }
54
+ : mf2;
55
+
48
56
  const response = await fetchImpl(micropubEndpoint, {
49
57
  method: "POST",
50
58
  headers: {
@@ -52,7 +60,7 @@ export async function postToMicropub(
52
60
  authorization: `Bearer ${accessToken}`,
53
61
  "content-type": "application/json",
54
62
  },
55
- body: JSON.stringify(mf2),
63
+ body: JSON.stringify(body),
56
64
  });
57
65
 
58
66
  if (!response.ok) {
@@ -196,7 +204,10 @@ export async function publishPending(feed, itemsCollection, options) {
196
204
  // of the batch would be marked postSkipped and lost for good.
197
205
  const token = mintImpl(me);
198
206
  const properties = buildJf2(item, feed.publish);
199
- const postUrl = await postImpl(micropubEndpoint, token, properties);
207
+ const postUrl =
208
+ (await postImpl(micropubEndpoint, token, properties, {
209
+ replaces: item.postUrl,
210
+ })) || item.postUrl;
200
211
 
201
212
  await itemsCollection.updateOne(
202
213
  { _id: item._id },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-rss",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "RSS feed reader endpoint for Indiekit. Aggregates multiple feeds, caches in MongoDB, displays on frontend.",
5
5
  "keywords": [
6
6
  "indiekit",