@jant/core 0.9.0 → 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-BzH8jmh3.js → app-B3P2N2vM.js} +153 -54
- package/dist/client/.vite/manifest.json +2 -2
- package/dist/client/_assets/{client-auth-Ds9G0IgR.js → client-auth-CeGBe0qG.js} +1 -1
- package/dist/client/_assets/{client-S8oryJ0m.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/lib/__tests__/discover.test.ts +24 -0
- package/src/lib/discover.ts +34 -0
- package/src/routes/api/__tests__/mcp.test.ts +54 -0
- package/src/routes/api/__tests__/search.test.ts +104 -0
- package/src/routes/api/search.ts +31 -2
- 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/mcp.ts +9 -4
- package/src/services/search.ts +77 -66
|
@@ -292,4 +292,4 @@ ${c}`:c;break;case`event`:r.event=c;break;case`id`:e(r.id=c);break;case`retry`:{
|
|
|
292
292
|
</div>`}
|
|
293
293
|
</div>
|
|
294
294
|
</dialog>
|
|
295
|
-
`:t}};customElements.define(`jant-text-preview`,gn);function _n(e){return e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey}function vn(e,t){t&&(e.textContent=t)}function yn(e){let t=e.target;if(!(t instanceof globalThis.Element))return;let n=t.closest(`a[data-note-expand]`);if(!n||_n(e))return;let r=n.closest(`article[data-post]`),i=r?.querySelector(`[data-post-body]`);if(r&&i&&i.querySelector(`[data-note-break]`)){if(e.preventDefault(),i.hasAttribute(`data-note-clamp`)){i.removeAttribute(`data-note-clamp`),n.setAttribute(`aria-expanded`,`true`),vn(n,n.dataset.labelLess);return}i.setAttribute(`data-note-clamp`,``),n.setAttribute(`aria-expanded`,`false`),vn(n,n.dataset.labelMore),r.getBoundingClientRect().top<0&&typeof r.scrollIntoView==`function`&&r.scrollIntoView({block:`start`})}}document.addEventListener(`click`,yn),document.querySelectorAll(`.archive-chip-dropdown`).forEach(e=>{let t=e.querySelector(`:scope > button`),n=e.querySelector(`:scope > [data-popover]`),r=n?n.querySelector(`[role="listbox"]`):null;if(!t||!n||!r)return;let i=Array.from(r.querySelectorAll(`[role="option"]`)),a=e.classList.contains(`archive-chip-media`),o=e.dataset.filterKey,s=new Set;a&&i.forEach(e=>{!e.dataset.navigate&&e.getAttribute(`aria-selected`)===`true`&&s.add(e.dataset.value)});let c=new Set(s),l=()=>{document.dispatchEvent(new CustomEvent(`basecoat:popover`,{detail:{source:e}})),n.setAttribute(`aria-hidden`,`false`),t.setAttribute(`aria-expanded`,`true`),a&&(c=new Set(s))},u=(e=!0)=>{if(n.getAttribute(`aria-hidden`)!==`true`&&(n.setAttribute(`aria-hidden`,`true`),t.setAttribute(`aria-expanded`,`false`),e&&t.focus(),a&&o&&(s.size!==c.size||[...s].some(e=>!c.has(e))))){let e=new URL(window.location.href),t=[...s];t.length>0?e.searchParams.set(o,t.join(`,`)):e.searchParams.delete(o),e.searchParams.delete(`hasMedia`),e.searchParams.delete(`page`),window.location.href=e.pathname+(e.search||``)}};t.addEventListener(`click`,e=>{e.target.closest(`.archive-chip-clear`)||(t.getAttribute(`aria-expanded`)===`true`?u():l())}),document.addEventListener(`click`,t=>{e.contains(t.target)||u(!1)}),document.addEventListener(`basecoat:popover`,t=>{t.detail.source!==e&&u(!1)}),r.addEventListener(`click`,e=>{let t=e.target.closest(`[role="option"]`);if(t){if(t.dataset.navigate){let e=t.dataset.value;typeof e==`string`&&e.startsWith(`/`)&&(window.location.href=e);return}if(a){let e=t.dataset.value;s.has(e)?(s.delete(e),t.removeAttribute(`aria-selected`)):(s.add(e),t.setAttribute(`aria-selected`,`true`))}else{let e=t.dataset.value;typeof e==`string`&&e.startsWith(`/`)&&(window.location.href=e)}}});let d=-1,f=e=>{d>-1&&i[d]&&i[d].classList.remove(`active`),d=e,d>-1&&i[d]&&(i[d].classList.add(`active`),i[d].scrollIntoView({block:`nearest`}))};r.addEventListener(`mousemove`,e=>{let t=e.target.closest(`[role="option"]`);if(t){let e=i.indexOf(t);e!==-1&&e!==d&&f(e)}}),r.addEventListener(`mouseleave`,()=>{f(-1)}),t.addEventListener(`keydown`,e=>{let t=n.getAttribute(`aria-hidden`)===`false`;if(e.key===`Escape`){t&&(e.preventDefault(),u());return}if(!t&&[`ArrowDown`,`ArrowUp`].includes(e.key)){e.preventDefault(),l();return}t&&(e.preventDefault(),e.key===`ArrowDown`?f(Math.min(d+1,i.length-1)):e.key===`ArrowUp`?f(Math.max(d-1,0)):e.key===`Enter`&&d>-1&&(i[d].click(),!a&&!i[d].dataset.navigate&&u()))})});function bn(e=document){e.querySelectorAll(`.collection-sort-menu`).forEach(e=>{if(e.dataset.collectionSortMenuInitialized===`true`)return;let t=e.querySelector(`:scope > .collection-sort-trigger`),n=e.querySelector(`:scope > [data-popover]`),r=n?.querySelector(`[data-collection-sort-options]`);if(!(t instanceof HTMLButtonElement)||!n||!r)return;let i=(e=!1)=>{n.getAttribute(`aria-hidden`)!==`true`&&(n.setAttribute(`aria-hidden`,`true`),t.setAttribute(`aria-expanded`,`false`),e&&t.focus())},a=()=>{document.dispatchEvent(new CustomEvent(`basecoat:popover`,{detail:{source:e}})),n.setAttribute(`aria-hidden`,`false`),t.setAttribute(`aria-expanded`,`true`)};t.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),t.getAttribute(`aria-expanded`)===`true`?i(!1):a()}),t.addEventListener(`keydown`,e=>{if(e.key===`Escape`){e.preventDefault(),i(!0);return}if(e.key===`ArrowDown`){e.preventDefault(),t.getAttribute(`aria-expanded`)!==`true`&&a();let n=r.querySelector(`a[href]`);n instanceof HTMLElement&&n.focus()}}),n.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.preventDefault(),i(!0))}),document.addEventListener(`click`,t=>{t.target instanceof Node&&(e.contains(t.target)||i(!1))}),document.addEventListener(`basecoat:popover`,t=>{t.detail?.source!==e&&i(!1)}),e.dataset.collectionSortMenuInitialized=`true`})}bn(),r(),document.documentElement.dataset.jantVersion=`0.9.
|
|
295
|
+
`:t}};customElements.define(`jant-text-preview`,gn);function _n(e){return e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey}function vn(e,t){t&&(e.textContent=t)}function yn(e){let t=e.target;if(!(t instanceof globalThis.Element))return;let n=t.closest(`a[data-note-expand]`);if(!n||_n(e))return;let r=n.closest(`article[data-post]`),i=r?.querySelector(`[data-post-body]`);if(r&&i&&i.querySelector(`[data-note-break]`)){if(e.preventDefault(),i.hasAttribute(`data-note-clamp`)){i.removeAttribute(`data-note-clamp`),n.setAttribute(`aria-expanded`,`true`),vn(n,n.dataset.labelLess);return}i.setAttribute(`data-note-clamp`,``),n.setAttribute(`aria-expanded`,`false`),vn(n,n.dataset.labelMore),r.getBoundingClientRect().top<0&&typeof r.scrollIntoView==`function`&&r.scrollIntoView({block:`start`})}}document.addEventListener(`click`,yn),document.querySelectorAll(`.archive-chip-dropdown`).forEach(e=>{let t=e.querySelector(`:scope > button`),n=e.querySelector(`:scope > [data-popover]`),r=n?n.querySelector(`[role="listbox"]`):null;if(!t||!n||!r)return;let i=Array.from(r.querySelectorAll(`[role="option"]`)),a=e.classList.contains(`archive-chip-media`),o=e.dataset.filterKey,s=new Set;a&&i.forEach(e=>{!e.dataset.navigate&&e.getAttribute(`aria-selected`)===`true`&&s.add(e.dataset.value)});let c=new Set(s),l=()=>{document.dispatchEvent(new CustomEvent(`basecoat:popover`,{detail:{source:e}})),n.setAttribute(`aria-hidden`,`false`),t.setAttribute(`aria-expanded`,`true`),a&&(c=new Set(s))},u=(e=!0)=>{if(n.getAttribute(`aria-hidden`)!==`true`&&(n.setAttribute(`aria-hidden`,`true`),t.setAttribute(`aria-expanded`,`false`),e&&t.focus(),a&&o&&(s.size!==c.size||[...s].some(e=>!c.has(e))))){let e=new URL(window.location.href),t=[...s];t.length>0?e.searchParams.set(o,t.join(`,`)):e.searchParams.delete(o),e.searchParams.delete(`hasMedia`),e.searchParams.delete(`page`),window.location.href=e.pathname+(e.search||``)}};t.addEventListener(`click`,e=>{e.target.closest(`.archive-chip-clear`)||(t.getAttribute(`aria-expanded`)===`true`?u():l())}),document.addEventListener(`click`,t=>{e.contains(t.target)||u(!1)}),document.addEventListener(`basecoat:popover`,t=>{t.detail.source!==e&&u(!1)}),r.addEventListener(`click`,e=>{let t=e.target.closest(`[role="option"]`);if(t){if(t.dataset.navigate){let e=t.dataset.value;typeof e==`string`&&e.startsWith(`/`)&&(window.location.href=e);return}if(a){let e=t.dataset.value;s.has(e)?(s.delete(e),t.removeAttribute(`aria-selected`)):(s.add(e),t.setAttribute(`aria-selected`,`true`))}else{let e=t.dataset.value;typeof e==`string`&&e.startsWith(`/`)&&(window.location.href=e)}}});let d=-1,f=e=>{d>-1&&i[d]&&i[d].classList.remove(`active`),d=e,d>-1&&i[d]&&(i[d].classList.add(`active`),i[d].scrollIntoView({block:`nearest`}))};r.addEventListener(`mousemove`,e=>{let t=e.target.closest(`[role="option"]`);if(t){let e=i.indexOf(t);e!==-1&&e!==d&&f(e)}}),r.addEventListener(`mouseleave`,()=>{f(-1)}),t.addEventListener(`keydown`,e=>{let t=n.getAttribute(`aria-hidden`)===`false`;if(e.key===`Escape`){t&&(e.preventDefault(),u());return}if(!t&&[`ArrowDown`,`ArrowUp`].includes(e.key)){e.preventDefault(),l();return}t&&(e.preventDefault(),e.key===`ArrowDown`?f(Math.min(d+1,i.length-1)):e.key===`ArrowUp`?f(Math.max(d-1,0)):e.key===`Enter`&&d>-1&&(i[d].click(),!a&&!i[d].dataset.navigate&&u()))})});function bn(e=document){e.querySelectorAll(`.collection-sort-menu`).forEach(e=>{if(e.dataset.collectionSortMenuInitialized===`true`)return;let t=e.querySelector(`:scope > .collection-sort-trigger`),n=e.querySelector(`:scope > [data-popover]`),r=n?.querySelector(`[data-collection-sort-options]`);if(!(t instanceof HTMLButtonElement)||!n||!r)return;let i=(e=!1)=>{n.getAttribute(`aria-hidden`)!==`true`&&(n.setAttribute(`aria-hidden`,`true`),t.setAttribute(`aria-expanded`,`false`),e&&t.focus())},a=()=>{document.dispatchEvent(new CustomEvent(`basecoat:popover`,{detail:{source:e}})),n.setAttribute(`aria-hidden`,`false`),t.setAttribute(`aria-expanded`,`true`)};t.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),t.getAttribute(`aria-expanded`)===`true`?i(!1):a()}),t.addEventListener(`keydown`,e=>{if(e.key===`Escape`){e.preventDefault(),i(!0);return}if(e.key===`ArrowDown`){e.preventDefault(),t.getAttribute(`aria-expanded`)!==`true`&&a();let n=r.querySelector(`a[href]`);n instanceof HTMLElement&&n.focus()}}),n.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.preventDefault(),i(!0))}),document.addEventListener(`click`,t=>{t.target instanceof Node&&(e.contains(t.target)||i(!1))}),document.addEventListener(`basecoat:popover`,t=>{t.detail?.source!==e&&i(!1)}),e.dataset.collectionSortMenuInitialized=`true`})}bn(),r(),document.documentElement.dataset.jantVersion=`0.9.1-d7610f6379632ea6`;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createApp } from "./app-
|
|
1
|
+
import { n as createApp } from "./app-B3P2N2vM.js";
|
|
2
2
|
export { createApp };
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as BUILTIN_FONT_THEMES, C as getEnvString, D as getTelegramBotPool, E as getSiteResolutionMode, F as BUILTIN_COLOR_THEMES, I as getPublicAssetBasePath, L as isAssetPath, M as getFontThemeCssVariables, N as resolveCjkFontProfile, O as getTelegramWebhookSecret, P as buildThemeStyle, S as getConfiguredStorageDriver, T as getPort, _ as createNodeDatabase, a as setUpNodeInstance, b as getConfiguredSingleSiteOrigin, c as resolveDatabaseDialect, d as getWebhookUrl, f as setMyCommands, g as sqliteSchemaBundle, h as pgSchemaBundle, i as createNodeRequestRuntime, j as getCjkFontCssVariables, k as shouldTrustProxy, l as createExportService, m as createStorageDriver, n as createApp, o as createSiteService, p as setWebhook, r as createNodeCliRuntime, s as getHostBasedStartupConfigurationIssues, u as resolveConfig, v as schema_exports, w as getHostedControlPlaneBaseUrl, x as getConfiguredSingleSitePathPrefix, y as now } from "./app-
|
|
1
|
+
import { A as BUILTIN_FONT_THEMES, C as getEnvString, D as getTelegramBotPool, E as getSiteResolutionMode, F as BUILTIN_COLOR_THEMES, I as getPublicAssetBasePath, L as isAssetPath, M as getFontThemeCssVariables, N as resolveCjkFontProfile, O as getTelegramWebhookSecret, P as buildThemeStyle, S as getConfiguredStorageDriver, T as getPort, _ as createNodeDatabase, a as setUpNodeInstance, b as getConfiguredSingleSiteOrigin, c as resolveDatabaseDialect, d as getWebhookUrl, f as setMyCommands, g as sqliteSchemaBundle, h as pgSchemaBundle, i as createNodeRequestRuntime, j as getCjkFontCssVariables, k as shouldTrustProxy, l as createExportService, m as createStorageDriver, n as createApp, o as createSiteService, p as setWebhook, r as createNodeCliRuntime, s as getHostBasedStartupConfigurationIssues, u as resolveConfig, v as schema_exports, w as getHostedControlPlaneBaseUrl, x as getConfiguredSingleSitePathPrefix, y as now } from "./app-B3P2N2vM.js";
|
|
2
2
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
3
3
|
import { serve } from "@hono/node-server";
|
|
4
4
|
import Database from "better-sqlite3";
|
|
@@ -530,7 +530,7 @@ async function createNodeRequestHandler(options) {
|
|
|
530
530
|
async function start(env = process.env, app) {
|
|
531
531
|
const handler = await createNodeRequestHandler({
|
|
532
532
|
env,
|
|
533
|
-
app: async () => app ?? (await import("./app-
|
|
533
|
+
app: async () => app ?? (await import("./app-B3P2N2vM.js").then((n) => n.t)).createApp()
|
|
534
534
|
});
|
|
535
535
|
const hostname = resolveHost(env);
|
|
536
536
|
const port = resolvePort(env);
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
getDiscoverFeedPath,
|
|
5
5
|
getDiscoverPageUrls,
|
|
6
6
|
getDiscoverSubmitUrl,
|
|
7
|
+
isDiscoverLanguage,
|
|
7
8
|
linkTerms,
|
|
8
9
|
measureDiscoverMaturity,
|
|
9
10
|
parseDiscoverSetting,
|
|
@@ -249,6 +250,29 @@ describe("measureDiscoverMaturity", () => {
|
|
|
249
250
|
});
|
|
250
251
|
});
|
|
251
252
|
|
|
253
|
+
describe("isDiscoverLanguage", () => {
|
|
254
|
+
// One list for both scripts: splitting an already small community over a
|
|
255
|
+
// script boundary is what the directory decided against.
|
|
256
|
+
it("accepts Chinese in either script", () => {
|
|
257
|
+
expect(isDiscoverLanguage("zh-Hans")).toBe(true);
|
|
258
|
+
expect(isDiscoverLanguage("zh-Hant")).toBe(true);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// A stored tag is not always one the picker offers; a region form or a bare
|
|
262
|
+
// `zh` is still Chinese.
|
|
263
|
+
it("reads the primary subtag, whatever follows it", () => {
|
|
264
|
+
expect(isDiscoverLanguage("zh")).toBe(true);
|
|
265
|
+
expect(isDiscoverLanguage("zh-TW")).toBe(true);
|
|
266
|
+
expect(isDiscoverLanguage("ZH-hans")).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("turns away every other language", () => {
|
|
270
|
+
expect(isDiscoverLanguage("en")).toBe(false);
|
|
271
|
+
expect(isDiscoverLanguage("ja")).toBe(false);
|
|
272
|
+
expect(isDiscoverLanguage("")).toBe(false);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
252
276
|
describe("getDiscoverSubmitUrl", () => {
|
|
253
277
|
it("finds the form beside the directory's own ping endpoint", () => {
|
|
254
278
|
expect(getDiscoverSubmitUrl("https://jant.me/api/discover/ping")).toBe(
|
package/src/lib/discover.ts
CHANGED
|
@@ -200,6 +200,40 @@ export const DISCOVER_FIRST_READ_MAX_HOURS = 6;
|
|
|
200
200
|
*/
|
|
201
201
|
export const DISCOVER_PUBLIC_DELAY_HOURS = 24;
|
|
202
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Languages the jant.me directory lists, as primary language subtags.
|
|
205
|
+
*
|
|
206
|
+
* The directory's rule — its `accepted_languages` — stated here for the same
|
|
207
|
+
* reason as `DISCOVER_MIN_PUBLIC_POSTS`, and read by setup alone: the Discover
|
|
208
|
+
* question is asked there only when the answer can lead somewhere. An author
|
|
209
|
+
* writing in a language the directory does not list would be handed a promise
|
|
210
|
+
* nobody keeps, ticked in advance on hosted Jant.
|
|
211
|
+
*
|
|
212
|
+
* Nothing else reads it. The settings checkbox records consent rather than
|
|
213
|
+
* applying for a listing, and a site can take on a listed language later
|
|
214
|
+
* through multilingual content, so it stays for everyone.
|
|
215
|
+
*
|
|
216
|
+
* Simplified and Traditional Chinese are one list there, which is why the
|
|
217
|
+
* match is on the primary subtag rather than on the script.
|
|
218
|
+
*/
|
|
219
|
+
export const DISCOVER_LANGUAGES: readonly string[] = ["zh"];
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Whether the jant.me directory lists posts written in a language.
|
|
223
|
+
*
|
|
224
|
+
* @param tag - A BCP 47 language tag, as the content language is stored
|
|
225
|
+
* @returns True when the tag's primary subtag is in `DISCOVER_LANGUAGES`
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* isDiscoverLanguage("zh-Hant"); // true
|
|
229
|
+
* isDiscoverLanguage("en"); // false
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
export function isDiscoverLanguage(tag: string): boolean {
|
|
233
|
+
const primary = tag.split("-")[0]?.toLowerCase() ?? "";
|
|
234
|
+
return DISCOVER_LANGUAGES.includes(primary);
|
|
235
|
+
}
|
|
236
|
+
|
|
203
237
|
/**
|
|
204
238
|
* The directory's names for its two format lists.
|
|
205
239
|
*
|
|
@@ -429,6 +429,60 @@ describe("MCP API Routes", () => {
|
|
|
429
429
|
expect(body.result.structuredContent.results[0].slug).toBeTruthy();
|
|
430
430
|
});
|
|
431
431
|
|
|
432
|
+
it("searches private posts and says which results are private", async () => {
|
|
433
|
+
const { app, services } = createTestApp({ authenticated: true, fts: true });
|
|
434
|
+
app.route("/api/mcp", mcpApiRoutes);
|
|
435
|
+
|
|
436
|
+
const root = await services.posts.create({
|
|
437
|
+
format: "note",
|
|
438
|
+
title: "Secret diary",
|
|
439
|
+
body: tiptapDoc("Private root about lanterns"),
|
|
440
|
+
visibility: "private",
|
|
441
|
+
});
|
|
442
|
+
const reply = await services.posts.create({
|
|
443
|
+
format: "note",
|
|
444
|
+
body: tiptapDoc("Private reply about lanterns"),
|
|
445
|
+
replyToId: root.id,
|
|
446
|
+
});
|
|
447
|
+
const publicPost = await services.posts.create({
|
|
448
|
+
format: "note",
|
|
449
|
+
body: tiptapDoc("Public post about lanterns"),
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
const res = await postMcp(
|
|
453
|
+
app,
|
|
454
|
+
{
|
|
455
|
+
jsonrpc: "2.0",
|
|
456
|
+
id: 4,
|
|
457
|
+
method: "tools/call",
|
|
458
|
+
params: {
|
|
459
|
+
name: "jant_search_posts",
|
|
460
|
+
arguments: { query: "lanterns" },
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
{ "MCP-Protocol-Version": "2025-06-18" },
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
expect(res.status).toBe(200);
|
|
467
|
+
const body = await res.json();
|
|
468
|
+
expect(body.result.isError).toBe(false);
|
|
469
|
+
const visibilityById = new Map(
|
|
470
|
+
(
|
|
471
|
+
body.result.structuredContent.results as {
|
|
472
|
+
id: string;
|
|
473
|
+
visibility: string;
|
|
474
|
+
}[]
|
|
475
|
+
).map((result) => [result.id, result.visibility]),
|
|
476
|
+
);
|
|
477
|
+
expect(visibilityById).toEqual(
|
|
478
|
+
new Map([
|
|
479
|
+
[root.id, "private"],
|
|
480
|
+
[reply.id, "private"],
|
|
481
|
+
[publicPost.id, "public"],
|
|
482
|
+
]),
|
|
483
|
+
);
|
|
484
|
+
});
|
|
485
|
+
|
|
432
486
|
it("uploads media through tools/call", async () => {
|
|
433
487
|
const storage = createMockStorage();
|
|
434
488
|
const { app, services } = createTestApp({
|
|
@@ -102,6 +102,110 @@ describe("Search API Routes", () => {
|
|
|
102
102
|
expect(body.count).toBe(0);
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
+
describe("private posts", () => {
|
|
106
|
+
async function seedPrivateThread(
|
|
107
|
+
services: ReturnType<typeof createTestApp>["services"],
|
|
108
|
+
) {
|
|
109
|
+
const root = await services.posts.create({
|
|
110
|
+
format: "note",
|
|
111
|
+
title: "Secret diary",
|
|
112
|
+
body: tiptapDoc("Private root about lanterns"),
|
|
113
|
+
visibility: "private",
|
|
114
|
+
});
|
|
115
|
+
await services.posts.create({
|
|
116
|
+
format: "note",
|
|
117
|
+
body: tiptapDoc("Private reply about lanterns"),
|
|
118
|
+
replyToId: root.id,
|
|
119
|
+
});
|
|
120
|
+
await services.posts.create({
|
|
121
|
+
format: "note",
|
|
122
|
+
title: "Public notes",
|
|
123
|
+
body: tiptapDoc("Public post about lanterns"),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
it("leaves out private posts and replies in a private Thread for anonymous callers", async () => {
|
|
128
|
+
const { app, services } = createTestApp({
|
|
129
|
+
authenticated: false,
|
|
130
|
+
fts: true,
|
|
131
|
+
});
|
|
132
|
+
app.route("/api/search", searchApiRoutes);
|
|
133
|
+
await seedPrivateThread(services);
|
|
134
|
+
|
|
135
|
+
const res = await app.request("/api/search?q=lanterns");
|
|
136
|
+
expect(res.status).toBe(200);
|
|
137
|
+
const body = await res.json();
|
|
138
|
+
expect(body.count).toBe(1);
|
|
139
|
+
expect(body.results[0].title).toBe("Public notes");
|
|
140
|
+
|
|
141
|
+
const titleRes = await app.request("/api/search?q=Secret");
|
|
142
|
+
const titleBody = await titleRes.json();
|
|
143
|
+
expect(titleBody.count).toBe(0);
|
|
144
|
+
expect(JSON.stringify(titleBody)).not.toContain("Secret diary");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("answers a signed-in caller the same way", async () => {
|
|
148
|
+
const { app, services } = createTestApp({
|
|
149
|
+
authenticated: true,
|
|
150
|
+
fts: true,
|
|
151
|
+
});
|
|
152
|
+
app.route("/api/search", searchApiRoutes);
|
|
153
|
+
await seedPrivateThread(services);
|
|
154
|
+
|
|
155
|
+
const res = await app.request("/api/search?q=lanterns");
|
|
156
|
+
const body = await res.json();
|
|
157
|
+
expect(body.count).toBe(1);
|
|
158
|
+
expect(body.results[0].title).toBe("Public notes");
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe("limit", () => {
|
|
163
|
+
async function seedMatches(
|
|
164
|
+
services: ReturnType<typeof createTestApp>["services"],
|
|
165
|
+
) {
|
|
166
|
+
for (let i = 0; i < 3; i++) {
|
|
167
|
+
await services.posts.create({
|
|
168
|
+
format: "note",
|
|
169
|
+
body: tiptapDoc(`Lantern note number ${i}`),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
it.each(["-1", "0", "-500"])(
|
|
175
|
+
"raises limit=%s to one result",
|
|
176
|
+
async (limit) => {
|
|
177
|
+
const { app, services } = createTestApp({ fts: true });
|
|
178
|
+
app.route("/api/search", searchApiRoutes);
|
|
179
|
+
await seedMatches(services);
|
|
180
|
+
|
|
181
|
+
const res = await app.request(`/api/search?q=lantern&limit=${limit}`);
|
|
182
|
+
expect(res.status).toBe(200);
|
|
183
|
+
const body = await res.json();
|
|
184
|
+
expect(body.count).toBe(1);
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
it("uses the default for a limit that isn't a number", async () => {
|
|
189
|
+
const { app, services } = createTestApp({ fts: true });
|
|
190
|
+
app.route("/api/search", searchApiRoutes);
|
|
191
|
+
await seedMatches(services);
|
|
192
|
+
|
|
193
|
+
const res = await app.request("/api/search?q=lantern&limit=abc");
|
|
194
|
+
const body = await res.json();
|
|
195
|
+
expect(body.count).toBe(3);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("keeps a limit within range as given", async () => {
|
|
199
|
+
const { app, services } = createTestApp({ fts: true });
|
|
200
|
+
app.route("/api/search", searchApiRoutes);
|
|
201
|
+
await seedMatches(services);
|
|
202
|
+
|
|
203
|
+
const res = await app.request("/api/search?q=lantern&limit=2");
|
|
204
|
+
const body = await res.json();
|
|
205
|
+
expect(body.count).toBe(2);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
105
209
|
it("does not require authentication", async () => {
|
|
106
210
|
const { app } = createTestApp({ authenticated: false, fts: true });
|
|
107
211
|
app.route("/api/search", searchApiRoutes);
|
package/src/routes/api/search.ts
CHANGED
|
@@ -12,6 +12,32 @@ import { requirePublicApiAccess } from "../../middleware/public-content-access.j
|
|
|
12
12
|
|
|
13
13
|
type Env = { Bindings: Bindings; Variables: AppVariables };
|
|
14
14
|
|
|
15
|
+
const DEFAULT_SEARCH_LIMIT = 20;
|
|
16
|
+
const MAX_SEARCH_LIMIT = 50;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Read `limit` from the query string, clamped to 1–50.
|
|
20
|
+
*
|
|
21
|
+
* Clamped rather than rejected: the endpoint has always capped a large value
|
|
22
|
+
* at 50, and a small one gets the same treatment. Anything that isn't a number
|
|
23
|
+
* falls back to the default.
|
|
24
|
+
*
|
|
25
|
+
* @param value - Raw `limit` query parameter
|
|
26
|
+
* @returns A page size between 1 and 50
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* parseSearchLimit(undefined); // 20
|
|
31
|
+
* parseSearchLimit("-1"); // 1
|
|
32
|
+
* parseSearchLimit("500"); // 50
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function parseSearchLimit(value: string | undefined): number {
|
|
36
|
+
const parsed = value === undefined ? Number.NaN : Number.parseInt(value, 10);
|
|
37
|
+
if (Number.isNaN(parsed)) return DEFAULT_SEARCH_LIMIT;
|
|
38
|
+
return Math.min(Math.max(parsed, 1), MAX_SEARCH_LIMIT);
|
|
39
|
+
}
|
|
40
|
+
|
|
15
41
|
export const searchApiRoutes = new Hono<Env>();
|
|
16
42
|
|
|
17
43
|
searchApiRoutes.use("*", requirePublicApiAccess());
|
|
@@ -40,13 +66,16 @@ searchApiRoutes.get("/", async (c) => {
|
|
|
40
66
|
throw new ValidationError("Query too long");
|
|
41
67
|
}
|
|
42
68
|
|
|
43
|
-
const
|
|
44
|
-
const limit = limitParam ? Math.min(parseInt(limitParam, 10) || 20, 50) : 20;
|
|
69
|
+
const limit = parseSearchLimit(c.req.query("limit"));
|
|
45
70
|
|
|
46
71
|
try {
|
|
72
|
+
// One answer for every caller, as on `/api/public/*`: this endpoint is
|
|
73
|
+
// documented as public, so a session or token does not widen it. The
|
|
74
|
+
// author searches private posts on `/search` or through MCP.
|
|
47
75
|
const results = await c.var.services.search.search(query, {
|
|
48
76
|
limit,
|
|
49
77
|
status: ["published"],
|
|
78
|
+
includePrivate: false,
|
|
50
79
|
});
|
|
51
80
|
|
|
52
81
|
return c.json({
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* field at all writes nothing, since that last case is an older client or a
|
|
7
7
|
* scripted setup and reading it as a refusal would opt sites out that never
|
|
8
8
|
* said so — and then acts on it, on the same terms as the settings page's own
|
|
9
|
-
* switch.
|
|
9
|
+
* switch. The one exception is a language the directory does not list: the
|
|
10
|
+
* question was not on screen, so whatever the form sent is not an answer.
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
import { describe, expect, it, vi } from "vitest";
|
|
@@ -144,6 +145,33 @@ describe("POST /setup, the Discover answer", () => {
|
|
|
144
145
|
expect(updateDiscoverSetting).not.toHaveBeenCalled();
|
|
145
146
|
});
|
|
146
147
|
|
|
148
|
+
// The box is off screen for a language the directory does not list, but its
|
|
149
|
+
// signal still goes out holding the starting state — ticked on hosted Jant,
|
|
150
|
+
// clear on a self-hosted install. Neither is an answer anyone gave.
|
|
151
|
+
it.each([true, false])(
|
|
152
|
+
"writes nothing for a language the directory does not list (box %s)",
|
|
153
|
+
async (discover) => {
|
|
154
|
+
const { app, updateDiscoverSetting, announceToDiscover, pending } =
|
|
155
|
+
createSetupApp();
|
|
156
|
+
|
|
157
|
+
await post(app, { contentLanguage: "en", discover });
|
|
158
|
+
await Promise.all(pending);
|
|
159
|
+
|
|
160
|
+
expect(updateDiscoverSetting).not.toHaveBeenCalled();
|
|
161
|
+
expect(announceToDiscover).not.toHaveBeenCalled();
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
it("takes the answer for Traditional Chinese as well", async () => {
|
|
166
|
+
const { app, updateDiscoverSetting } = createSetupApp();
|
|
167
|
+
|
|
168
|
+
await post(app, { contentLanguage: "zh-Hant", discover: true });
|
|
169
|
+
|
|
170
|
+
expect(updateDiscoverSetting).toHaveBeenCalledWith("latest", {
|
|
171
|
+
demoMode: false,
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
147
175
|
// The answer takes effect now, not when the author next happens to open a
|
|
148
176
|
// settings page they have no reason to open. A directory decides eligibility
|
|
149
177
|
// for itself and re-reads the feed on its own schedule, so a site with
|
|
@@ -13,7 +13,11 @@ import { renderToString } from "hono/jsx/dom/server";
|
|
|
13
13
|
import { describe, expect, it } from "vitest";
|
|
14
14
|
import { I18nProvider } from "../../../i18n/context.js";
|
|
15
15
|
import { createI18n } from "../../../i18n/i18n.js";
|
|
16
|
-
import
|
|
16
|
+
import {
|
|
17
|
+
isDiscoverLanguage,
|
|
18
|
+
type DiscoverPageUrls,
|
|
19
|
+
} from "../../../lib/discover.js";
|
|
20
|
+
import { SUPPORTED_LOCALE_TAGS } from "../../../i18n/supported-locales.js";
|
|
17
21
|
import { getDiscoverCopy } from "../../../ui/dash/settings/discover-copy.js";
|
|
18
22
|
import { SetupContent } from "../setup.js";
|
|
19
23
|
|
|
@@ -26,6 +30,23 @@ const PAGES: DiscoverPageUrls = {
|
|
|
26
30
|
rules: "https://jant.me/discover/about",
|
|
27
31
|
};
|
|
28
32
|
|
|
33
|
+
/** The Discover field's opening tag, which carries whether it is on screen. */
|
|
34
|
+
function discoverFieldTag(html: string): string {
|
|
35
|
+
const tag = html.match(/<div class="field mt-2"[^>]*>/)?.[0];
|
|
36
|
+
if (!tag) throw new Error("No Discover field in the rendered form");
|
|
37
|
+
return tag;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Undo the attribute escaping the renderer applies. */
|
|
41
|
+
function unescapeAttribute(value: string): string {
|
|
42
|
+
return value
|
|
43
|
+
.replace(/"/g, '"')
|
|
44
|
+
.replace(/'/g, "'")
|
|
45
|
+
.replace(/</g, "<")
|
|
46
|
+
.replace(/>/g, ">")
|
|
47
|
+
.replace(/&/g, "&");
|
|
48
|
+
}
|
|
49
|
+
|
|
29
50
|
function render(props: SetupProps): string {
|
|
30
51
|
const i18n = createI18n("en");
|
|
31
52
|
const c = {
|
|
@@ -150,6 +171,43 @@ describe("SetupContent — the Discover question", () => {
|
|
|
150
171
|
expect(html).toContain("discover: false");
|
|
151
172
|
});
|
|
152
173
|
|
|
174
|
+
// The directory lists Chinese only. Asking anyone else leads nowhere, and on
|
|
175
|
+
// hosted Jant the box would arrive ticked.
|
|
176
|
+
it("stays off screen for a language the directory does not list", () => {
|
|
177
|
+
const tag = discoverFieldTag(render({ ...base, contentLanguage: "en" }));
|
|
178
|
+
|
|
179
|
+
expect(tag).toContain('style="display:none"');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("is on screen from the start for a language the directory lists", () => {
|
|
183
|
+
const tag = discoverFieldTag(
|
|
184
|
+
render({ ...base, contentLanguage: "zh-Hant" }),
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
expect(tag).not.toContain("display:none");
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// The field follows the picker on the client and the answer is filtered on
|
|
191
|
+
// the server, so the two have to read the language the same way. The
|
|
192
|
+
// expression is plain JavaScript once Datastar has swapped its signal in, and
|
|
193
|
+
// `$contentLanguage` is a valid parameter name, so it runs here as written.
|
|
194
|
+
it("follows the picker the way the server reads the language", () => {
|
|
195
|
+
const tag = discoverFieldTag(render(base));
|
|
196
|
+
const expression = unescapeAttribute(
|
|
197
|
+
tag.match(/data-show="([^"]*)"/)?.[1] ?? "",
|
|
198
|
+
);
|
|
199
|
+
const shows = new Function(
|
|
200
|
+
"$contentLanguage",
|
|
201
|
+
`return (${expression});`,
|
|
202
|
+
) as (language: string) => boolean;
|
|
203
|
+
|
|
204
|
+
for (const language of [...SUPPORTED_LOCALE_TAGS, "zh", "zh-TW"]) {
|
|
205
|
+
expect(shows(language), language).toBe(isDiscoverLanguage(language));
|
|
206
|
+
}
|
|
207
|
+
expect(shows("zh-Hans")).toBe(true);
|
|
208
|
+
expect(shows("en")).toBe(false);
|
|
209
|
+
});
|
|
210
|
+
|
|
153
211
|
// One control appearing twice should not describe itself two ways: the
|
|
154
212
|
// label is the settings page's, and the help line is the settings page's
|
|
155
213
|
// opening sentence rather than a wording of setup's own. The delay, the
|
|
@@ -67,8 +67,10 @@ import { toPublicPath } from "../../lib/url.js";
|
|
|
67
67
|
import { ONBOARDING_STATUS } from "../../lib/constants.js";
|
|
68
68
|
import { announceInBackground } from "../discover-announce.js";
|
|
69
69
|
import {
|
|
70
|
+
DISCOVER_LANGUAGES,
|
|
70
71
|
discoverIntroRuns,
|
|
71
72
|
getDiscoverPageUrls,
|
|
73
|
+
isDiscoverLanguage,
|
|
72
74
|
resolveDiscoverMode,
|
|
73
75
|
type DiscoverPageUrls,
|
|
74
76
|
} from "../../lib/discover.js";
|
|
@@ -142,6 +144,14 @@ const LocaleField: FC<{
|
|
|
142
144
|
);
|
|
143
145
|
};
|
|
144
146
|
|
|
147
|
+
/**
|
|
148
|
+
* `isDiscoverLanguage` as a Datastar expression over the language signal, so
|
|
149
|
+
* the Discover question follows the picker without a round trip. The list is
|
|
150
|
+
* the same constant the server reads, and a test holds the two readings of it
|
|
151
|
+
* together.
|
|
152
|
+
*/
|
|
153
|
+
const DISCOVER_LANGUAGE_EXPRESSION = `${JSON.stringify(DISCOVER_LANGUAGES)}.includes($contentLanguage.split('-')[0].toLowerCase())`;
|
|
154
|
+
|
|
145
155
|
/**
|
|
146
156
|
* The one question setup asks about the world outside this site.
|
|
147
157
|
*
|
|
@@ -151,6 +161,11 @@ const LocaleField: FC<{
|
|
|
151
161
|
* settings page's own: one control appearing twice should not describe itself
|
|
152
162
|
* two ways.
|
|
153
163
|
*
|
|
164
|
+
* Only on screen while the chosen language is one the directory lists. For any
|
|
165
|
+
* other, learning the directory exists leads nowhere, and on hosted Jant the box
|
|
166
|
+
* would arrive ticked — a promise nobody keeps. It follows the language picker
|
|
167
|
+
* above it, since both are answered on the same screen.
|
|
168
|
+
*
|
|
154
169
|
* The words come from the same `getDiscoverCopy` the settings page uses,
|
|
155
170
|
* which is what keeps the two surfaces from drifting when either is edited.
|
|
156
171
|
* The label is the settings page's; the help line is the settings page's
|
|
@@ -164,14 +179,22 @@ const DiscoverField: FC<{
|
|
|
164
179
|
copy: DiscoverCopy;
|
|
165
180
|
/** The directory's pages, or null when this deployment announces to none. */
|
|
166
181
|
pages: DiscoverPageUrls | null;
|
|
167
|
-
|
|
182
|
+
/** Whether the language the form opens with is one the directory lists. */
|
|
183
|
+
shown: boolean;
|
|
184
|
+
}> = ({ copy, pages, shown }) => {
|
|
168
185
|
const runs = discoverIntroRuns(copy.about, copy, pages);
|
|
169
186
|
|
|
170
187
|
return (
|
|
171
188
|
// Held a little further from the field above it than the form's own gap:
|
|
172
189
|
// every other field on this screen is about the site itself, and this one
|
|
173
|
-
// is about the world outside it.
|
|
174
|
-
|
|
190
|
+
// is about the world outside it. Hidden in the markup as well as by
|
|
191
|
+
// `data-show`, so a form opening in English never flashes the question
|
|
192
|
+
// before Datastar starts.
|
|
193
|
+
<div
|
|
194
|
+
class="field mt-2"
|
|
195
|
+
data-show={DISCOVER_LANGUAGE_EXPRESSION}
|
|
196
|
+
style={shown ? undefined : "display:none"}
|
|
197
|
+
>
|
|
175
198
|
{/* Classes copied from the settings page's own Discover checkbox
|
|
176
199
|
(`jant-settings-general.ts`), so the control a hosted author meets here
|
|
177
200
|
and the one they find later in Settings are the same object. */}
|
|
@@ -410,6 +433,8 @@ export type SetupContentProps = {
|
|
|
410
433
|
*
|
|
411
434
|
* False where the answer could not be honoured — a demo site, or feeds
|
|
412
435
|
* switched off — and a control nobody can act on is worse than none.
|
|
436
|
+
* Where it is true, the question still waits for a language the
|
|
437
|
+
* directory lists; see `DiscoverField`.
|
|
413
438
|
*/
|
|
414
439
|
discoverAvailable: boolean;
|
|
415
440
|
/**
|
|
@@ -474,11 +499,15 @@ export const SetupContent: FC<SetupContentProps> = (props) => {
|
|
|
474
499
|
}),
|
|
475
500
|
);
|
|
476
501
|
|
|
477
|
-
//
|
|
478
|
-
//
|
|
502
|
+
// The signal exists even when the question is not asked, so the form can
|
|
503
|
+
// name it unconditionally; `discoverAvailable` decides whether the control
|
|
479
504
|
// appears, and an absent field simply sends the default back.
|
|
480
505
|
const discoverField = discoverAvailable ? (
|
|
481
|
-
<DiscoverField
|
|
506
|
+
<DiscoverField
|
|
507
|
+
copy={getDiscoverCopy(i18n)}
|
|
508
|
+
pages={discoverPages}
|
|
509
|
+
shown={isDiscoverLanguage(contentLanguage)}
|
|
510
|
+
/>
|
|
482
511
|
) : null;
|
|
483
512
|
|
|
484
513
|
const signals = [
|
|
@@ -630,6 +659,12 @@ export const SetupContent: FC<SetupContentProps> = (props) => {
|
|
|
630
659
|
* is the whole point of asking. An absent field is not a refusal — an older
|
|
631
660
|
* client or a scripted setup sends none — and leaves the default in force.
|
|
632
661
|
*
|
|
662
|
+
* Neither is a value sent with a language the directory does not list. The
|
|
663
|
+
* question was not on screen for it, but the signal behind the hidden box still
|
|
664
|
+
* went out holding its starting state, and storing that would record an answer
|
|
665
|
+
* to a question nobody was asked. It is dropped, and the default stays in
|
|
666
|
+
* force — the same as sending nothing.
|
|
667
|
+
*
|
|
633
668
|
* A yes is announced immediately, on the same terms as the settings page's own
|
|
634
669
|
* switch. A directory decides eligibility for itself and re-reads the feed on
|
|
635
670
|
* its own schedule, so a site with nothing published yet loses nothing by
|
|
@@ -644,12 +679,16 @@ export const SetupContent: FC<SetupContentProps> = (props) => {
|
|
|
644
679
|
* page's status block reads it back with a Retry beside it.
|
|
645
680
|
*
|
|
646
681
|
* @param c - The setup request, for its services and its config
|
|
647
|
-
* @param
|
|
682
|
+
* @param answers - The validated answers: the checkbox, or undefined when the
|
|
683
|
+
* form carried no field, and the language it was answered for
|
|
648
684
|
*/
|
|
649
685
|
async function storeDiscoverAnswer(
|
|
650
686
|
c: Context<Env>,
|
|
651
|
-
|
|
687
|
+
answers: SetupLanguageAnswers,
|
|
652
688
|
): Promise<void> {
|
|
689
|
+
const answer = isDiscoverLanguage(answers.contentLanguage)
|
|
690
|
+
? answers.discover
|
|
691
|
+
: undefined;
|
|
653
692
|
if (answer === undefined) return;
|
|
654
693
|
const stored = answer ? "latest" : "off";
|
|
655
694
|
const { shouldAnnounce } =
|
|
@@ -959,7 +998,7 @@ async function storeSiteAnswers(
|
|
|
959
998
|
},
|
|
960
999
|
);
|
|
961
1000
|
|
|
962
|
-
await storeDiscoverAnswer(c, answers
|
|
1001
|
+
await storeDiscoverAnswer(c, answers);
|
|
963
1002
|
|
|
964
1003
|
return dsRedirect(toPublicPath("/", c.var.appConfig.sitePathPrefix));
|
|
965
1004
|
}
|