@jant/core 1.1.0 → 1.3.0

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 (196) hide show
  1. package/bin/commands/site/import.js +2 -1
  2. package/bin/lib/site-snapshot.js +10 -0
  3. package/dist/{app-CKQ9PqAr.js → app-C8dETvgL.js} +9267 -5697
  4. package/dist/client/.vite/manifest.json +82 -93
  5. package/dist/client/_assets/chunks/{confirm-CMe01lne.js → confirm-BQebcuNB.js} +1 -1
  6. package/dist/client/_assets/chunks/{create-editor-BQkrw8Ax.js → create-editor-B8KuszlS.js} +38 -38
  7. package/dist/client/_assets/chunks/footnote-rail-DUrqz0Py.js +2 -0
  8. package/dist/client/_assets/chunks/{jant-locale-picker-2L4rkDaz.js → jant-locale-picker-CLq0iKDH.js} +1 -1
  9. package/dist/client/_assets/chunks/lit-BN4mrI3j.js +2 -0
  10. package/dist/client/_assets/chunks/{settings-paths-B0bNUaih.js → settings-paths-_fry4yWW.js} +1 -1
  11. package/dist/client/_assets/chunks/{slug-format-CYmQE5ln.js → slug-format-bcJ2ozr4.js} +1 -1
  12. package/dist/client/_assets/chunks/sortable-list-Bz2Na2E9.js +2 -0
  13. package/dist/client/_assets/chunks/types-DrYFqJH2.js +1 -0
  14. package/dist/client/_assets/chunks/{unsafe-html-CWos3v6N.js → unsafe-html-OJ9m154w.js} +1 -1
  15. package/dist/client/_assets/chunks/unsafe-svg-DVJ4NPcb.js +1 -0
  16. package/dist/client/_assets/client-CoNHvipV.css +2 -0
  17. package/dist/client/_assets/{client-auth-CG55rWb5.js → client-auth-CbnZkLJ6.js} +99 -129
  18. package/dist/client/_assets/{client-author-CGVvrNZ8.css → client-author-2WYBkgni.css} +1 -1
  19. package/dist/client/_assets/client-compose-DYtDlYm-.js +2008 -0
  20. package/dist/client/_assets/{client-manage-DnYdQAhf.js → client-manage-BODyYP5Z.js} +157 -157
  21. package/dist/client/_assets/client-pq6sVS7y.js +354 -0
  22. package/dist/client/_assets/{client-settings-CHgsIqXJ.js → client-settings-DDpe_tXJ.js} +166 -166
  23. package/dist/client/_assets/client-share-B9OsXx9p.js +149 -0
  24. package/dist/{constants-DEgyqWDl.js → constants-C2CdWAqt.js} +55 -5
  25. package/dist/index.js +1 -1
  26. package/dist/node.js +3 -2
  27. package/package.json +2 -1
  28. package/src/app.tsx +9 -0
  29. package/src/client/components/compose-types.ts +6 -1
  30. package/src/client/components/jant-compose-dialog.ts +26 -4
  31. package/src/client/components/jant-compose-editor.ts +30 -0
  32. package/src/client/components/jant-compose-fullscreen.ts +1 -0
  33. package/src/client/components/jant-media-lightbox.ts +18 -3
  34. package/src/client/components/jant-nav-manager.ts +2 -0
  35. package/src/client/components/jant-post-menu.ts +42 -89
  36. package/src/client/components/nav-manager-types.ts +2 -0
  37. package/src/client/components/settings-types.ts +1 -1
  38. package/src/client/compose-bridge.ts +61 -1
  39. package/src/client/feed-video-player.ts +6 -0
  40. package/src/client/list-views.ts +382 -0
  41. package/src/client/media-lightbox-events.ts +12 -0
  42. package/src/client/runtime-paths.ts +12 -0
  43. package/src/client/share-capture.ts +63 -0
  44. package/src/client/share-launch.ts +36 -9
  45. package/src/client/tiptap/bubble-menu.ts +25 -2
  46. package/src/client/tiptap/create-editor.ts +6 -0
  47. package/src/client/tiptap/embed-node.ts +3 -1
  48. package/src/client/tiptap/extensions.ts +4 -0
  49. package/src/client/tiptap/html-block-node.ts +3 -1
  50. package/src/client/tiptap/image-node.ts +3 -1
  51. package/src/client/video-processor.ts +106 -52
  52. package/src/client/view-confirm.ts +136 -0
  53. package/src/client.ts +2 -0
  54. package/src/db/migrations/0035_brainy_next_avengers.sql +9 -0
  55. package/src/db/migrations/0036_gorgeous_smasher.sql +7 -0
  56. package/src/db/migrations/0037_round_post.sql +16 -0
  57. package/src/db/migrations/0038_flashy_changeling.sql +15 -0
  58. package/src/db/migrations/0039_mixed_sister_grimm.sql +1 -0
  59. package/src/db/migrations/meta/0035_snapshot.json +2877 -0
  60. package/src/db/migrations/meta/0036_snapshot.json +2924 -0
  61. package/src/db/migrations/meta/0037_snapshot.json +2932 -0
  62. package/src/db/migrations/meta/0038_snapshot.json +2924 -0
  63. package/src/db/migrations/meta/0039_snapshot.json +2931 -0
  64. package/src/db/migrations/meta/_journal.json +35 -0
  65. package/src/db/migrations/pg/0033_cute_magdalene.sql +10 -0
  66. package/src/db/migrations/pg/0034_material_agent_brand.sql +8 -0
  67. package/src/db/migrations/pg/0035_flimsy_outlaw_kid.sql +3 -0
  68. package/src/db/migrations/pg/0036_milky_wolverine.sql +5 -0
  69. package/src/db/migrations/pg/0037_fuzzy_hammerhead.sql +1 -0
  70. package/src/db/migrations/pg/meta/0033_snapshot.json +3719 -0
  71. package/src/db/migrations/pg/meta/0034_snapshot.json +3766 -0
  72. package/src/db/migrations/pg/meta/0035_snapshot.json +3773 -0
  73. package/src/db/migrations/pg/meta/0036_snapshot.json +3766 -0
  74. package/src/db/migrations/pg/meta/0037_snapshot.json +3772 -0
  75. package/src/db/migrations/pg/meta/_journal.json +35 -0
  76. package/src/db/pg/schema.ts +41 -0
  77. package/src/db/post-visibility.ts +37 -6
  78. package/src/db/schema.ts +64 -0
  79. package/src/i18n/locales/glossary.zh-Hans.yml +4 -0
  80. package/src/i18n/locales/glossary.zh-Hant.yml +4 -0
  81. package/src/i18n/locales/public/en.po +26 -7
  82. package/src/i18n/locales/public/en.ts +1 -1
  83. package/src/i18n/locales/public/zh-Hans.po +25 -6
  84. package/src/i18n/locales/public/zh-Hans.ts +1 -1
  85. package/src/i18n/locales/public/zh-Hant.po +25 -6
  86. package/src/i18n/locales/public/zh-Hant.ts +1 -1
  87. package/src/i18n/locales/settings/en.po +159 -0
  88. package/src/i18n/locales/settings/en.ts +1 -1
  89. package/src/i18n/locales/settings/zh-Hans.po +159 -0
  90. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  91. package/src/i18n/locales/settings/zh-Hant.po +159 -0
  92. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  93. package/src/lib/api-public-posts.ts +10 -0
  94. package/src/lib/env.ts +20 -0
  95. package/src/lib/feed-policy.ts +2 -2
  96. package/src/lib/filter-dimensions.ts +11 -4
  97. package/src/lib/github-app-state.ts +1 -1
  98. package/src/lib/github-app.ts +183 -1
  99. package/src/lib/hugo-markdown.ts +7 -0
  100. package/src/lib/icons.ts +2 -0
  101. package/src/lib/link-preview.ts +499 -0
  102. package/src/lib/list-views.ts +117 -0
  103. package/src/lib/markdown-manager.ts +169 -2
  104. package/src/lib/navigation.ts +1 -1
  105. package/src/lib/post-meta.ts +13 -3
  106. package/src/lib/referrer-aliases.ts +311 -0
  107. package/src/lib/render.tsx +10 -0
  108. package/src/lib/resolve-config.ts +14 -0
  109. package/src/lib/share-card.ts +4 -3
  110. package/src/lib/summary.ts +152 -54
  111. package/src/lib/thread-query.ts +6 -2
  112. package/src/lib/timeline.ts +12 -11
  113. package/src/lib/tiptap-render.ts +1 -0
  114. package/src/lib/upload.ts +21 -1
  115. package/src/lib/url-fetch.ts +291 -74
  116. package/src/lib/video-playback.ts +55 -0
  117. package/src/lib/view-buffer.ts +201 -0
  118. package/src/lib/view-counting.ts +540 -0
  119. package/src/lib/view-token.ts +199 -0
  120. package/src/lib/view.ts +30 -1
  121. package/src/middleware/view-counter.ts +145 -0
  122. package/src/node/runtime.ts +4 -0
  123. package/src/preset.css +36 -17
  124. package/src/routes/api/media.ts +21 -3
  125. package/src/routes/api/search.ts +1 -1
  126. package/src/routes/dash/settings.tsx +434 -169
  127. package/src/routes/feed/sitemap.ts +1 -1
  128. package/src/routes/pages/archive.tsx +26 -19
  129. package/src/routes/pages/collection.tsx +9 -3
  130. package/src/routes/pages/collections.tsx +1 -0
  131. package/src/routes/pages/featured.tsx +1 -0
  132. package/src/routes/pages/home.tsx +1 -0
  133. package/src/routes/pages/page.tsx +18 -3
  134. package/src/routes/pages/search.tsx +3 -3
  135. package/src/routes/pages/smart-collection.tsx +2 -0
  136. package/src/routes/pages/subscribe.tsx +1 -0
  137. package/src/routes/view-confirm.ts +71 -0
  138. package/src/services/collection.ts +1 -1
  139. package/src/services/export-theme/assets/client-site.js +19 -19
  140. package/src/services/export-theme/layouts/archive/list.html +4 -2
  141. package/src/services/export-theme/layouts/partials/collection-members.html +4 -3
  142. package/src/services/export-theme/layouts/partials/featured-members.html +3 -3
  143. package/src/services/export-theme/layouts/partials/head.html +2 -0
  144. package/src/services/export-theme/layouts/partials/latest-members.html +4 -4
  145. package/src/services/export-theme/layouts/partials/post-card.html +1 -9
  146. package/src/services/export-theme/layouts/partials/reply.html +1 -9
  147. package/src/services/export-theme/layouts/partials/smart-collection-members.html +4 -3
  148. package/src/services/export-theme/layouts/post/list.html +1 -9
  149. package/src/services/export-theme/styles/main.css +41 -47
  150. package/src/services/export.ts +12 -3
  151. package/src/services/index.ts +17 -0
  152. package/src/services/mcp.ts +36 -6
  153. package/src/services/media.ts +63 -0
  154. package/src/services/navigation.ts +9 -4
  155. package/src/services/post.ts +102 -112
  156. package/src/services/search.ts +22 -7
  157. package/src/services/smart-collection.ts +3 -3
  158. package/src/services/stats.ts +1137 -0
  159. package/src/services/thread.ts +6 -2
  160. package/src/styles/components-author.css +242 -3
  161. package/src/styles/components.css +11 -3
  162. package/src/styles/tokens.css +89 -55
  163. package/src/styles/ui-author.css +140 -353
  164. package/src/styles/ui.css +90 -45
  165. package/src/types/app-context.ts +9 -0
  166. package/src/types/bindings.ts +5 -0
  167. package/src/types/config.ts +54 -0
  168. package/src/types/constants.ts +68 -4
  169. package/src/types/entities.ts +1 -0
  170. package/src/types/views.ts +8 -0
  171. package/src/ui/compose/ComposeDialog.tsx +26 -1
  172. package/src/ui/dash/StatusBadge.tsx +11 -0
  173. package/src/ui/dash/appearance/FontThemeContent.tsx +1 -1
  174. package/src/ui/dash/appearance/NavigationContent.tsx +8 -0
  175. package/src/ui/dash/settings/SettingsRootContent.tsx +24 -6
  176. package/src/ui/dash/settings/StatsContent.tsx +855 -0
  177. package/src/ui/feed/LinkCard.tsx +19 -2
  178. package/src/ui/feed/PostStatusBadges.tsx +19 -3
  179. package/src/ui/feed/TimelineFeed.tsx +3 -0
  180. package/src/ui/font-themes.ts +56 -6
  181. package/src/ui/layouts/BaseLayout.tsx +4 -2
  182. package/src/ui/layouts/SiteLayout.tsx +8 -3
  183. package/src/ui/pages/ArchivePage.tsx +1 -0
  184. package/src/ui/shared/MediaGallery.tsx +19 -3
  185. package/src/ui/shared/PostFooter.tsx +1 -22
  186. package/src/ui/shared/custom-icons.ts +5 -5
  187. package/dist/client/_assets/chunks/footnote-rail-B08scyhW.js +0 -2
  188. package/dist/client/_assets/chunks/lit-Bw_voPoW.js +0 -2
  189. package/dist/client/_assets/chunks/runtime-paths-y0_gHowM.js +0 -1
  190. package/dist/client/_assets/chunks/sortable-list-t11Ma1Ek.js +0 -2
  191. package/dist/client/_assets/chunks/types-D5iF3H1a.js +0 -1
  192. package/dist/client/_assets/chunks/unsafe-svg-DZl-yjas.js +0 -1
  193. package/dist/client/_assets/client-B0-s9sqx.css +0 -2
  194. package/dist/client/_assets/client-Dp46QSht.js +0 -354
  195. package/dist/client/_assets/client-compose-DkUTuavR.js +0 -2004
  196. package/dist/client/_assets/client-share-C59mOLJ1.js +0 -149
