@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.
- package/dist/{app--uxnaIRV.js → app-B3P2N2vM.js} +1346 -310
- package/dist/client/.vite/manifest.json +2 -2
- package/dist/client/_assets/{client-auth-begiT1tq.js → client-auth-CeGBe0qG.js} +1 -1
- package/dist/client/_assets/{client-BT6kpcuG.js → client-nByuF0Ct.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/node.js +2 -2
- package/package.json +1 -1
- package/src/__tests__/helpers/cursor-walk.ts +37 -7
- package/src/app.tsx +4 -0
- package/src/lib/__tests__/discover.test.ts +24 -0
- package/src/lib/__tests__/thread-fold.test.ts +43 -0
- package/src/lib/api-posts.ts +110 -2
- package/src/lib/api-public-posts.ts +263 -0
- package/src/lib/api-threads.ts +207 -0
- package/src/lib/discover.ts +34 -0
- package/src/lib/thread-fold.ts +83 -41
- package/src/lib/thread-query.ts +143 -0
- package/src/middleware/cors.ts +8 -1
- package/src/middleware/deprecation.ts +48 -0
- package/src/routes/api/__tests__/mcp.test.ts +143 -0
- package/src/routes/api/__tests__/posts.test.ts +78 -0
- package/src/routes/api/__tests__/public-access.test.ts +5 -0
- package/src/routes/api/__tests__/search.test.ts +104 -0
- package/src/routes/api/__tests__/threads.test.ts +115 -0
- package/src/routes/api/posts.ts +15 -104
- package/src/routes/api/public/__tests__/threads.test.ts +363 -0
- package/src/routes/api/public/archive.ts +82 -81
- package/src/routes/api/public/posts.ts +97 -298
- package/src/routes/api/public/threads.ts +141 -0
- package/src/routes/api/search.ts +31 -2
- package/src/routes/api/threads.ts +128 -0
- package/src/routes/auth/__tests__/setup-discover.test.ts +29 -1
- package/src/routes/auth/__tests__/setup-page.test.tsx +59 -1
- package/src/routes/auth/setup.tsx +48 -9
- package/src/routes/pages/__tests__/search.test.ts +58 -0
- package/src/routes/pages/search.tsx +3 -1
- package/src/services/__tests__/search.test.ts +211 -0
- package/src/services/__tests__/thread.test.ts +495 -0
- package/src/services/index.ts +4 -0
- package/src/services/mcp.ts +217 -57
- package/src/services/post.ts +222 -43
- package/src/services/search.ts +77 -66
- package/src/services/thread.ts +392 -0
- package/src/types/constants.ts +25 -0
- package/src/ui/feed/ThreadPreview.tsx +9 -14
- package/src/ui/feed/__tests__/thread-preview.test.ts +18 -22
- 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 {
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
ctx
|
|
70
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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,
|
|
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 {
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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 [
|
|
353
|
-
|
|
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
|
});
|