Skip to content

Commit

Permalink
feat(endpoint-micropub): remove frontend interface
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jun 14, 2022
1 parent fdd3b33 commit 36a63a7
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 329 deletions.
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 2 additions & 12 deletions packages/endpoint-micropub/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from "express";
import multer from "multer";
import { actionController } from "./lib/controllers/action.js";
import { postsController } from "./lib/controllers/posts.js";
import { queryController } from "./lib/controllers/query.js";

const defaults = {
mountPath: "/micropub",
Expand All @@ -17,24 +17,14 @@ export const MicropubEndpoint = class {
this._router = express.Router(); // eslint-disable-line new-cap
}

navigationItems(application) {
if (application.hasDatabase) {
return {
href: this.options.mountPath,
text: "micropub.title",
};
}
}

get routes() {
const router = this._router;
const multipartParser = multer({
storage: multer.memoryStorage(),
});

router.get("/", postsController.posts);
router.get("/", queryController);
router.post("/", multipartParser.any(), actionController);
router.get("/:id", postsController.post);

return router;
}
Expand Down
116 changes: 0 additions & 116 deletions packages/endpoint-micropub/lib/controllers/posts.js

This file was deleted.

74 changes: 74 additions & 0 deletions packages/endpoint-micropub/lib/controllers/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import httpError from "http-errors";
import { getConfig, queryConfig } from "../config.js";
import { getMf2Properties, jf2ToMf2, url2Mf2 } from "../mf2.js";

/**
* Query previously published posts
*
* @param {object} request HTTP request
* @param {object} response HTTP response
* @param {Function} next Next middleware callback
* @returns {object} HTTP response
*/
export const queryController = async (request, response, next) => {
const { application, publication } = request.app.locals;

try {
if (!application.hasDatabase) {
throw new httpError.NotImplemented(
response.__("errors.noDatabase.content")
);
}

const config = getConfig(application, publication);

let { page, limit, offset } = request.query;
page = Number.parseInt(page, 10) || 1;
limit = Number.parseInt(limit, 10) || 40;
offset = Number.parseInt(offset, 10) || (page - 1) * limit;

const posts = await publication.posts
.find()
.sort({ _id: -1 })
.skip(offset)
.limit(limit)
.toArray();

let { filter, properties, q, url } = request.query;
if (!q) {
throw new httpError.BadRequest("Invalid query");
}

// `category` param is used to query `categories` configuration property
q = q === "category" ? "categories" : q;

switch (q) {
case "config":
return response.json(config);

case "source":
// Return mf2 for a given source URL
if (url) {
const mf2 = await url2Mf2(url);
return response.json(getMf2Properties(mf2, properties));
}

// Return mf2 for previously published posts
return response.json({
items: posts.map((post) => jf2ToMf2(post.properties)),
});

default:
// Query configuration value (can be filtered, limited and offset)
if (config[q]) {
return response.json({
[q]: queryConfig(config[q], { filter, limit, offset }),
});
}

throw new httpError.NotImplemented(`Unsupported parameter: ${q}`);
}
} catch (error) {
next(error);
}
};
10 changes: 0 additions & 10 deletions packages/endpoint-micropub/locales/de.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/endpoint-micropub/locales/en.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/endpoint-micropub/locales/es.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/endpoint-micropub/locales/fr.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/endpoint-micropub/locales/id.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/endpoint-micropub/locales/nl.json

This file was deleted.

10 changes: 0 additions & 10 deletions packages/endpoint-micropub/locales/pt.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/endpoint-micropub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"lodash": "^4.17.21",
"markdown-it": "^13.0.0",
"microformats-parser": "^1.4.0",
"mongodb": "^4.1.1",
"multer": "^1.4.5-lts",
"newbase60": "^1.3.1",
"turndown": "^7.1.1",
Expand Down
17 changes: 0 additions & 17 deletions packages/endpoint-micropub/tests/integration/200-posts-list.js

This file was deleted.

38 changes: 0 additions & 38 deletions packages/endpoint-micropub/tests/integration/200-posts-view.js

This file was deleted.

Loading

0 comments on commit 36a63a7

Please sign in to comment.