@@ -73,6 +73,7 @@ import type { StorageDriver } from "../lib/storage.js";
73
73
  import type { MediaService } from "./media.js";
74
74
  import {
75
75
  FORMATS,
76
+ isListedForReader,
76
77
  MAX_MEDIA_ATTACHMENTS,
77
78
  STATUSES,
78
79
  VISIBILITIES,
@@ -105,9 +106,9 @@ import { getOrBuildEntry } from "../i18n/supported-locales.js";
105
106
  import { suggestPostLanguage } from "../lib/lang-detect.js";
106
107
  import { createPathService, type PathService } from "./path.js";
107
108
  import {
108
- extractYouTubeVideoId,
109
- getYouTubeThumbnailUrls,
110
- } from "../lib/youtube.js";
109
+ resolveLinkPreview,
110
+ type LinkPreviewImage,
111
+ } from "../lib/link-preview.js";
111
112
  import { getPreviewStorageKey } from "../lib/upload.js";
112
113
  import { generateRandomId } from "../lib/nanoid.js";
113
114
  import { resolveSummaryConfig } from "../lib/resolve-config.js";
@@ -163,8 +164,8 @@ export interface PostFilters {
163
164
  excludeReplies?: boolean;
164
165
  /** Exclude posts hidden from Latest from results */
165
166
  excludeLatestHidden?: boolean;
166
- /** Exclude private posts from results */
167
- excludePrivate?: boolean;
167
+ /** Keep only what a signed-out reader may list: no Unlisted, no Private. */
168
+ listedForReader?: boolean;
168
169
  threadId?: string;
169
170
  /**
170
171
  * Restrict to these Posts. The list becomes one `IN (…)`, so a caller keeps
@@ -262,7 +263,7 @@ export interface SummaryConfig {
262
263
 
263
264
  export interface ThreadRootPageOptions {
264
265
  status?: Status;
265
- excludePrivate?: boolean;
266
+ listedForReader?: boolean;
266
267
  excludeLatestHidden?: boolean;
267
268
  /** See `PostFilters.lang`. */
268
269
  lang?: string;
@@ -864,7 +865,7 @@ export interface PostService {
864
865
  * ```ts
865
866
  * const first = await posts.listCollectionThreadRootPage(
866
867
  * [collection.id],
867
- * { status: "published", excludePrivate: true, sortOrder: "newest" },
868
+ * { status: "published", listedForReader: true, sortOrder: "newest" },
868
869
  * { limit: 20 },
869
870
  * );
870
871
  * ```
@@ -1043,7 +1044,7 @@ function ensurePostVisibility(
1043
1044
  return ensureAllowedPostValue(
1044
1045
  value,
1045
1046
  VISIBILITIES,
1046
- "Visibility must be public, hidden from Latest, or private.",
1047
+ "Visibility must be public, hidden from Latest, unlisted, or private.",
1047
1048
  ErrorCtor,
1048
1049
  );
1049
1050
  }
@@ -1377,83 +1378,92 @@ export function createPostService(
1377
1378
  }
1378
1379
 
1379
1380
  /**
1380
- * Fetch a link preview thumbnail and store it.
1381
- * Silently returns without updating if the URL is not a recognized provider
1382
- * or if the fetch fails.
1381
+ * Resolve a Link post's preview from its URL and store it, replacing the
1382
+ * preview it had: the video thumbnail (with its kind and provider) and the
1383
+ * site's icon. Called when a post is created and when its URL or format
1384
+ * changes; any other format ends up with no preview.
1385
+ *
1386
+ * The page is fetched before anything changes, the new fields land in one
1387
+ * write, and only then are the old files deleted, so a failure at any step
1388
+ * leaves the post with one complete preview or none. Best-effort throughout:
1389
+ * a page that can't be read leaves the post without a preview, never
1390
+ * without the save.
1383
1391
  */
1384
- async function resolveAndStorePreview(
1385
- postId: string,
1386
- format: string,
1387
- url: string | null | undefined,
1392
+ async function refreshLinkPreview(
1393
+ post: Pick<
1394
+ Post,
1395
+ "id" | "format" | "url" | "previewImageKey" | "previewIconKey"
1396
+ >,
1388
1397
  storage: StorageDriver | null | undefined,
1389
1398
  ): Promise<void> {
1390
- if (!storage || format !== "link" || !url) return;
1391
-
1392
- const videoId = extractYouTubeVideoId(url);
1393
- if (!videoId) return;
1394
-
1395
- const thumbnailUrls = getYouTubeThumbnailUrls(videoId);
1396
- let imageBytes: Uint8Array | null = null;
1397
- let contentType = "image/jpeg";
1398
-
1399
- for (const thumbUrl of thumbnailUrls) {
1400
- try {
1401
- const response = await fetch(thumbUrl);
1402
- if (response.ok) {
1403
- const ct = response.headers.get("content-type");
1404
- // YouTube returns a grey placeholder (120×90) when maxresdefault
1405
- // is not available. Detect it by checking content-length.
1406
- const cl = response.headers.get("content-length");
1407
- if (cl && parseInt(cl, 10) < 5000) {
1408
- // Too small — likely a placeholder, try next quality
1409
- continue;
1410
- }
1411
- imageBytes = new Uint8Array(await response.arrayBuffer());
1412
- if (ct) contentType = ct;
1413
- break;
1414
- }
1415
- } catch {
1416
- // Network failure — try next URL
1417
- }
1418
- }
1419
-
1420
- if (!imageBytes) return;
1399
+ const previousKeys = [post.previewImageKey, post.previewIconKey];
1400
+ const preview =
1401
+ storage && post.format === "link" && post.url
1402
+ ? await resolveLinkPreview(post.url)
1403
+ : null;
1404
+ if (!preview && previousKeys.every((key) => !key)) return;
1421
1405
 
1422
- const ext = contentType.includes("webp")
1423
- ? "webp"
1424
- : contentType.includes("png")
1425
- ? "png"
1426
- : "jpg";
1427
- const suffix = generateRandomId(8);
1428
- const storageKey = getPreviewStorageKey(siteId, postId, suffix, ext);
1406
+ const [imageKey, iconKey] = await Promise.all([
1407
+ preview?.image
1408
+ ? storePreviewFile(post.id, "", preview.image, storage)
1409
+ : null,
1410
+ preview?.icon
1411
+ ? storePreviewFile(post.id, "icon-", preview.icon, storage)
1412
+ : null,
1413
+ ]);
1429
1414
 
1430
1415
  try {
1431
- await storage.put(storageKey, imageBytes, { contentType });
1432
1416
  await db
1433
1417
  .update(posts)
1434
1418
  .set({
1435
- previewImageKey: storageKey,
1436
- previewKind: "video",
1437
- previewProvider: "youtube",
1419
+ previewImageKey: imageKey,
1420
+ previewKind: imageKey ? (preview?.kind ?? null) : null,
1421
+ previewProvider: imageKey ? (preview?.provider ?? null) : null,
1422
+ previewIconKey: iconKey,
1438
1423
  })
1439
- .where(and(eq(posts.siteId, siteId), eq(posts.id, postId)));
1424
+ .where(and(eq(posts.siteId, siteId), eq(posts.id, post.id)));
1440
1425
  } catch {
1441
- // Storage or DB failure — preview is best-effort
1426
+ await deletePreviewFiles([imageKey, iconKey], storage);
1427
+ return;
1442
1428
  }
1429
+ await deletePreviewFiles(previousKeys, storage);
1443
1430
  }
1444
1431
 
1445
- /**
1446
- * Delete a preview image from storage if it exists.
1447
- */
1448
- async function deletePreviewImage(
1449
- previewImageKey: string | null | undefined,
1432
+ /** Store one preview file under a fresh key; null when storing fails. */
1433
+ async function storePreviewFile(
1434
+ postId: string,
1435
+ prefix: string,
1436
+ file: LinkPreviewImage,
1450
1437
  storage: StorageDriver | null | undefined,
1451
- ): Promise<void> {
1452
- if (!storage || !previewImageKey) return;
1438
+ ): Promise<string | null> {
1439
+ if (!storage) return null;
1440
+ const key = getPreviewStorageKey(
1441
+ siteId,
1442
+ postId,
1443
+ `${prefix}${generateRandomId(8)}`,
1444
+ file.ext,
1445
+ );
1453
1446
  try {
1454
- await storage.delete(previewImageKey);
1447
+ await storage.put(key, file.bytes, { contentType: file.contentType });
1448
+ return key;
1455
1449
  } catch {
1456
- // Best-effort cleanup
1450
+ return null;
1451
+ }
1452
+ }
1453
+
1454
+ /** Delete a post's preview files from storage. Best-effort. */
1455
+ async function deletePreviewFiles(
1456
+ keys: readonly (string | null | undefined)[],
1457
+ storage: StorageDriver | null | undefined,
1458
+ ): Promise<void> {
1459
+ if (!storage) return;
1460
+ for (const key of keys) {
1461
+ if (!key) continue;
1462
+ try {
1463
+ await storage.delete(key);
1464
+ } catch {
1465
+ // Best-effort cleanup
1466
+ }
1457
1467
  }
1458
1468
  }
1459
1469
 
@@ -1883,6 +1893,7 @@ export function createPostService(
1883
1893
  previewImageKey: row.previewImageKey,
1884
1894
  previewKind: row.previewKind,
1885
1895
  previewProvider: row.previewProvider,
1896
+ previewIconKey: row.previewIconKey,
1886
1897
  replyToId: row.replyToId,
1887
1898
  threadId: row.threadId,
1888
1899
  language: row.language,
@@ -2470,7 +2481,7 @@ export function createPostService(
2470
2481
  // semantics stay consistent if they ever change.
2471
2482
  const conditions = buildFilterConditions({
2472
2483
  status: "published",
2473
- excludePrivate: true,
2484
+ listedForReader: true,
2474
2485
  excludeReplies: true,
2475
2486
  });
2476
2487
  if (afterId !== undefined) {
@@ -2539,7 +2550,7 @@ export function createPostService(
2539
2550
  async countForSitemap() {
2540
2551
  const conditions = buildFilterConditions({
2541
2552
  status: "published",
2542
- excludePrivate: true,
2553
+ listedForReader: true,
2543
2554
  excludeReplies: true,
2544
2555
  });
2545
2556
  const result = await db
@@ -2553,7 +2564,7 @@ export function createPostService(
2553
2564
  if (offset < 0) return null;
2554
2565
  const conditions = buildFilterConditions({
2555
2566
  status: "published",
2556
- excludePrivate: true,
2567
+ listedForReader: true,
2557
2568
  excludeReplies: true,
2558
2569
  });
2559
2570
  const rows = await db
@@ -3208,13 +3219,8 @@ export function createPostService(
3208
3219
  }
3209
3220
  await applyAttachmentAltUpdates(attachmentInputs, deps);
3210
3221
 
3211
- // Best-effort: fetch and store link preview thumbnail
3212
- await resolveAndStorePreview(
3213
- post.id,
3214
- post.format,
3215
- post.url,
3216
- deps.storage,
3217
- );
3222
+ // Best-effort: the video thumbnail and the site's icon
3223
+ await refreshLinkPreview(post, deps.storage);
3218
3224
 
3219
3225
  return post;
3220
3226
  } catch (error) {
@@ -3346,13 +3352,13 @@ export function createPostService(
3346
3352
  const wasNavigationPageEligible =
3347
3353
  existing.format === "note" &&
3348
3354
  existing.status === "published" &&
3349
- existing.visibility !== "private" &&
3355
+ isListedForReader(existing.visibility) &&
3350
3356
  !isThreadReply(existing) &&
3351
3357
  hasNonEmptyText(existing.title);
3352
3358
  const remainsNavigationPageEligible =
3353
3359
  nextFormat === "note" &&
3354
3360
  nextStatus === "published" &&
3355
- effectiveNextVisibility !== "private" &&
3361
+ isListedForReader(effectiveNextVisibility) &&
3356
3362
  !isThreadReply(existing) &&
3357
3363
  hasNonEmptyText(nextTitle);
3358
3364
 
@@ -3780,19 +3786,12 @@ export function createPostService(
3780
3786
  const formatChanged =
3781
3787
  data.format !== undefined && data.format !== existing.format;
3782
3788
  if (urlChanged || formatChanged) {
3783
- await deletePreviewImage(existing.previewImageKey, deps.storage);
3784
- await db
3785
- .update(posts)
3786
- .set({
3787
- previewImageKey: null,
3788
- previewKind: null,
3789
- previewProvider: null,
3790
- })
3791
- .where(and(eq(posts.siteId, siteId), eq(posts.id, post.id)));
3792
- await resolveAndStorePreview(
3793
- post.id,
3794
- post.format,
3795
- post.url,
3789
+ await refreshLinkPreview(
3790
+ {
3791
+ ...post,
3792
+ previewImageKey: existing.previewImageKey,
3793
+ previewIconKey: existing.previewIconKey,
3794
+ },
3796
3795
  deps.storage,
3797
3796
  );
3798
3797
  }
@@ -3850,24 +3849,12 @@ export function createPostService(
3850
3849
  const formatChanged =
3851
3850
  data.format !== undefined && data.format !== existingPost.format;
3852
3851
  if (urlChanged || formatChanged) {
3853
- // Clean up old preview image
3854
- await deletePreviewImage(existingPost.previewImageKey, deps.storage);
3855
-
3856
- // Clear preview fields first (may be re-set by resolveAndStorePreview)
3857
- await db
3858
- .update(posts)
3859
- .set({
3860
- previewImageKey: null,
3861
- previewKind: null,
3862
- previewProvider: null,
3863
- })
3864
- .where(and(eq(posts.siteId, siteId), eq(posts.id, post.id)));
3865
-
3866
- // Fetch new preview if applicable
3867
- await resolveAndStorePreview(
3868
- post.id,
3869
- post.format,
3870
- post.url,
3852
+ await refreshLinkPreview(
3853
+ {
3854
+ ...post,
3855
+ previewImageKey: existingPost.previewImageKey,
3856
+ previewIconKey: existingPost.previewIconKey,
3857
+ },
3871
3858
  deps.storage,
3872
3859
  );
3873
3860
  }
@@ -3918,7 +3905,10 @@ export function createPostService(
3918
3905
  }
3919
3906
 
3920
3907
  for (const p of affectedPosts) {
3921
- await deletePreviewImage(p.previewImageKey, deps.storage);
3908
+ await deletePreviewFiles(
3909
+ [p.previewImageKey, p.previewIconKey],
3910
+ deps.storage,
3911
+ );
3922
3912
  }
3923
3913
  }
3924
3914
 
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  import type { Post, Status, Format, SearchResult } from "../types.js";
10
+ import { READER_LISTED_VISIBILITIES } from "../types/constants.js";
10
11
  import type { DatabaseDialect } from "../db/dialect.js";
11
12
  import type { RawQueryClient } from "../db/raw-query.js";
12
13
  import { escapeHtml } from "../lib/html.js";
@@ -26,12 +27,14 @@ export interface SearchOptions {
26
27
  /** Filter by status */
27
28
  status?: Status[];
28
29
  /**
29
- * Whether private posts, and replies in a private Thread, may match.
30
+ * Whether the signed-in author is asking. Only then may Unlisted and Private
31
+ * posts, and replies in such a Thread, match: no list a reader sees includes
32
+ * them.
30
33
  *
31
34
  * Defaults to `false`, so a caller that doesn't say who is asking gets what a
32
- * signed-out reader would. Pass `true` only for the signed-in author.
35
+ * signed-out reader would.
33
36
  */
34
- includePrivate?: boolean;
37
+ asAuthor?: boolean;
35
38
  /** Filter by format */
36
39
  format?: Format;
37
40
  /**
@@ -109,6 +112,7 @@ function mapRow(row: RawSearchRow): SearchResult {
109
112
  previewImageKey: null,
110
113
  previewKind: null,
111
114
  previewProvider: null,
115
+ previewIconKey: null,
112
116
  replyToId: row.reply_to_id,
113
117
  threadId: row.thread_id,
114
118
  language: row.language,
@@ -201,13 +205,22 @@ function buildPgPrefixTsQuery(query: string): string | null {
201
205
  const EFFECTIVE_VISIBILITY_SQL =
202
206
  "COALESCE(post.visibility, root_post.visibility)";
203
207
 
208
+ /**
209
+ * The visibilities a signed-out reader may find in a list, as SQL literals.
210
+ * Written into the statement rather than bound, so the reader's rule adds no
211
+ * placeholder and the author's statement lines up with it.
212
+ */
213
+ const READER_LISTED_SQL_VALUES = READER_LISTED_VISIBILITIES.map(
214
+ (value) => `'${value}'`,
215
+ ).join(", ");
216
+
204
217
  /**
205
218
  * The conditions every search statement applies after its own match clause:
206
219
  * site, status, audience, format, and language.
207
220
  *
208
221
  * Built once so that no statement can leave one out. Each dialect and each
209
222
  * match strategy has its own SQL, and a statement missing the visibility
210
- * clause does not fail — it returns private posts.
223
+ * clause does not fail — it returns Unlisted and Private posts.
211
224
  *
212
225
  * @param siteId - Site the search is scoped to
213
226
  * @param options - Caller's search options
@@ -216,7 +229,7 @@ const EFFECTIVE_VISIBILITY_SQL =
216
229
  * @example
217
230
  * ```ts
218
231
  * const filters = buildSearchFilters(siteId, { status: ["published"] });
219
- * // filters.sql: "AND post.site_id = ?\nAND post.status IN (?)\nAND COALESCE(…) != 'private'"
232
+ * // filters.sql: "AND post.site_id = ?\nAND post.status IN (?)\nAND COALESCE(…) IN ('public', 'latest_hidden')"
220
233
  * // filters.params: [siteId, "published"]
221
234
  * ```
222
235
  */
@@ -231,8 +244,10 @@ function buildSearchFilters(
231
244
  ];
232
245
  const params: unknown[] = [siteId, ...status];
233
246
 
234
- if (!options.includePrivate) {
235
- conditions.push(`${EFFECTIVE_VISIBILITY_SQL} != 'private'`);
247
+ if (!options.asAuthor) {
248
+ conditions.push(
249
+ `${EFFECTIVE_VISIBILITY_SQL} IN (${READER_LISTED_SQL_VALUES})`,
250
+ );
236
251
  }
237
252
  if (options.format) {
238
253
  conditions.push("post.format = ?");
@@ -342,7 +342,7 @@ export function createSmartCollectionService(
342
342
  excludeReplies: true,
343
343
  // The floor, always. A smart collection is public, but the posts inside
344
344
  // it are only as visible as they are anywhere else.
345
- excludePrivate: !viewer.isAuthenticated,
345
+ listedForReader: !viewer.isAuthenticated,
346
346
  excludeLatestHidden: false,
347
347
  // Membership never depends on presentation, so the year condition is
348
348
  // pinned to the publication axis whatever the chosen order is.
@@ -403,7 +403,7 @@ export function createSmartCollectionService(
403
403
  {
404
404
  status: "published",
405
405
  excludeReplies: true,
406
- excludePrivate: !viewer.isAuthenticated,
406
+ listedForReader: !viewer.isAuthenticated,
407
407
  excludeLatestHidden: false,
408
408
  lang: viewer.lang,
409
409
  },
@@ -598,7 +598,7 @@ export function createSmartCollectionService(
598
598
  const base: PostFilters = {
599
599
  status: "published",
600
600
  excludeReplies: true,
601
- excludePrivate: !viewer.isAuthenticated,
601
+ listedForReader: !viewer.isAuthenticated,
602
602
  excludeLatestHidden: false,
603
603
  lang: viewer.lang,
604
604
  };