@jant/core 0.8.1 → 0.9.1

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.
Files changed (47) hide show
  1. package/dist/{app--uxnaIRV.js → app-B3P2N2vM.js} +1346 -310
  2. package/dist/client/.vite/manifest.json +2 -2
  3. package/dist/client/_assets/{client-auth-begiT1tq.js → client-auth-CeGBe0qG.js} +1 -1
  4. package/dist/client/_assets/{client-BT6kpcuG.js → client-nByuF0Ct.js} +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/node.js +2 -2
  7. package/package.json +1 -1
  8. package/src/__tests__/helpers/cursor-walk.ts +37 -7
  9. package/src/app.tsx +4 -0
  10. package/src/lib/__tests__/discover.test.ts +24 -0
  11. package/src/lib/__tests__/thread-fold.test.ts +43 -0
  12. package/src/lib/api-posts.ts +110 -2
  13. package/src/lib/api-public-posts.ts +263 -0
  14. package/src/lib/api-threads.ts +207 -0
  15. package/src/lib/discover.ts +34 -0
  16. package/src/lib/thread-fold.ts +83 -41
  17. package/src/lib/thread-query.ts +143 -0
  18. package/src/middleware/cors.ts +8 -1
  19. package/src/middleware/deprecation.ts +48 -0
  20. package/src/routes/api/__tests__/mcp.test.ts +143 -0
  21. package/src/routes/api/__tests__/posts.test.ts +78 -0
  22. package/src/routes/api/__tests__/public-access.test.ts +5 -0
  23. package/src/routes/api/__tests__/search.test.ts +104 -0
  24. package/src/routes/api/__tests__/threads.test.ts +115 -0
  25. package/src/routes/api/posts.ts +15 -104
  26. package/src/routes/api/public/__tests__/threads.test.ts +363 -0
  27. package/src/routes/api/public/archive.ts +82 -81
  28. package/src/routes/api/public/posts.ts +97 -298
  29. package/src/routes/api/public/threads.ts +141 -0
  30. package/src/routes/api/search.ts +31 -2
  31. package/src/routes/api/threads.ts +128 -0
  32. package/src/routes/auth/__tests__/setup-discover.test.ts +29 -1
  33. package/src/routes/auth/__tests__/setup-page.test.tsx +59 -1
  34. package/src/routes/auth/setup.tsx +48 -9
  35. package/src/routes/pages/__tests__/search.test.ts +58 -0
  36. package/src/routes/pages/search.tsx +3 -1
  37. package/src/services/__tests__/search.test.ts +211 -0
  38. package/src/services/__tests__/thread.test.ts +495 -0
  39. package/src/services/index.ts +4 -0
  40. package/src/services/mcp.ts +217 -57
  41. package/src/services/post.ts +222 -43
  42. package/src/services/search.ts +77 -66
  43. package/src/services/thread.ts +392 -0
  44. package/src/types/constants.ts +25 -0
  45. package/src/ui/feed/ThreadPreview.tsx +9 -14
  46. package/src/ui/feed/__tests__/thread-preview.test.ts +18 -22
  47. package/src/ui/feed/thread-preview-state.ts +0 -35
@@ -13,8 +13,12 @@ import {
13
13
  toPostFilters,
14
14
  } from "../../../lib/filter-dimensions.js";
15
15
  import { ValidationError } from "../../../lib/errors.js";
16
- import { toPublicPost } from "./posts.js";
16
+ import { loadPublicPostResponses } from "../../../lib/api-public-posts.js";
17
17
  import { requirePublicApiEnabled } from "../../../middleware/public-content-access.js";
18
+ import {
19
+ deprecated,
20
+ THREAD_LIST_DEPRECATED_AT,
21
+ } from "../../../middleware/deprecation.js";
18
22
 
19
23
  type Env = { Bindings: Bindings; Variables: AppVariables };
20
24
 
@@ -45,90 +49,87 @@ const INVALID_VISIBILITY_MESSAGE =
45
49
  value === "latest_hidden" ? "hidden" : value,
46
50
  ).join(", ");
47
51
 
