@jant/core 1.2.0 → 1.4.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.
- package/bin/commands/site/import.js +2 -1
- package/dist/{app-CbOZ2Irh.js → app-BuzORSgm.js} +1441 -686
- package/dist/client/.vite/manifest.json +72 -83
- package/dist/client/_assets/chunks/{confirm-CMe01lne.js → confirm-BQebcuNB.js} +1 -1
- package/dist/client/_assets/chunks/{create-editor-hWapNE40.js → create-editor-B8KuszlS.js} +38 -38
- package/dist/client/_assets/chunks/footnote-rail-DUrqz0Py.js +2 -0
- package/dist/client/_assets/chunks/{jant-locale-picker-2L4rkDaz.js → jant-locale-picker-CLq0iKDH.js} +1 -1
- package/dist/client/_assets/chunks/lit-BN4mrI3j.js +2 -0
- package/dist/client/_assets/chunks/{settings-paths-BBVT8zKj.js → settings-paths-_fry4yWW.js} +1 -1
- package/dist/client/_assets/chunks/{slug-format-BuCPjSrB.js → slug-format-bcJ2ozr4.js} +1 -1
- package/dist/client/_assets/chunks/{sortable-list-DJXwkaOv.js → sortable-list-Bz2Na2E9.js} +2 -2
- package/dist/client/_assets/chunks/{unsafe-html-CWos3v6N.js → unsafe-html-OJ9m154w.js} +1 -1
- package/dist/client/_assets/chunks/unsafe-svg-DVJ4NPcb.js +1 -0
- package/dist/client/_assets/client-CStDm2xD.js +354 -0
- package/dist/client/_assets/{client-D8Rrsd73.css → client-CoNHvipV.css} +1 -1
- package/dist/client/_assets/{client-auth-CsUGM718.js → client-auth-D53R-Wby.js} +99 -129
- package/dist/client/_assets/client-author-2WYBkgni.css +2 -0
- package/dist/client/_assets/{client-compose-BB4U7Wz0.js → client-compose-DYtDlYm-.js} +248 -244
- package/dist/client/_assets/{client-manage-CI9-eh-8.js → client-manage-BODyYP5Z.js} +157 -157
- package/dist/client/_assets/{client-settings-BnGPuqwc.js → client-settings-DDpe_tXJ.js} +166 -166
- package/dist/client/_assets/client-share-B9OsXx9p.js +149 -0
- package/dist/{constants-DEgyqWDl.js → constants-C2CdWAqt.js} +55 -5
- package/dist/index.js +1 -1
- package/dist/node.js +2 -2
- package/package.json +2 -1
- package/src/client/components/compose-types.ts +5 -1
- package/src/client/components/jant-compose-dialog.ts +25 -4
- package/src/client/components/jant-media-lightbox.ts +18 -3
- package/src/client/components/jant-nav-manager.ts +2 -0
- package/src/client/components/jant-post-menu.ts +42 -89
- package/src/client/components/nav-manager-types.ts +2 -0
- package/src/client/components/settings-types.ts +1 -1
- package/src/client/list-views.ts +382 -0
- package/src/client/media-lightbox-events.ts +12 -0
- package/src/client/runtime-paths.ts +12 -0
- package/src/client/share-capture.ts +63 -0
- package/src/client/share-launch.ts +36 -9
- package/src/client/tiptap/create-editor.ts +4 -0
- package/src/client/tiptap/embed-node.ts +3 -1
- package/src/client/tiptap/html-block-node.ts +3 -1
- package/src/client/tiptap/image-node.ts +3 -1
- package/src/client/view-confirm.ts +32 -4
- package/src/client.ts +1 -0
- package/src/db/migrations/0037_round_post.sql +16 -0
- package/src/db/migrations/0038_flashy_changeling.sql +15 -0
- package/src/db/migrations/0039_mixed_sister_grimm.sql +1 -0
- package/src/db/migrations/meta/0037_snapshot.json +2932 -0
- package/src/db/migrations/meta/0038_snapshot.json +2924 -0
- package/src/db/migrations/meta/0039_snapshot.json +2931 -0
- package/src/db/migrations/meta/_journal.json +21 -0
- package/src/db/migrations/pg/0035_flimsy_outlaw_kid.sql +3 -0
- package/src/db/migrations/pg/0036_milky_wolverine.sql +5 -0
- package/src/db/migrations/pg/0037_fuzzy_hammerhead.sql +1 -0
- package/src/db/migrations/pg/meta/0035_snapshot.json +3773 -0
- package/src/db/migrations/pg/meta/0036_snapshot.json +3766 -0
- package/src/db/migrations/pg/meta/0037_snapshot.json +3772 -0
- package/src/db/migrations/pg/meta/_journal.json +21 -0
- package/src/db/pg/schema.ts +1 -0
- package/src/db/post-visibility.ts +37 -6
- package/src/db/schema.ts +5 -2
- package/src/i18n/locales/glossary.zh-Hans.yml +4 -0
- package/src/i18n/locales/glossary.zh-Hant.yml +4 -0
- package/src/i18n/locales/public/en.po +21 -90
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +20 -89
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +20 -89
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +84 -0
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +130 -46
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +124 -40
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/lib/api-public-posts.ts +10 -0
- package/src/lib/feed-policy.ts +2 -2
- package/src/lib/feed.ts +17 -1
- package/src/lib/filter-dimensions.ts +11 -4
- package/src/lib/hugo-markdown.ts +7 -0
- package/src/lib/icons.ts +2 -0
- package/src/lib/link-preview.ts +499 -0
- package/src/lib/list-views.ts +117 -0
- package/src/lib/markdown-manager.ts +40 -1
- package/src/lib/navigation.ts +1 -1
- package/src/lib/share-card.ts +4 -3
- package/src/lib/thread-query.ts +6 -2
- package/src/lib/timeline.ts +12 -11
- package/src/lib/url-fetch.ts +291 -74
- package/src/lib/view-buffer.ts +2 -2
- package/src/lib/view-counting.ts +7 -6
- package/src/lib/view-token.ts +29 -7
- package/src/lib/view.ts +17 -0
- package/src/middleware/view-counter.ts +10 -5
- package/src/preset.css +5 -3
- package/src/routes/api/search.ts +1 -1
- package/src/routes/dash/settings.tsx +1 -1
- package/src/routes/feed/sitemap.ts +1 -1
- package/src/routes/pages/archive.tsx +25 -19
- package/src/routes/pages/collection.tsx +3 -3
- package/src/routes/pages/page.tsx +16 -4
- package/src/routes/pages/search.tsx +3 -3
- package/src/routes/pages/subscribe.tsx +19 -3
- package/src/routes/view-confirm.ts +23 -15
- package/src/services/collection.ts +1 -1
- package/src/services/export-theme/assets/client-site.js +19 -19
- package/src/services/export-theme/layouts/archive/list.html +4 -2
- package/src/services/export-theme/layouts/partials/collection-members.html +4 -3
- package/src/services/export-theme/layouts/partials/featured-members.html +3 -3
- package/src/services/export-theme/layouts/partials/head.html +2 -0
- package/src/services/export-theme/layouts/partials/latest-members.html +4 -4
- package/src/services/export-theme/layouts/partials/post-card.html +1 -9
- package/src/services/export-theme/layouts/partials/reply.html +1 -9
- package/src/services/export-theme/layouts/partials/smart-collection-members.html +4 -3
- package/src/services/export-theme/layouts/post/list.html +1 -9
- package/src/services/export-theme/styles/main.css +2 -26
- package/src/services/export.ts +10 -3
- package/src/services/mcp.ts +5 -5
- package/src/services/navigation.ts +9 -4
- package/src/services/post.ts +102 -112
- package/src/services/search.ts +22 -7
- package/src/services/smart-collection.ts +3 -3
- package/src/services/stats.ts +12 -5
- package/src/services/thread.ts +6 -2
- package/src/styles/components-author.css +69 -7
- package/src/styles/tokens.css +28 -29
- package/src/styles/ui-author.css +140 -353
- package/src/styles/ui.css +34 -32
- package/src/types/constants.ts +68 -4
- package/src/types/entities.ts +1 -0
- package/src/types/views.ts +2 -0
- package/src/ui/compose/ComposeDialog.tsx +20 -1
- package/src/ui/dash/StatusBadge.tsx +11 -0
- package/src/ui/dash/appearance/FontThemeContent.tsx +1 -1
- package/src/ui/dash/appearance/NavigationContent.tsx +8 -0
- package/src/ui/dash/settings/StatsContent.tsx +29 -29
- package/src/ui/feed/LinkCard.tsx +19 -2
- package/src/ui/feed/PostStatusBadges.tsx +19 -3
- package/src/ui/feed/TimelineFeed.tsx +3 -0
- package/src/ui/font-themes.ts +32 -15
- package/src/ui/pages/ArchivePage.tsx +1 -0
- package/src/ui/pages/SubscribePage.tsx +9 -1
- package/src/ui/shared/PostFooter.tsx +1 -22
- package/src/ui/shared/custom-icons.ts +5 -5
- package/dist/client/_assets/chunks/footnote-rail-9zwl6jtV.js +0 -2
- package/dist/client/_assets/chunks/lit-Bw_voPoW.js +0 -2
- package/dist/client/_assets/chunks/runtime-paths-y0_gHowM.js +0 -1
- package/dist/client/_assets/chunks/unsafe-svg-CUrgo4Xg.js +0 -1
- package/dist/client/_assets/client-BO8GOFfT.js +0 -354
- package/dist/client/_assets/client-author-QPm1whbO.css +0 -2
- package/dist/client/_assets/client-share-C59mOLJ1.js +0 -149
|
@@ -32,6 +32,7 @@ import type {
|
|
|
32
32
|
NavigationPageCandidate,
|
|
33
33
|
} from "../types.js";
|
|
34
34
|
import { SYSTEM_NAV_KEYS } from "../types.js";
|
|
35
|
+
import { isListedForReader } from "../types/constants.js";
|
|
35
36
|
|
|
36
37
|
const POSITION_RETRY_ATTEMPTS = 5;
|
|
37
38
|
const SUGGESTED_NAV_LINK_CANDIDATES = [
|
|
@@ -47,6 +48,7 @@ export interface ListSuggestedLinksOptions {
|
|
|
47
48
|
// Re-export shared constraint detection — see db/dialect.ts
|
|
48
49
|
import { isUniqueConstraintError } from "../db/dialect.js";
|
|
49
50
|
import {
|
|
51
|
+
buildListedForReaderCondition,
|
|
50
52
|
buildReaderVisibilityConditions,
|
|
51
53
|
type ReaderVisibilityOptions,
|
|
52
54
|
} from "../db/post-visibility.js";
|
|
@@ -85,6 +87,8 @@ export type NavTargetResolution =
|
|
|
85
87
|
| { status: "unpublished" }
|
|
86
88
|
/** Published but private: a menu entry nobody could open. */
|
|
87
89
|
| { status: "private" }
|
|
90
|
+
/** Published but unlisted: a menu entry would list it on every page. */
|
|
91
|
+
| { status: "unlisted" }
|
|
88
92
|
| { status: "not_found" };
|
|
89
93
|
|
|
90
94
|
export interface NavTargetCollection {
|
|
@@ -286,7 +290,7 @@ export function createNavItemService(
|
|
|
286
290
|
inArray(posts.translationGroupId, groupIds),
|
|
287
291
|
eq(posts.language, language),
|
|
288
292
|
eq(posts.status, "published"),
|
|
289
|
-
|
|
293
|
+
buildListedForReaderCondition(posts.visibility),
|
|
290
294
|
isNull(posts.replyToId),
|
|
291
295
|
sql`trim(${posts.title}) != ''`,
|
|
292
296
|
),
|
|
@@ -430,7 +434,7 @@ export function createNavItemService(
|
|
|
430
434
|
eq(posts.id, data.postId),
|
|
431
435
|
eq(posts.format, "note"),
|
|
432
436
|
eq(posts.status, "published"),
|
|
433
|
-
|
|
437
|
+
buildListedForReaderCondition(posts.visibility),
|
|
434
438
|
isNull(posts.replyToId),
|
|
435
439
|
sql`trim(${posts.title}) != ''`,
|
|
436
440
|
),
|
|
@@ -590,7 +594,7 @@ export function createNavItemService(
|
|
|
590
594
|
eq(posts.siteId, siteId),
|
|
591
595
|
eq(posts.format, "note"),
|
|
592
596
|
eq(posts.status, "published"),
|
|
593
|
-
|
|
597
|
+
buildListedForReaderCondition(posts.visibility),
|
|
594
598
|
isNull(posts.replyToId),
|
|
595
599
|
sql`trim(${posts.title}) != ''`,
|
|
596
600
|
isNull(navItems.id),
|
|
@@ -710,6 +714,7 @@ export function createNavItemService(
|
|
|
710
714
|
|
|
711
715
|
if (row.status !== "published") return { status: "unpublished" };
|
|
712
716
|
if (row.visibility === "private") return { status: "private" };
|
|
717
|
+
if (row.visibility === "unlisted") return { status: "unlisted" };
|
|
713
718
|
const title = row.title?.trim() ?? "";
|
|
714
719
|
if (!title) return { status: "untitled" };
|
|
715
720
|
|
|
@@ -1054,7 +1059,7 @@ export function createNavItemService(
|
|
|
1054
1059
|
!post ||
|
|
1055
1060
|
post.format !== "note" ||
|
|
1056
1061
|
post.status !== "published" ||
|
|
1057
|
-
post.visibility
|
|
1062
|
+
!isListedForReader(post.visibility ?? "public") ||
|
|
1058
1063
|
post.replyToId !== null ||
|
|
1059
1064
|
!post.title?.trim()
|
|
1060
1065
|
) {
|
package/src/services/post.ts
CHANGED
|
@@ -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
|
-
|
|
109
|
-
|
|
110
|
-
} from "../lib/
|
|
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
|
-
/**
|
|
167
|
-
|
|
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
|
-
|
|
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",
|
|
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
|
-
*
|
|
1381
|
-
*
|
|
1382
|
-
*
|
|
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
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
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
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
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
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
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:
|
|
1436
|
-
previewKind:
|
|
1437
|
-
previewProvider:
|
|
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,
|
|
1424
|
+
.where(and(eq(posts.siteId, siteId), eq(posts.id, post.id)));
|
|
1440
1425
|
} catch {
|
|
1441
|
-
|
|
1426
|
+
await deletePreviewFiles([imageKey, iconKey], storage);
|
|
1427
|
+
return;
|
|
1442
1428
|
}
|
|
1429
|
+
await deletePreviewFiles(previousKeys, storage);
|
|
1443
1430
|
}
|
|
1444
1431
|
|
|
1445
|
-
/**
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
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<
|
|
1452
|
-
if (!storage
|
|
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.
|
|
1447
|
+
await storage.put(key, file.bytes, { contentType: file.contentType });
|
|
1448
|
+
return key;
|
|
1455
1449
|
} catch {
|
|
1456
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
3212
|
-
await
|
|
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
|
|
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
|
|
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
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
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
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
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
|
|
3908
|
+
await deletePreviewFiles(
|
|
3909
|
+
[p.previewImageKey, p.previewIconKey],
|
|
3910
|
+
deps.storage,
|
|
3911
|
+
);
|
|
3922
3912
|
}
|
|
3923
3913
|
}
|
|
3924
3914
|
|
package/src/services/search.ts
CHANGED
|
@@ -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
|
|
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.
|
|
35
|
+
* signed-out reader would.
|
|
33
36
|
*/
|
|
34
|
-
|
|
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
|
|
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(…)
|
|
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.
|
|
235
|
-
conditions.push(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
601
|
+
listedForReader: !viewer.isAuthenticated,
|
|
602
602
|
excludeLatestHidden: false,
|
|
603
603
|
lang: viewer.lang,
|
|
604
604
|
};
|
package/src/services/stats.ts
CHANGED
|
@@ -11,11 +11,18 @@
|
|
|
11
11
|
* - **A row is a counter.** Ten thousand readers opening one post from one
|
|
12
12
|
* link are one row. The table grows with the variety of a day's traffic,
|
|
13
13
|
* never its volume.
|
|
14
|
-
* - **A key names a page.** A
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* - **A key names a page.** A Thread (a lone post is a Thread of one), a
|
|
15
|
+
* collection or a smart collection is counted by id — a Thread by its
|
|
16
|
+
* root's — so its count survives a change of address and every post of a
|
|
17
|
+
* Thread opens the same page; the home page, the archive and an aggregate
|
|
18
|
+
* selection are counted by path. The key's shape says which
|
|
19
|
+
* (`viewPageKind`), and the list is named from it when read, never stored.
|
|
20
|
+
* - **Opened, or read in a list.** A Thread a reader read whole in a list
|
|
21
|
+
* without opening it (`client/list-views.ts` has what "whole" takes)
|
|
22
|
+
* counts as a view of it, like its page opened, in every number: its own,
|
|
23
|
+
* the site's total, the chart, the referrers. A view is something read,
|
|
24
|
+
* not a visit — Jant has no visits — so the home page opened and three
|
|
25
|
+
* notes read on it are four.
|
|
19
26
|
* - **Thirty days.** Rows older than `VIEW_COUNT_RETENTION_DAYS` are deleted,
|
|
20
27
|
* once a day per site, by whichever flush comes first. Nothing is rolled up:
|
|
21
28
|
* a lifetime total is exactly the scoreboard this feature is not.
|
package/src/services/thread.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
type PostFilterSelection,
|
|
22
22
|
} from "../lib/filter-dimensions.js";
|
|
23
23
|
import { foldReplyWindows, type ThreadFold } from "../lib/thread-fold.js";
|
|
24
|
+
import { isOpenableByReader } from "../types/constants.js";
|
|
24
25
|
import type {
|
|
25
26
|
CollectionSortOrder,
|
|
26
27
|
Post,
|
|
@@ -263,6 +264,9 @@ export function createThreadService(deps: {
|
|
|
263
264
|
if (reader && visibility === "private") {
|
|
264
265
|
throw new ValidationError("Private posts aren't listed here.");
|
|
265
266
|
}
|
|
267
|
+
if (reader && visibility === "unlisted") {
|
|
268
|
+
throw new ValidationError("Unlisted posts aren't listed here.");
|
|
269
|
+
}
|
|
266
270
|
if (
|
|
267
271
|
visibility === "featured" &&
|
|
268
272
|
query.sort !== undefined &&
|
|
@@ -273,7 +277,7 @@ export function createThreadService(deps: {
|
|
|
273
277
|
|
|
274
278
|
const base = {
|
|
275
279
|
status: reader ? ("published" as const) : (query.status ?? "published"),
|
|
276
|
-
|
|
280
|
+
listedForReader: reader,
|
|
277
281
|
excludeLatestHidden:
|
|
278
282
|
reader && visibility === undefined && !query.includeHidden,
|
|
279
283
|
lang: query.lang,
|
|
@@ -344,7 +348,7 @@ export function createThreadService(deps: {
|
|
|
344
348
|
if (!root) return null;
|
|
345
349
|
if (
|
|
346
350
|
audience === "reader" &&
|
|
347
|
-
(root.status !== "published" || root.visibility
|
|
351
|
+
(root.status !== "published" || !isOpenableByReader(root.visibility))
|
|
348
352
|
) {
|
|
349
353
|
return null;
|
|
350
354
|
}
|