@rmdes/indiekit-endpoint-posts 1.0.0-beta.32 → 1.0.0-beta.34

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.
@@ -10,7 +10,7 @@
10
10
  "editor-endpoint": application.mediaEndpoint,
11
11
  "editor-id": (properties.uid or ("new-" + postType)) + "-content",
12
12
  "editor-locale": application.locale,
13
- "editor-image-upload": "false" if postType == "note" or postType == "photo",
13
+ "editor-image-upload": true,
14
14
  "editor-status": "false" if not field.required
15
15
  }
16
16
  }
package/index.js CHANGED
@@ -5,6 +5,7 @@ import { ISO_6709_RE, isRequired } from "@indiekit/util";
5
5
  import express from "express";
6
6
 
7
7
  import { deleteController } from "./lib/controllers/delete.js";
8
+ import { editController } from "./lib/controllers/edit.js";
8
9
  import { purgeController } from "./lib/controllers/purge.js";
9
10
  import { formController } from "./lib/controllers/form.js";
10
11
  import { newController } from "./lib/controllers/new.js";
@@ -44,6 +45,8 @@ export default class PostsEndpoint {
44
45
  get routes() {
45
46
  router.get("/", postsController);
46
47
 
48
+ router.get("/edit", editController.get);
49
+
47
50
  router.get("/new", newController.get);
48
51
  router.post("/new", validate.new, newController.post);
49
52
 
@@ -0,0 +1,24 @@
1
+ import { getPostPropertiesByUrl } from "../utils.js";
2
+
3
+ export const editController = {
4
+ async get(request, response, next) {
5
+ try {
6
+ const { url } = request.query;
7
+ const { application } = request.app.locals;
8
+
9
+ if (!url) {
10
+ return response.redirect(request.baseUrl);
11
+ }
12
+
13
+ const properties = await getPostPropertiesByUrl(url, application);
14
+
15
+ if (!properties) {
16
+ return response.redirect(request.baseUrl);
17
+ }
18
+
19
+ response.redirect(`${request.baseUrl}/${properties.uid}/update`);
20
+ } catch (error) {
21
+ next(error);
22
+ }
23
+ },
24
+ };
package/lib/utils.js CHANGED
@@ -298,6 +298,34 @@ export const purgePost = async (uid, application) => {
298
298
  return result.deletedCount > 0;
299
299
  };
300
300
 
301
+ /**
302
+ * Query database for post data by Micropub URL
303
+ * @param {string} url - Micropub URL (e.g. https://example.com/articles/2026/02/13/slug)
304
+ * @param {object} application - Application object with collections
305
+ * @returns {Promise<object|false>} JF2 properties with uid, or false if not found
306
+ */
307
+ export const getPostPropertiesByUrl = async (url, application) => {
308
+ try {
309
+ const postsCollection = application?.collections?.get("posts");
310
+ if (!postsCollection) {
311
+ return false;
312
+ }
313
+
314
+ const postData = await postsCollection.findOne({ "properties.url": url });
315
+
316
+ if (!postData?.properties) {
317
+ return false;
318
+ }
319
+
320
+ return {
321
+ ...postData.properties,
322
+ uid: postData._id.toString(),
323
+ };
324
+ } catch {
325
+ return false;
326
+ }
327
+ };
328
+
301
329
  /**
302
330
  * Get post URL from ID
303
331
  * @param {string} id - ID
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-posts",
3
- "version": "1.0.0-beta.32",
3
+ "version": "1.0.0-beta.34",
4
4
  "description": "Post management endpoint for Indiekit with syndicate form fix. View posts published by your Micropub endpoint and publish new posts to it.",
5
5
  "keywords": [
6
6
  "indiekit",