@commonpub/layer 0.15.4 → 0.15.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonpub/layer",
3
- "version": "0.15.4",
3
+ "version": "0.15.5",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "files": [
@@ -56,9 +56,9 @@
56
56
  "@commonpub/docs": "0.6.2",
57
57
  "@commonpub/config": "0.10.0",
58
58
  "@commonpub/auth": "0.5.1",
59
+ "@commonpub/editor": "0.7.9",
59
60
  "@commonpub/protocol": "0.9.9",
60
61
  "@commonpub/learning": "0.5.0",
61
- "@commonpub/editor": "0.7.9",
62
62
  "@commonpub/ui": "0.8.5"
63
63
  },
64
64
  "devDependencies": {
@@ -4,9 +4,13 @@ import { hubPosts, users } from '@commonpub/schema';
4
4
  import { eq } from 'drizzle-orm';
5
5
 
6
6
  /**
7
- * Hub post AP Note endpoint.
8
- * Serves the Note JSON-LD when requested with AP Accept header.
9
- * Remote instances dereference this URI when processing Announce activities.
7
+ * Middleware: serve ActivityPub Note JSON-LD for hub post URIs.
8
+ *
9
+ * Matches /hubs/{slug}/posts/{postId} with AP Accept headers.
10
+ * Non-AP requests pass through to the Nuxt page renderer.
11
+ *
12
+ * This MUST be a middleware (not a server route) because a server route
13
+ * returning undefined sends HTTP 204, which prevents the Nuxt page from rendering.
10
14
  */
11
15
  export default defineEventHandler(async (event) => {
12
16
  const accept = getRequestHeader(event, 'accept') ?? '';
@@ -16,13 +20,15 @@ export default defineEventHandler(async (event) => {
16
20
 
17
21
  if (!isAPRequest) return;
18
22
 
23
+ const path = getRequestURL(event).pathname;
24
+ const match = path.match(/^\/hubs\/([a-z0-9][a-z0-9_-]*)\/posts\/([a-zA-Z0-9_-]+)$/);
25
+ if (!match) return;
26
+
19
27
  const config = useConfig();
20
28
  if (!config.features.federation || !config.features.federateHubs) return;
21
29
 
22
- const slug = getRouterParam(event, 'slug');
23
- const postId = getRouterParam(event, 'postId');
24
- if (!slug || !postId) return;
25
-
30
+ const slug = match[1]!;
31
+ const postId = match[2]!;
26
32
  const db = useDB();
27
33
  const domain = config.instance.domain;
28
34
 
@@ -51,7 +57,6 @@ export default defineEventHandler(async (event) => {
51
57
 
52
58
  setResponseHeader(event, 'content-type', 'application/activity+json');
53
59
 
54
- // Build Note content — share posts need special handling
55
60
  let noteContent = escapeHtmlForAP(post.content);
56
61
  const ext: Record<string, unknown> = {};
57
62