48
- publicArchiveApiRoutes.get("/", async (c) => {
49
- const { lang, cursor, limit, content } = parseValidated(
50
- ListPublicArchiveQuerySchema,
51
- c.req.query(),
52
- );
53
-
54
- const read = (key: string): string | undefined => c.req.query(key);
52
+ /**
53
+ * Deprecated in 0.9 for `GET /api/public/threads?visibility=any&sort=published`,
54
+ * which takes the same filters. Answers as it always has until 1.0.1 removes it.
55
+ */
56
+ publicArchiveApiRoutes.get(
57
+ "/",
58
+ deprecated(
59
+ THREAD_LIST_DEPRECATED_AT,
60
+ "/api/public/threads?visibility=any&sort=published",
61
+ ),
62
+ async (c) => {
63
+ const { lang, cursor, limit, content } = parseValidated(
64
+ ListPublicArchiveQuerySchema,
65
+ c.req.query(),
66
+ );
55
67
 
56
- // Resolving a collection slug costs a round trip, so it is paid for only when
57
- // the caller named one.
58
- const slugs = readCollectionSlugs(read);
59
- const ctx: DimensionContext = {
60
- collections:
61
- slugs.length > 0
62
- ? buildCollectionVocabulary(await c.var.services.collections.list())
63
- : EMPTY_COLLECTION_VOCABULARY,
64
- };
68
+ const read = (key: string): string | undefined => c.req.query(key);
65
69
 
66
- const parsed = parsePostFilterSelectionStrict(
67
- read,
68
- Object.keys(c.req.query()),
69
- ctx,
70
- { allow: ENDPOINT_PARAMS },
71
- );
70
+ // Resolving a collection slug costs a round trip, so it is paid for only when
71
+ // the caller named one.
72
+ const slugs = readCollectionSlugs(read);
73
+ const ctx: DimensionContext = {
74
+ collections:
75
+ slugs.length > 0
76
+ ? buildCollectionVocabulary(await c.var.services.collections.list())
77
+ : EMPTY_COLLECTION_VOCABULARY,
78
+ };
72
79
 
73
- // A collection slug that names nothing is answered as an empty result rather
74
- // than a rejection: the caller's words were understood, and this site simply
75
- // holds no such collection.
76
- if (
77
- !parsed.ok &&
78
- parsed.issues.every((issue) => issue.param === "collection")
79
- ) {
80
- return c.json({ posts: [], nextCursor: null });
81
- }
82
- if (!parsed.ok) {
83
- const first = parsed.issues[0];
84
- throw new ValidationError(first?.message ?? "Validation failed");
85
- }
80
+ const parsed = parsePostFilterSelectionStrict(
81
+ read,
82
+ Object.keys(c.req.query()),
83
+ ctx,
84
+ { allow: ENDPOINT_PARAMS },
85
+ );
86
86
 
87
- // `private` names a set no anonymous caller may see. Rejected rather than
88
- // dropped: silently widening the result to the whole archive would answer a
89
- // different question under the caller's own words.
90
- const visibility = parsed.selection.visibility;
91
- if (
92
- visibility !== undefined &&
93
- !(PUBLIC_ARCHIVE_VISIBILITIES as readonly string[]).includes(visibility)
94
- ) {
95
- throw new ValidationError(INVALID_VISIBILITY_MESSAGE);
96
- }
87
+ // A collection slug that names nothing is answered as an empty result rather
88
+ // than a rejection: the caller's words were understood, and this site simply
89
+ // holds no such collection.
90
+ if (
91
+ !parsed.ok &&
92
+ parsed.issues.every((issue) => issue.param === "collection")
93
+ ) {
94
+ return c.json({ posts: [], nextCursor: null });
95
+ }
96
+ if (!parsed.ok) {
97
+ const first = parsed.issues[0];
98
+ throw new ValidationError(first?.message ?? "Validation failed");
99
+ }
97
100
 
98
- const { posts, nextCursor } = await c.var.services.posts.listPage(
99
- {
100
- lang,
101
- status: "published",
102
- excludePrivate: true,
103
- excludeLatestHidden: false,
104
- excludeReplies: true,
105
- // Newest-published-first, the page's default order. Named explicitly:
106
- // left unset, a published list sorts by activity, and a reply would
107
- // lift an old root to the top. The year filter reads the same column,
108
- // and so does the cursor.
109
- ...toPostFilters(parsed.selection, { yearAxis: "published" }),
110
- sortBy: "published",
111
- ignorePinnedSort: true,
112
- },
113
- { cursor, limit },
114
- );
101
+ // `private` names a set no anonymous caller may see. Rejected rather than
102
+ // dropped: silently widening the result to the whole archive would answer a
103
+ // different question under the caller's own words.
104
+ const visibility = parsed.selection.visibility;
105
+ if (
106
+ visibility !== undefined &&
107
+ !(PUBLIC_ARCHIVE_VISIBILITIES as readonly string[]).includes(visibility)
108
+ ) {
109
+ throw new ValidationError(INVALID_VISIBILITY_MESSAGE);
110
+ }
115
111
 
116
- const postIds = posts.map((post) => post.id);
117
- const [mediaMap, collectionsMap] = await Promise.all([
118
- c.var.services.media.getByPostIds(postIds),
119
- c.var.services.collections.getCollectionsByPostIds(postIds),
120
- ]);
112
+ const { posts, nextCursor } = await c.var.services.posts.listPage(
113
+ {
114
+ lang,
115
+ status: "published",
116
+ excludePrivate: true,
117
+ excludeLatestHidden: false,
118
+ excludeReplies: true,
119
+ // Newest-published-first, the page's default order. Named explicitly:
120
+ // left unset, a published list sorts by activity, and a reply would
121
+ // lift an old root to the top. The year filter reads the same column,
122
+ // and so does the cursor.
123
+ ...toPostFilters(parsed.selection, { yearAxis: "published" }),
124
+ sortBy: "published",
125
+ ignorePinnedSort: true,
126
+ },
127
+ { cursor, limit },
128
+ );
121
129
 
122
- return c.json({
123
- posts: posts.map((post) =>
124
- toPublicPost(
125
- post,
126
- mediaMap.get(post.id) ?? [],
127
- collectionsMap.get(post.id) ?? [],
128
- c.var.appConfig,
129
- { content },
130
- ),
131
- ),
132
- nextCursor,
133
- });
134
- });
130
+ return c.json({
131
+ posts: await loadPublicPostResponses(c.var, posts, { content }),
132
+ nextCursor,
133
+ });
134
+ },
135
+ );
@@ -1,8 +1,7 @@
1
1
  import { Hono } from "hono";
