Skip to content

Commit

Permalink
fix: update syndication endpoint params. fixes #567
Browse files Browse the repository at this point in the history
* `source_url` makes it clearer what this URL is
* `redirect_uri` is consistent with param used by IndieAuth
* nesting body properties under `syndication` prevents name collision
  • Loading branch information
paulrobertlloyd committed Jan 4, 2023
1 parent a9ebd41 commit f7fc748
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"redirect_uri",
"request_uri",
"response_type",
"source_url",
"success_description",
"token_type"
]
Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-posts/includes/endpoint-posts-syndicate.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
}) | indent(2) }}

{{ input({
name: "redirectUri",
name: "syndication[redirect_uri]",
type: "hidden",
value: redirectUri
}) | indent(2) }}

{{ button({
classes: "button--secondary button--small",
name: "url",
name: "syndication[source_url]",
value: post.url,
icon: "syndicate",
text: __("posts.post.syndicate")
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-syndicate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Add `@indiekit/endpoint-syndicate` to your list of plug-ins, specifying options
## Supported endpoint queries

- Access token (required): `/syndicate?token=XXXXXXX`
- URL to syndicate: `/syndicate?token=XXXXXXX&url=https%3A%2F%2Fwebsite.example%2Fposts%2F1`
- URL to syndicate: `/syndicate?token=XXXXXXX&source_url=https%3A%2F%2Fwebsite.example%2Fposts%2F1`
12 changes: 7 additions & 5 deletions packages/endpoint-syndicate/lib/controllers/syndicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export const syndicateController = {
try {
const { application, publication } = request.app.locals;
const token = request.query.token || request.body.token;
const url = request.query.url || request.body.url;
const redirectUri = request.query.redirectUri || request.body.redirectUri;
const sourceUrl =
request.query.source_url || request.body.syndication?.source_url;
const redirectUri =
request.query.redirect_uri || request.body.syndication?.redirect_uri;

if (!application.hasDatabase) {
throw IndiekitError.notImplemented(
Expand All @@ -26,12 +28,12 @@ export const syndicateController = {
}

// Get post data
const postData = await getPostData(publication, url);
const postData = await getPostData(publication, sourceUrl);

if (!postData && url) {
if (!postData && sourceUrl) {
return response.json({
success: "OK",
success_description: `No post record available for ${url}`,
success_description: `No post record available for ${sourceUrl}`,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test("Returns no post record for URL", async (t) => {
.post("/syndicate")
.auth(testToken(), { type: "bearer" })
.set("accept", "application/json")
.query({ url: "https://website.example/notes/foobar/" });
.query({ source_url: "https://website.example/notes/foobar/" });

t.is(result.status, 200);
t.is(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test("Syndicates a URL", async (t) => {
const result = await request
.post("/syndicate")
.set("accept", "application/json")
.query({ url: "https://website.example/notes/foobar/" })
.query({ source_url: "https://website.example/notes/foobar/" })
.query({ token: testToken() });

t.is(result.status, 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test("Syndicates a URL", async (t) => {
const result = await request
.post("/syndicate")
.set("accept", "application/json")
.query({ url: "https://website.example/notes/foobar/" })
.query({ source_url: "https://website.example/notes/foobar/" })
.query({ token: testToken() });

t.is(result.status, 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test("Syndicates a URL", async (t) => {
const result = await request
.post("/syndicate")
.set("accept", "application/json")
.query({ url: "https://website.example/notes/foobar/" })
.query({ source_url: "https://website.example/notes/foobar/" })
.query({ token: testToken() });

t.is(result.status, 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test("Returns 500 error syndicating URL", async (t) => {
const result = await request
.post("/syndicate")
.set("accept", "application/json")
.query({ url: "https://website.example/notes/foobar/" })
.query({ source_url: "https://website.example/notes/foobar/" })
.query({ token: testToken() });

t.is(result.status, 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ test("Syndicates a URL", async (t) => {
const result = await request
.post("/syndicate")
.set("accept", "application/json")
.send({ url: "https://website.example/notes/foobar/" })
.send({ redirectUri: "/posts/12345" })
.send({
syndication: {
url: "https://website.example/notes/foobar/",
redirect_uri: "/posts/12345",
},
})
.send({ token: testToken() });

t.is(result.status, 302);
Expand Down

0 comments on commit f7fc748

Please sign in to comment.