-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(endpoint-micropub): remove frontend interface
- Loading branch information
1 parent
fdd3b33
commit 36a63a7
Showing
18 changed files
with
76 additions
and
329 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
packages/endpoint-micropub/tests/integration/200-posts-list.js
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
packages/endpoint-micropub/tests/integration/200-posts-view.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.