2
2
  import { z } from "zod";
3
- import type { Bindings, Collection, Media, Post } from "../../../types.js";
3
+ import type { Bindings, Post } from "../../../types.js";
4
4
  import type { AppVariables } from "../../../types/app-context.js";
5
- import { getCollectionPagePath } from "../../../lib/collection-paths.js";
6
5
  import {
7
6
  CollectionSortOrderSchema,
8
7
  ContentLanguageSchema,
@@ -10,19 +9,16 @@ import {
10
9
  parseValidated,
11
10
  } from "../../../lib/schemas.js";
12
11
  import { NotFoundError } from "../../../lib/errors.js";
13
- import { toApiAttachment } from "../../../lib/api-posts.js";
14
- import { tiptapJsonToMarkdown } from "../../../lib/tiptap-to-markdown.js";
15
- import { toPublicPath } from "../../../lib/url.js";
16
- import {
17
- getImageUrl,
18
- getMediaUrl,
19
- getPublicUrlForProvider,
20
- } from "../../../lib/image.js";
12
+ import { loadPublicPostResponses } from "../../../lib/api-public-posts.js";
21
13
  import {
22
14
  resolveCollectionSortOrder,
23
15
  supportsCollectionRatingSort,
24
16
  } from "../../../lib/collection-sort.js";
25
17
  import { requirePublicApiEnabled } from "../../../middleware/public-content-access.js";
18
+ import {
19
+ deprecated,
20
+ THREAD_LIST_DEPRECATED_AT,
21
+ } from "../../../middleware/deprecation.js";
26
22
 
27
23
  type Env = { Bindings: Bindings; Variables: AppVariables };
28
24
 
@@ -48,85 +44,6 @@ const PublicPostContentQuerySchema = z.object({
48
44
  content: z.enum(["markdown"]).optional(),
49
45
  });
50
46
 
51
- export type PublicPostBaseResponse = {
52
- id: string;
53
- format: Post["format"];
54
- status: "published";
55
- visibility: Post["visibility"];
56
- slug: string;
57
- permalink: string;
58
- title?: string | null;
59
- url?: string | null;
60
- sourceName?: string | null;
61
- sourceUrl?: string | null;
62
- quoteText: string | null;
63
- summary: string | null;
64
- rating: number | null;
65
- previewKind: string | null;
66
- previewProvider: string | null;
67
- previewImageUrl: string | null;
68
- replyToId: string | null;
69
- threadId: string;
70
- /**
71
- * BCP 47 content language, or null on a post written before the site
72
- * enabled multilingual content.
73
- */
74
- language: string | null;
75
- /**
76
- * Shared by every translation of this Thread. Null when the Thread has no
77
- * translations.
78
- */
79
- translationGroupId: string | null;
80
- /** Reply published without announcing its Thread. Always false on roots. */
81
- quietReply: boolean;
82
- pinnedAt: number | null;
83
- featuredAt: number | null;
84
- publishedAt: number | null;
85
- /** Root only: newest post in the Thread, quiet replies excluded. */
86
- lastActivityAt: number;
87
- /** Root only: newest post in the Thread, quiet replies included. */
88
- threadUpdatedAt: number;
89
- createdAt: number;
90
- updatedAt: number;
91
- attachments: ReturnType<typeof toApiAttachment>[];
92
- collections: {
93
- id: string;
94
- slug: string;
95
- title: string;
96
- url: string;
97
- }[];
98
- };
99
-
100
- export type PublicPostRenderedResponse = PublicPostBaseResponse & {
101
- bodyHtml: string | null;
102
- bodyText: string | null;
103
- };
104
-
105
- export type PublicPostMarkdownResponse = PublicPostBaseResponse & {
106
- bodyMarkdown: string | null;
107
- };
108
-
109
- export type PublicPostResponse =
110
- PublicPostRenderedResponse | PublicPostMarkdownResponse;
111
-
112
- /**
113
- * The public Markdown for a post, or null for a historical body that isn't
114
- * TipTap JSON. One unreadable row answers null and is logged, rather than
115
- * failing the whole listing; `bodyHtml` still falls back to stored HTML.
116
- */
117
- function toPublicBodyMarkdown(postId: string, body: string): string | null {
118
- try {
119
- return tiptapJsonToMarkdown(body);
120
- } catch (error) {
121
- // eslint-disable-next-line no-console -- A skipped body must leave a trace
122
- console.error(
123
- `Couldn't convert the body of post ${postId} to Markdown`,
124
- error,
125
- );
126
- return null;
127
- }
128
- }
129
-
130
47
  function isPublicDetailVisible(post: Post | null): post is Post {
131
48
  return (
132
49
  post !== null &&
@@ -135,207 +52,97 @@ function isPublicDetailVisible(post: Post | null): post is Post {
135
52
  );
136
53
  }
137
54
 
138
- export function toPublicPost(
139
- post: Post,
140
- mediaList: Media[],
141
- threadCollections: Collection[],
142
- appConfig: AppVariables["appConfig"],
143
- options?: { content?: "markdown" },
144
- ): PublicPostResponse {
145
- const {
146
- r2PublicUrl,
147
- imageTransformUrl,
148
- s3PublicUrl,
149
- localPublicUrl,
150
- sitePathPrefix,
151
- storageDriver,
152
- } = appConfig;
153
-
154
- const previewImagePublicUrl = getPublicUrlForProvider(
155
- storageDriver,
156
- r2PublicUrl,
157
- s3PublicUrl,
158
- localPublicUrl,
159
- );
160
- const previewImageUrl = post.previewImageKey
161
- ? getImageUrl(
162
- getMediaUrl(
163
- post.previewImageKey,
164
- previewImagePublicUrl,
165
- sitePathPrefix,
166
- ),
167
- imageTransformUrl,
168
- { width: 1280, quality: 80, format: "auto", fit: "scale-down" },
169
- )
170
- : null;
171
-
172
- const base = {
173
- id: post.id,
174
- format: post.format,
175
- status: "published" as const,
176
- visibility: post.visibility,
177
- slug: post.slug,
178
- permalink: toPublicPath(`/${post.slug}`, sitePathPrefix),
179
- quoteText: post.quoteText,
180
- summary: post.summary,
181
- rating: post.rating,
182
- previewKind: post.previewKind,
183
- previewProvider: post.previewProvider,
184
- previewImageUrl,
185
- replyToId: post.replyToId,
186
- threadId: post.threadId,
187
- language: post.language,
188
- translationGroupId: post.translationGroupId,
189
- quietReply: post.quietReply,
190
- pinnedAt: post.pinnedAt,
191
- featuredAt: post.featuredAt,
192
- publishedAt: post.publishedAt,
193
- lastActivityAt: post.lastActivityAt,
194
- threadUpdatedAt: post.threadUpdatedAt,
195
- createdAt: post.createdAt,
196
- updatedAt: post.updatedAt,
197
- attachments: mediaList.map((media) =>
198
- toApiAttachment(
199
- media,
200
- r2PublicUrl,
201
- imageTransformUrl,
202
- s3PublicUrl,
203
- localPublicUrl,
204
- sitePathPrefix,
205
- ),
206
- ),
207
- collections: threadCollections.map((collection) => ({
208
- id: collection.id,
209
- slug: collection.slug,
210
- title: collection.title,
211
- url: toPublicPath(getCollectionPagePath(collection.slug), sitePathPrefix),
212
- })),
213
- };
214
- const contentFields =
215
- options?.content === "markdown"
216
- ? {
217
- bodyMarkdown: post.body
218
- ? toPublicBodyMarkdown(post.id, post.body)
219
- : null,
220
- }
221
- : {
222
- bodyHtml: post.bodyHtml,
223
- bodyText: post.bodyText,
224
- };
225
-
226
- if (post.format === "quote") {
227
- return {
228
- ...base,
229
- ...contentFields,
230
- sourceName: post.title,
231
- sourceUrl: post.url,
232
- };
233
- }
234
-
235
- return {
236
- ...base,
237
- ...contentFields,
238
- title: post.title,
239
- url: post.url,
240
- };
241
- }
242
-
243
- publicPostsApiRoutes.get("/", async (c) => {
244
- const { format, lang, collection, sort, cursor, limit, content } =
245
- parseValidated(ListPublicPostsQuerySchema, c.req.query());
246
-
247
- // Resolve collection slug(s) — accepts comma-separated (e.g. "tech,art")
248
- // or "+" separated (e.g. "tech+art"), matching the page URL convention.
249
- let collectionIds: string[] | undefined;
250
- let sortOrder: "newest" | "oldest" | "rating_desc" | undefined;
251
-
252
- if (collection) {
253
- // Normalize: commas → "+" so resolveSelection handles both forms
254
- const slugExpression = collection.replace(/,/g, "+");
255
- const selection =
256
- await c.var.services.collections.resolveSelection(slugExpression);
257
- if (!selection) {
258
- return c.json({ posts: [], nextCursor: null });
259
- }
260
-
261
- collectionIds = selection.collections.map((col) => col.id);
262
-
263
- // Determine sort order: single collection uses its configured default,
264
- // aggregate selections default to "newest"
265
- const isAggregate = selection.collections.length > 1;
266
- const primaryCollection = selection.collections[0];
267
- if (!primaryCollection) {
268
- return c.json({ posts: [], nextCursor: null });
269
- }
270
- const requestedDefaultSort = isAggregate
271
- ? "newest"
272
- : primaryCollection.sortOrder;
273
-
274
- const ratedThreadCount =
275
- await c.var.services.posts.countCollectionThreadRootsUpToForCollections(
276
- collectionIds,
277
- {
278
- status: "published",
279
- excludePrivate: true,
280
- excludeLatestHidden: true,
281
- rootFormat: format,
282
- hasRating: true,
283
- },
284
- 2,
285
- );
286
- const showRatingSort = supportsCollectionRatingSort(ratedThreadCount);
287
- const defaultSort = resolveCollectionSortOrder(
288
- undefined,
289
- requestedDefaultSort,
290
- showRatingSort,
291
- );
292
- sortOrder = resolveCollectionSortOrder(sort, defaultSort, showRatingSort);
293
- }
294
-
295
- const { posts, nextCursor } = collectionIds
296
- ? await c.var.services.posts.listCollectionThreadRootPage(
297
- collectionIds,
298
- {
299
- status: "published",
300
- excludePrivate: true,
301
- excludeLatestHidden: true,
302
- rootFormat: format,
303
- lang,
304
- sortOrder,
305
- },
306
- { cursor, limit },
307
- )
308
- : await c.var.services.posts.listPage(
309
- {
310
- format,
311
- lang,
312
- status: "published",
313
- excludePrivate: true,
314
- excludeLatestHidden: true,
315
- excludeReplies: true,
316
- },
317
- { cursor, limit },
55
+ /**
56
+ * Deprecated in 0.9 for `GET /api/public/threads`, which lists the same Thread
57
+ * roots with the archive's filters and the homepage's defaults. Answers as it
58
+ * always has until 1.0.1 removes it.
59
+ */
60
+ publicPostsApiRoutes.get(
61
+ "/",
62
+ deprecated(THREAD_LIST_DEPRECATED_AT, "/api/public/threads"),
63
+ async (c) => {
64
+ const { format, lang, collection, sort, cursor, limit, content } =
65
+ parseValidated(ListPublicPostsQuerySchema, c.req.query());
66
+
67
+ // Resolve collection slug(s) — accepts comma-separated (e.g. "tech,art")
68
+ // or "+" separated (e.g. "tech+art"), matching the page URL convention.
69
+ let collectionIds: string[] | undefined;
70
+ let sortOrder: "newest" | "oldest" | "rating_desc" | undefined;
71
+
72
+ if (collection) {
73
+ // Normalize: commas → "+" so resolveSelection handles both forms
74
+ const slugExpression = collection.replace(/,/g, "+");
75
+ const selection =
76
+ await c.var.services.collections.resolveSelection(slugExpression);
77
+ if (!selection) {
78
+ return c.json({ posts: [], nextCursor: null });
79
+ }
80
+
81
+ collectionIds = selection.collections.map((col) => col.id);
82
+
83
+ // Determine sort order: single collection uses its configured default,
84
+ // aggregate selections default to "newest"
85
+ const isAggregate = selection.collections.length > 1;
86
+ const primaryCollection = selection.collections[0];
87
+ if (!primaryCollection) {
88
+ return c.json({ posts: [], nextCursor: null });
89
+ }
90
+ const requestedDefaultSort = isAggregate
91
+ ? "newest"
92
+ : primaryCollection.sortOrder;
93
+
94
+ const ratedThreadCount =
95
+ await c.var.services.posts.countCollectionThreadRootsUpToForCollections(
96
+ collectionIds,
97
+ {
98
+ status: "published",
99
+ excludePrivate: true,
100
+ excludeLatestHidden: true,
101
+ rootFormat: format,
102
+ hasRating: true,
103
+ },
104
+ 2,
105
+ );
106
+ const showRatingSort = supportsCollectionRatingSort(ratedThreadCount);
107
+ const defaultSort = resolveCollectionSortOrder(
108
+ undefined,
109
+ requestedDefaultSort,
110
+ showRatingSort,
318
111
  );
112
+ sortOrder = resolveCollectionSortOrder(sort, defaultSort, showRatingSort);
113
+ }
319
114
 
320
- const postIds = posts.map((post) => post.id);
321
- const [mediaMap, collectionsMap] = await Promise.all([
322
- c.var.services.media.getByPostIds(postIds),
323
- c.var.services.collections.getCollectionsByPostIds(postIds),
324
- ]);
325
-
326
- return c.json({
327
- posts: posts.map((post) =>
328
- toPublicPost(
329
- post,
330
- mediaMap.get(post.id) ?? [],
331
- collectionsMap.get(post.id) ?? [],
332
- c.var.appConfig,
333
- { content },
334
- ),
335
- ),
336
- nextCursor,
337
- });
338
- });
115
+ const { posts, nextCursor } = collectionIds
116
+ ? await c.var.services.posts.listCollectionThreadRootPage(
117
+ collectionIds,
118
+ {
119
+ status: "published",
120
+ excludePrivate: true,
121
+ excludeLatestHidden: true,
122
+ rootFormat: format,
123
+ lang,
124
+ sortOrder,
125
+ },
126
+ { cursor, limit },
127
+ )
128
+ : await c.var.services.posts.listPage(
129
+ {
130
+ format,
131
+ lang,
132
+ status: "published",
133
+ excludePrivate: true,
134
+ excludeLatestHidden: true,
135
+ excludeReplies: true,
136
+ },
137
+ { cursor, limit },
138
+ );
139
+
140
+ return c.json({
141
+ posts: await loadPublicPostResponses(c.var, posts, { content }),
142
+ nextCursor,
143
+ });
144
+ },
145
+ );
339
146
 
340
147
  publicPostsApiRoutes.get("/:slug", async (c) => {
341
148
  const { content } = parseValidated(
@@ -349,14 +156,6 @@ publicPostsApiRoutes.get("/:slug", async (c) => {
349
156
  throw new NotFoundError("Post");
350
157
  }
351
158
 
352
- const [mediaList, threadCollections] = await Promise.all([
353
- c.var.services.media.getByPostId(post.id),
354
- c.var.services.collections.getCollectionsByPostId(post.id),
355
- ]);
356
-
357
- return c.json(
358
- toPublicPost(post, mediaList, threadCollections, c.var.appConfig, {
359
- content,
360
- }),
361
- );
159
+ const [response] = await loadPublicPostResponses(c.var, [post], { content });
160
+ return c.json(response);
362
161
  });