Skip to content

Commit

Permalink
fix(endpoint-micropub): fetch references for form-encoded requests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Nov 12, 2023
1 parent c3bbd6c commit a3ad0fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions indiekit.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const config = {
publication: {
me: process.env.PUBLICATION_URL,
categories: ["internet", "indieweb", "indiekit", "test", "testing"],
enrichPostData: true,
},
"@indiekit/store-github": {
user: process.env.GITHUB_USER,
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-micropub/lib/controllers/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const actionController = async (request, response, next) => {
// Create and normalise JF2 data
jf2 = request.is("json")
? await mf2ToJf2(body, publication.enrichPostData)
: formEncodedToJf2(body);
: await formEncodedToJf2(body, publication.enrichPostData);

// Attach files
jf2 = files
Expand Down
10 changes: 8 additions & 2 deletions packages/endpoint-micropub/lib/jf2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getDate, randomString, slugify } from "@indiekit/util";
import { mf2tojf2, mf2tojf2referenced } from "@paulrobertlloyd/mf2tojf2";
import { fetchReferences } from "@paulrobertlloyd/mf2tojf2/lib/fetch-references.js";
import { markdownToHtml, htmlToMarkdown } from "./markdown.js";
import { reservedProperties } from "./reserved-properties.js";
import {
Expand All @@ -12,9 +13,10 @@ import {
/**
* Create JF2 object from form-encoded request
* @param {object} body - Form-encoded request body
* @returns {object} Micropub action
* @param {boolean} requestReferences - Request data for any referenced URLs
* @returns {Promise<object>} Micropub action
*/
export const formEncodedToJf2 = (body) => {
export const formEncodedToJf2 = async (body, requestReferences) => {
const jf2 = {
type: body.h || "entry",
};
Expand All @@ -37,6 +39,10 @@ export const formEncodedToJf2 = (body) => {
}
}

if (requestReferences) {
return fetchReferences(jf2);
}

return jf2;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-micropub/tests/unit/jf2.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ test.beforeEach((t) => {
};
});

test("Creates JF2 object from form-encoded request", (t) => {
const result = formEncodedToJf2({
test("Creates JF2 object from form-encoded request", async (t) => {
const result = await formEncodedToJf2({
h: "entry",
content: "I+ate+a+cheese+sandwich,+which+was+nice.",
category: ["foo", "bar"],
Expand Down

0 comments on commit a3ad0fa

Please sign in to comment.