@abraca/junis 2.84.0 → 2.86.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/dist/module.d.mts +17 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +270 -22
- package/dist/runtime/assets/css/jun.css +1 -1
- package/dist/runtime/components/JunBlobBackdrop.client.vue +1 -1
- package/dist/runtime/components/JunCampfirePresence.client.vue +75 -10
- package/dist/runtime/components/JunCollectionIntro.d.vue.ts +11 -0
- package/dist/runtime/components/JunCollectionIntro.vue +45 -0
- package/dist/runtime/components/JunCollectionIntro.vue.d.ts +11 -0
- package/dist/runtime/components/JunConfigRow.d.vue.ts +43 -0
- package/dist/runtime/components/JunConfigRow.vue +34 -0
- package/dist/runtime/components/JunConfigRow.vue.d.ts +43 -0
- package/dist/runtime/components/JunFooter.vue +1 -1
- package/dist/runtime/components/JunHead.vue +37 -5
- package/dist/runtime/components/JunHorizontalTimeline.d.vue.ts +30 -0
- package/dist/runtime/components/JunHorizontalTimeline.vue.d.ts +30 -0
- package/dist/runtime/components/JunLinksRow.d.vue.ts +16 -1
- package/dist/runtime/components/JunLinksRow.vue +17 -7
- package/dist/runtime/components/JunLinksRow.vue.d.ts +16 -1
- package/dist/runtime/components/JunLogo.vue +10 -45
- package/dist/runtime/components/JunMedia.client.d.vue.ts +1 -1
- package/dist/runtime/components/JunMedia.client.vue.d.ts +1 -1
- package/dist/runtime/components/JunNavigation.vue +21 -4
- package/dist/runtime/components/JunNoteLinks.d.vue.ts +6 -0
- package/dist/runtime/components/JunNoteLinks.vue +57 -0
- package/dist/runtime/components/JunNoteLinks.vue.d.ts +6 -0
- package/dist/runtime/components/JunPageHero.d.vue.ts +8 -2
- package/dist/runtime/components/JunPageHero.vue +15 -3
- package/dist/runtime/components/JunPageHero.vue.d.ts +8 -2
- package/dist/runtime/components/JunPatternBackdrop.client.vue +1 -1
- package/dist/runtime/components/JunReaders.d.vue.ts +11 -0
- package/dist/runtime/components/JunReaders.vue +99 -0
- package/dist/runtime/components/JunReaders.vue.d.ts +11 -0
- package/dist/runtime/components/JunSearch.client.vue +2 -2
- package/dist/runtime/components/JunSectionPresence.client.d.vue.ts +17 -0
- package/dist/runtime/components/JunSectionPresence.client.vue +99 -0
- package/dist/runtime/components/JunSectionPresence.client.vue.d.ts +17 -0
- package/dist/runtime/components/JunShaderBackdrop.client.vue +1 -1
- package/dist/runtime/components/JunThreadComposer.d.vue.ts +37 -0
- package/dist/runtime/components/JunThreadComposer.vue +54 -0
- package/dist/runtime/components/JunThreadComposer.vue.d.ts +37 -0
- package/dist/runtime/components/JunTravellersChip.vue +35 -5
- package/dist/runtime/components/JunVideoEmbed.client.d.vue.ts +1 -1
- package/dist/runtime/components/JunVideoEmbed.client.vue.d.ts +1 -1
- package/dist/runtime/components/JunViewControl.d.vue.ts +29 -0
- package/dist/runtime/components/JunViewControl.vue +340 -0
- package/dist/runtime/components/JunViewControl.vue.d.ts +29 -0
- package/dist/runtime/components/JunViewControls.d.vue.ts +27 -0
- package/dist/runtime/components/JunViewControls.vue +94 -0
- package/dist/runtime/components/JunViewControls.vue.d.ts +27 -0
- package/dist/runtime/components/renderers/JunAppsRenderer.vue +45 -4
- package/dist/runtime/components/renderers/JunCinemaRenderer.vue +42 -4
- package/dist/runtime/components/renderers/JunConfigRenderer.vue +362 -239
- package/dist/runtime/components/renderers/JunCourseRenderer.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/JunCourseRenderer.vue +229 -0
- package/dist/runtime/components/renderers/JunCourseRenderer.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/JunCvRenderer.vue +44 -6
- package/dist/runtime/components/renderers/JunDeckRenderer.d.vue.ts +9 -0
- package/dist/runtime/components/renderers/JunDeckRenderer.vue +370 -0
- package/dist/runtime/components/renderers/JunDeckRenderer.vue.d.ts +9 -0
- package/dist/runtime/components/renderers/JunEntryRenderer.vue +157 -31
- package/dist/runtime/components/renderers/JunFestivalRenderer.vue +42 -5
- package/dist/runtime/components/renderers/JunGardenRenderer.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/JunGardenRenderer.vue +280 -0
- package/dist/runtime/components/renderers/JunGardenRenderer.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/JunGuestbookRenderer.vue +96 -14
- package/dist/runtime/components/renderers/JunHomeRenderer.vue +31 -132
- package/dist/runtime/components/renderers/JunItemRenderer.d.vue.ts +10 -0
- package/dist/runtime/components/renderers/JunItemRenderer.vue +398 -0
- package/dist/runtime/components/renderers/JunItemRenderer.vue.d.ts +10 -0
- package/dist/runtime/components/renderers/JunJournalRenderer.vue +141 -11
- package/dist/runtime/components/renderers/JunLibraryRenderer.vue +295 -12
- package/dist/runtime/components/renderers/JunLinksRenderer.vue +33 -1
- package/dist/runtime/components/renderers/JunLiveRenderer.vue +38 -2
- package/dist/runtime/components/renderers/JunMosaicRenderer.vue +3 -2
- package/dist/runtime/components/renderers/JunMovieRenderer.vue +32 -5
- package/dist/runtime/components/renderers/JunNowRenderer.vue +40 -7
- package/dist/runtime/components/renderers/JunPollRenderer.d.vue.ts +9 -0
- package/dist/runtime/components/renderers/JunPollRenderer.vue +231 -0
- package/dist/runtime/components/renderers/JunPollRenderer.vue.d.ts +9 -0
- package/dist/runtime/components/renderers/JunProjectRenderer.vue +74 -18
- package/dist/runtime/components/renderers/JunServicesRenderer.vue +40 -2
- package/dist/runtime/components/renderers/JunStatsRenderer.vue +37 -50
- package/dist/runtime/components/renderers/JunThreadRenderer.d.vue.ts +9 -0
- package/dist/runtime/components/renderers/JunThreadRenderer.vue +304 -0
- package/dist/runtime/components/renderers/JunThreadRenderer.vue.d.ts +9 -0
- package/dist/runtime/components/renderers/JunTrackRenderer.vue +32 -4
- package/dist/runtime/components/renderers/JunUsesRenderer.vue +57 -13
- package/dist/runtime/components/renderers/JunWallRenderer.vue +60 -5
- package/dist/runtime/composables/useJunDeck.d.ts +66 -0
- package/dist/runtime/composables/useJunDeck.js +61 -0
- package/dist/runtime/composables/useJunDocPage.d.ts +14 -11
- package/dist/runtime/composables/useJunDocPage.js +67 -3
- package/dist/runtime/composables/useJunFollow.d.ts +65 -9
- package/dist/runtime/composables/useJunFollow.js +237 -20
- package/dist/runtime/composables/useJunGarden.d.ts +67 -0
- package/dist/runtime/composables/useJunGarden.js +92 -0
- package/dist/runtime/composables/useJunOptions.d.ts +1 -0
- package/dist/runtime/composables/useJunPresence.d.ts +26 -0
- package/dist/runtime/composables/useJunPresence.js +9 -2
- package/dist/runtime/composables/useJunSections.d.ts +73 -0
- package/dist/runtime/composables/useJunSections.js +117 -0
- package/dist/runtime/composables/useJunSettings.d.ts +1 -1
- package/dist/runtime/composables/useJunSettings.js +5 -1
- package/dist/runtime/composables/useJunSiteConfig.d.ts +37 -0
- package/dist/runtime/composables/useJunTheme.js +49 -50
- package/dist/runtime/composables/useJunViewOptions.d.ts +85 -0
- package/dist/runtime/composables/useJunViewOptions.js +63 -0
- package/dist/runtime/pages/doc.vue +14 -8
- package/dist/runtime/plugins/jun-sw.client.d.ts +2 -0
- package/dist/runtime/plugins/jun-sw.client.js +36 -0
- package/dist/runtime/server/api/health.get.d.ts +19 -0
- package/dist/runtime/server/api/health.get.js +40 -0
- package/dist/runtime/server/api/links.get.d.ts +19 -0
- package/dist/runtime/server/api/links.get.js +37 -0
- package/dist/runtime/server/api/resolve/[...slug].get.d.ts +9 -0
- package/dist/runtime/server/api/resolve/[...slug].get.js +5 -0
- package/dist/runtime/server/api/stats.get.js +2 -1
- package/dist/runtime/server/janitor/junJanitorChores.js +8 -0
- package/dist/runtime/server/plugins/jun-bootstrap.js +103 -15
- package/dist/runtime/server/plugins/jun-doc-cache.js +42 -4
- package/dist/runtime/server/plugins/jun-janitor.js +9 -1
- package/dist/runtime/server/plugins/jun-rpc.js +293 -0
- package/dist/runtime/server/plugins/jun-watchdog.d.ts +2 -0
- package/dist/runtime/server/plugins/jun-watchdog.js +54 -0
- package/dist/runtime/server/routes/jun-icon.png.get.d.ts +2 -0
- package/dist/runtime/server/routes/jun-icon.png.get.js +25 -0
- package/dist/runtime/server/routes/jun-icon.svg.get.d.ts +2 -0
- package/dist/runtime/server/routes/jun-icon.svg.get.js +9 -0
- package/dist/runtime/server/routes/jun-splash.png.get.d.ts +2 -0
- package/dist/runtime/server/routes/jun-splash.png.get.js +37 -0
- package/dist/runtime/server/routes/jun-sw.js.get.d.ts +2 -0
- package/dist/runtime/server/routes/jun-sw.js.get.js +126 -0
- package/dist/runtime/server/routes/manifest.webmanifest.get.d.ts +24 -0
- package/dist/runtime/server/routes/manifest.webmanifest.get.js +51 -0
- package/dist/runtime/server/routes/sitemap.xml.get.js +2 -0
- package/dist/runtime/server/utils/junBoot.d.ts +1 -0
- package/dist/runtime/server/utils/junBoot.js +4 -0
- package/dist/runtime/server/utils/junBrand.d.ts +4 -0
- package/dist/runtime/server/utils/junBrand.js +9 -0
- package/dist/runtime/server/utils/junCache.d.ts +17 -0
- package/dist/runtime/server/utils/junCache.js +5 -0
- package/dist/runtime/server/utils/junIcon.d.ts +44 -0
- package/dist/runtime/server/utils/junIcon.js +374 -0
- package/dist/runtime/server/utils/junSeedGate.d.ts +68 -0
- package/dist/runtime/server/utils/junSeedGate.js +41 -0
- package/dist/runtime/types.d.ts +82 -3
- package/dist/runtime/utils/junCourse.d.ts +106 -0
- package/dist/runtime/utils/junCourse.js +65 -0
- package/dist/runtime/utils/junGarden.d.ts +193 -0
- package/dist/runtime/utils/junGarden.js +233 -0
- package/dist/runtime/utils/junIdentity.d.ts +121 -0
- package/dist/runtime/utils/junIdentity.js +115 -0
- package/dist/runtime/utils/junMark.d.ts +254 -0
- package/dist/runtime/utils/junMark.js +169 -0
- package/dist/runtime/utils/junMetaSchemas.js +8 -1
- package/dist/runtime/utils/junModeration.d.ts +67 -0
- package/dist/runtime/utils/junModeration.js +20 -0
- package/dist/runtime/utils/junMotion.d.ts +26 -0
- package/dist/runtime/utils/junMotion.js +31 -0
- package/dist/runtime/utils/junPeople.d.ts +43 -0
- package/dist/runtime/utils/junPeople.js +9 -0
- package/dist/runtime/utils/junPoll.d.ts +79 -0
- package/dist/runtime/utils/junPoll.js +82 -0
- package/dist/runtime/utils/junReadiness.d.ts +131 -0
- package/dist/runtime/utils/junReadiness.js +69 -0
- package/dist/runtime/utils/junSections.d.ts +115 -0
- package/dist/runtime/utils/junSections.js +45 -0
- package/dist/runtime/utils/junSlides.d.ts +66 -0
- package/dist/runtime/utils/junSlides.js +47 -0
- package/dist/runtime/utils/junThread.d.ts +81 -0
- package/dist/runtime/utils/junThread.js +75 -0
- package/dist/runtime/utils/junViewSpecs.d.ts +671 -0
- package/dist/runtime/utils/junViewSpecs.js +534 -0
- package/dist/runtime/utils/junViewValues.d.ts +125 -0
- package/dist/runtime/utils/junViewValues.js +104 -0
- package/dist/types.d.mts +1 -1
- package/package.json +5 -1
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import * as Y from "yjs";
|
|
2
|
+
import {
|
|
3
|
+
junCapBallots,
|
|
4
|
+
junMyBallot,
|
|
5
|
+
junNextBallot,
|
|
6
|
+
junPollBallots,
|
|
7
|
+
junPollChoices,
|
|
8
|
+
junTallyVotes
|
|
9
|
+
} from "../../utils/junPoll.js";
|
|
10
|
+
import { junCanReplyTo } from "../../utils/junThread.js";
|
|
11
|
+
import { junCapProgress, junCourseProgress, junNextProgress } from "../../utils/junCourse.js";
|
|
2
12
|
import { AbracadabraProvider } from "@abraca/dabra";
|
|
3
13
|
import { defineNitroPlugin, useRuntimeConfig } from "nitropack/runtime";
|
|
4
14
|
const SYNC_TIMEOUT_MS = 8e3;
|
|
@@ -50,6 +60,35 @@ const reactSchema = {
|
|
|
50
60
|
return { docId: v.docId };
|
|
51
61
|
}
|
|
52
62
|
};
|
|
63
|
+
const voteSchema = {
|
|
64
|
+
parse(value) {
|
|
65
|
+
const v = value;
|
|
66
|
+
if (typeof v?.docId !== "string" || !v.docId) throw new Error("docId required");
|
|
67
|
+
const choice = typeof v?.choice === "number" ? v.choice : Number(v?.choice);
|
|
68
|
+
if (!Number.isInteger(choice) || choice < 0 || choice > 64) throw new Error("choice must be an index");
|
|
69
|
+
return { docId: v.docId, choice };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const postSchema = {
|
|
73
|
+
parse(value) {
|
|
74
|
+
const v = value;
|
|
75
|
+
if (typeof v?.docId !== "string" || !v.docId) throw new Error("docId required");
|
|
76
|
+
const message = cleanText(String(v?.message ?? ""));
|
|
77
|
+
if (!message) throw new Error("message is empty");
|
|
78
|
+
if (message.length > MAX_MESSAGE) throw new Error(`message too long (max ${MAX_MESSAGE})`);
|
|
79
|
+
const handle = cleanText(String(v.handle ?? "")).replace(/\n/g, " ").slice(0, MAX_HANDLE) || "Traveller";
|
|
80
|
+
const replyTo = typeof v?.replyTo === "string" && v.replyTo ? v.replyTo : null;
|
|
81
|
+
return { docId: v.docId, message, handle, replyTo };
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const stepSchema = {
|
|
85
|
+
parse(value) {
|
|
86
|
+
const v = value;
|
|
87
|
+
if (typeof v?.docId !== "string" || !v.docId) throw new Error("docId required");
|
|
88
|
+
if (typeof v?.stepId !== "string" || !v.stepId) throw new Error("stepId required");
|
|
89
|
+
return { docId: v.docId, stepId: v.stepId };
|
|
90
|
+
}
|
|
91
|
+
};
|
|
53
92
|
export default defineNitroPlugin((nitroApp) => {
|
|
54
93
|
const jun = useRuntimeConfig().public.jun;
|
|
55
94
|
if (!jun?.features?.rpc) return;
|
|
@@ -408,6 +447,260 @@ export default defineNitroPlugin((nitroApp) => {
|
|
|
408
447
|
}
|
|
409
448
|
}),
|
|
410
449
|
// @ts-expect-error — server auto-import from @abraca/nuxt
|
|
450
|
+
defineRpcHandler({
|
|
451
|
+
method: "jun.thread.post@1",
|
|
452
|
+
schema: postSchema,
|
|
453
|
+
/**
|
|
454
|
+
* Post to a `jun-thread`.
|
|
455
|
+
*
|
|
456
|
+
* The guestbook's signature with one more field. Every post is a
|
|
457
|
+
* hidden child DOCUMENT rather than an entry in a blob of meta, so
|
|
458
|
+
* moderation, the trash, search exclusion and the permission cascade
|
|
459
|
+
* all work without inventing anything — and adding a reply never
|
|
460
|
+
* rewrites somebody else's words, which a nested structure in one
|
|
461
|
+
* document would do on every post.
|
|
462
|
+
*/
|
|
463
|
+
async handler({ docId, message, handle, replyTo }, ctx) {
|
|
464
|
+
if (siteConfig().guestbookEnabled === false) {
|
|
465
|
+
throw new RpcError("DISABLED", "the conversation is closed right now");
|
|
466
|
+
}
|
|
467
|
+
const page = plain(sharedTree().get(docId));
|
|
468
|
+
const threadType = jun?.typeIds?.thread;
|
|
469
|
+
if (!page || page.trashed || threadType && page.type !== threadType) {
|
|
470
|
+
throw new RpcError("NOT_FOUND", "no conversation here");
|
|
471
|
+
}
|
|
472
|
+
if (page.meta?.threadClosed === true) {
|
|
473
|
+
throw new RpcError("DISABLED", "this conversation is closed");
|
|
474
|
+
}
|
|
475
|
+
const siblings = [];
|
|
476
|
+
const now = Date.now();
|
|
477
|
+
let mineRecent = 0;
|
|
478
|
+
let recentAny = 0;
|
|
479
|
+
sharedTree().forEach((e, id2) => {
|
|
480
|
+
const entry = plain(e);
|
|
481
|
+
if (!entry || entry.parentId !== docId || entry.trashed) return;
|
|
482
|
+
siblings.push({ id: id2, parentId: entry.parentId, trashed: entry.trashed, meta: entry.meta });
|
|
483
|
+
const date = typeof entry.meta?.date === "number" ? entry.meta.date : 0;
|
|
484
|
+
if (date > now - FLOOD_WINDOW_MS) recentAny++;
|
|
485
|
+
if (entry.meta?.signerId === ctx.from && date > now - PER_SIGNER_COOLDOWN_MS) mineRecent++;
|
|
486
|
+
});
|
|
487
|
+
if (!junCanReplyTo(siblings, docId, replyTo)) {
|
|
488
|
+
throw new RpcError("NOT_FOUND", "that post is not in this conversation");
|
|
489
|
+
}
|
|
490
|
+
if (mineRecent > 0) {
|
|
491
|
+
throw new RpcError("RATE_LIMITED", "one at a time \u2014 try again in a moment");
|
|
492
|
+
}
|
|
493
|
+
if (recentAny >= FLOOD_MAX) {
|
|
494
|
+
throw new RpcError("RATE_LIMITED", "this conversation is busy \u2014 try again in a minute");
|
|
495
|
+
}
|
|
496
|
+
const id = crypto.randomUUID();
|
|
497
|
+
await withRootTree(
|
|
498
|
+
(tree) => {
|
|
499
|
+
tree.set(id, {
|
|
500
|
+
label: handle,
|
|
501
|
+
type: "doc",
|
|
502
|
+
parentId: docId,
|
|
503
|
+
order: now,
|
|
504
|
+
createdAt: now,
|
|
505
|
+
updatedAt: now,
|
|
506
|
+
meta: {
|
|
507
|
+
hidden: true,
|
|
508
|
+
message,
|
|
509
|
+
// The SERVER stamps who wrote this, never the client.
|
|
510
|
+
signerId: ctx.from,
|
|
511
|
+
signerHandle: handle,
|
|
512
|
+
date: now,
|
|
513
|
+
...replyTo ? { replyTo } : {}
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
},
|
|
517
|
+
() => !!sharedTree().get(id)
|
|
518
|
+
);
|
|
519
|
+
try {
|
|
520
|
+
await runner.client.createChild(docId, { child_id: id, label: handle, doc_type: "doc" });
|
|
521
|
+
} catch (err) {
|
|
522
|
+
console.warn(`[jun:rpc] register post ${id} failed:`, err?.message ?? err);
|
|
523
|
+
}
|
|
524
|
+
return { id, date: now };
|
|
525
|
+
}
|
|
526
|
+
}),
|
|
527
|
+
// @ts-expect-error — server auto-import from @abraca/nuxt
|
|
528
|
+
defineRpcHandler({
|
|
529
|
+
method: "jun.course.step@1",
|
|
530
|
+
schema: stepSchema,
|
|
531
|
+
/**
|
|
532
|
+
* Tick (or untick) a step of a `jun-course`.
|
|
533
|
+
*
|
|
534
|
+
* The fourth write path of this shape, and the one where the rule
|
|
535
|
+
* matters most: progress is a claim about a PERSON, so it is keyed by
|
|
536
|
+
* `ctx.from` — the identity the server stamped. A second tab, a
|
|
537
|
+
* reload and a reconnect are one learner, and nobody can tick a step
|
|
538
|
+
* on somebody else's behalf.
|
|
539
|
+
*
|
|
540
|
+
* The step must be a CHILD of the course. Without that check any
|
|
541
|
+
* document id would be storable as progress, which turns a narrow
|
|
542
|
+
* write path into a general-purpose one — the same reason the poll
|
|
543
|
+
* checks its choice index and the thread checks its parent.
|
|
544
|
+
*/
|
|
545
|
+
async handler({ docId, stepId }, ctx) {
|
|
546
|
+
if (siteConfig().reactionsEnabled === false) {
|
|
547
|
+
throw new RpcError("DISABLED", "this course is not taking progress right now");
|
|
548
|
+
}
|
|
549
|
+
const page = plain(sharedTree().get(docId));
|
|
550
|
+
const courseType = jun?.typeIds?.course;
|
|
551
|
+
if (!page || page.trashed || courseType && page.type !== courseType) {
|
|
552
|
+
throw new RpcError("NOT_FOUND", "no course here");
|
|
553
|
+
}
|
|
554
|
+
const stepIds = () => {
|
|
555
|
+
const out = [];
|
|
556
|
+
sharedTree().forEach((e, id) => {
|
|
557
|
+
const entry2 = plain(e);
|
|
558
|
+
if (!entry2 || entry2.parentId !== docId || entry2.trashed) return;
|
|
559
|
+
out.push({ id, order: typeof entry2.order === "number" ? entry2.order : 0 });
|
|
560
|
+
});
|
|
561
|
+
return out.sort((a, b) => a.order - b.order).map((step) => step.id);
|
|
562
|
+
};
|
|
563
|
+
if (!stepIds().includes(stepId)) {
|
|
564
|
+
throw new RpcError("NOT_FOUND", "that step is not part of this course");
|
|
565
|
+
}
|
|
566
|
+
let stored = [];
|
|
567
|
+
let refused = false;
|
|
568
|
+
await withRootTree(
|
|
569
|
+
(tree) => {
|
|
570
|
+
const entry2 = plain(tree.get(docId));
|
|
571
|
+
if (!entry2) {
|
|
572
|
+
throw new RpcError("NOT_FOUND", "no course here");
|
|
573
|
+
}
|
|
574
|
+
const ids2 = stepIds();
|
|
575
|
+
const progress2 = junCourseProgress(entry2.meta, ids2);
|
|
576
|
+
if (!junCapProgress(progress2, ctx.from)) {
|
|
577
|
+
refused = true;
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
const next = junNextProgress(progress2[ctx.from], ids2, stepId);
|
|
581
|
+
if (next === null) {
|
|
582
|
+
refused = true;
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
stored = next;
|
|
586
|
+
const kept = Object.fromEntries(
|
|
587
|
+
Object.entries(progress2).filter(([person]) => person !== ctx.from)
|
|
588
|
+
);
|
|
589
|
+
tree.set(docId, {
|
|
590
|
+
...entry2,
|
|
591
|
+
// `updatedAt` deliberately not bumped: ticking a step is not
|
|
592
|
+
// an edit of the course, and bumping it would put every course
|
|
593
|
+
// at the top of every "recently changed" list forever.
|
|
594
|
+
meta: {
|
|
595
|
+
...entry2.meta ?? {},
|
|
596
|
+
courseProgress: next.length ? { ...kept, [ctx.from]: next } : kept
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
},
|
|
600
|
+
() => {
|
|
601
|
+
if (refused) return true;
|
|
602
|
+
const entry2 = plain(sharedTree().get(docId));
|
|
603
|
+
const mine = junCourseProgress(entry2?.meta, stepIds())[ctx.from] ?? [];
|
|
604
|
+
return mine.length === stored.length && mine.every((id, i) => id === stored[i]);
|
|
605
|
+
}
|
|
606
|
+
);
|
|
607
|
+
if (refused) {
|
|
608
|
+
throw new RpcError("LIMIT", "this course cannot take any more progress");
|
|
609
|
+
}
|
|
610
|
+
const entry = plain(sharedTree().get(docId));
|
|
611
|
+
const ids = stepIds();
|
|
612
|
+
const progress = junCourseProgress(entry?.meta, ids);
|
|
613
|
+
return {
|
|
614
|
+
mine: stored,
|
|
615
|
+
people: Object.keys(progress).length,
|
|
616
|
+
finished: Object.values(progress).filter((l) => ids.length > 0 && l.length === ids.length).length
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
}),
|
|
620
|
+
// @ts-expect-error — server auto-import from @abraca/nuxt
|
|
621
|
+
defineRpcHandler({
|
|
622
|
+
method: "jun.poll.vote@1",
|
|
623
|
+
schema: voteSchema,
|
|
624
|
+
/**
|
|
625
|
+
* Cast a vote on a `jun-poll`.
|
|
626
|
+
*
|
|
627
|
+
* The same shape as the guestbook's signature and for the same
|
|
628
|
+
* reason: a visitor has no write access to this document, so the
|
|
629
|
+
* server writes on their behalf after checking who they are. What
|
|
630
|
+
* it stores is keyed by `ctx.from` — the identity the SERVER
|
|
631
|
+
* stamped — which is what makes "one vote per person" true rather
|
|
632
|
+
* than merely intended. A client-supplied voter id would make
|
|
633
|
+
* ballot-stuffing a one-line change.
|
|
634
|
+
*/
|
|
635
|
+
async handler({ docId, choice }, ctx) {
|
|
636
|
+
if (siteConfig().reactionsEnabled === false) {
|
|
637
|
+
throw new RpcError("DISABLED", "voting is off right now");
|
|
638
|
+
}
|
|
639
|
+
const page = plain(sharedTree().get(docId));
|
|
640
|
+
const pollType = jun?.typeIds?.poll;
|
|
641
|
+
if (!page || page.trashed || pollType && page.type !== pollType) {
|
|
642
|
+
throw new RpcError("NOT_FOUND", "no poll here");
|
|
643
|
+
}
|
|
644
|
+
const choices = junPollChoices(page.meta?.pollOptions);
|
|
645
|
+
if (!choices.length) {
|
|
646
|
+
throw new RpcError("NOT_FOUND", "this poll has no choices yet");
|
|
647
|
+
}
|
|
648
|
+
if (choice >= choices.length) {
|
|
649
|
+
throw new RpcError("INVALID", "no such choice");
|
|
650
|
+
}
|
|
651
|
+
let stored = [];
|
|
652
|
+
let refused = false;
|
|
653
|
+
await withRootTree(
|
|
654
|
+
(tree) => {
|
|
655
|
+
const entry2 = plain(tree.get(docId));
|
|
656
|
+
if (!entry2) {
|
|
657
|
+
throw new RpcError("NOT_FOUND", "no poll here");
|
|
658
|
+
}
|
|
659
|
+
const live = junPollChoices(entry2.meta?.pollOptions);
|
|
660
|
+
const ballots = junPollBallots(entry2.meta?.pollVotes, live.length);
|
|
661
|
+
const next = junNextBallot(junMyBallot(ballots, ctx.from), choice, {
|
|
662
|
+
multiple: entry2.meta?.pollMultiple === true,
|
|
663
|
+
revote: entry2.meta?.pollRevote !== false
|
|
664
|
+
});
|
|
665
|
+
if (next === null) {
|
|
666
|
+
refused = true;
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
stored = next;
|
|
670
|
+
const kept = Object.fromEntries(
|
|
671
|
+
Object.entries(ballots).filter(([voter]) => voter !== ctx.from)
|
|
672
|
+
);
|
|
673
|
+
const votes = junCapBallots(
|
|
674
|
+
next.length ? { ...kept, [ctx.from]: next } : kept
|
|
675
|
+
);
|
|
676
|
+
tree.set(docId, {
|
|
677
|
+
...entry2,
|
|
678
|
+
// `updatedAt` deliberately not bumped — a vote is not an
|
|
679
|
+
// edit, and bumping it would put every poll at the top of
|
|
680
|
+
// every "recently changed" list forever.
|
|
681
|
+
meta: { ...entry2.meta ?? {}, pollVotes: votes }
|
|
682
|
+
});
|
|
683
|
+
},
|
|
684
|
+
() => {
|
|
685
|
+
if (refused) return true;
|
|
686
|
+
const entry2 = plain(sharedTree().get(docId));
|
|
687
|
+
const live = junPollChoices(entry2?.meta?.pollOptions);
|
|
688
|
+
const mine = junMyBallot(junPollBallots(entry2?.meta?.pollVotes, live.length), ctx.from);
|
|
689
|
+
return mine.length === stored.length && mine.every((c, i) => c === stored[i]);
|
|
690
|
+
}
|
|
691
|
+
);
|
|
692
|
+
if (refused) {
|
|
693
|
+
throw new RpcError("LIMIT", "this poll only takes one vote per person");
|
|
694
|
+
}
|
|
695
|
+
const entry = plain(sharedTree().get(docId));
|
|
696
|
+
const tally = junTallyVotes(
|
|
697
|
+
junPollBallots(entry?.meta?.pollVotes, choices.length),
|
|
698
|
+
choices.length
|
|
699
|
+
);
|
|
700
|
+
return { mine: stored, counts: tally.counts, voters: tally.voters };
|
|
701
|
+
}
|
|
702
|
+
}),
|
|
703
|
+
// @ts-expect-error — server auto-import from @abraca/nuxt
|
|
411
704
|
defineRpcHandler({
|
|
412
705
|
method: "jun.react@1",
|
|
413
706
|
schema: reactSchema,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { defineNitroPlugin, useRuntimeConfig, useStorage } from "nitropack/runtime";
|
|
2
|
+
import { junDocTree, junHeartbeat, junSlugMap } from "../utils/junCache.js";
|
|
3
|
+
import { junBootedAt } from "../utils/junBoot.js";
|
|
4
|
+
import { junReadiness, junShouldWarn } from "../../utils/junReadiness.js";
|
|
5
|
+
const TICK_MS = 2e4;
|
|
6
|
+
const WARN_EVERY_MS = 6e4;
|
|
7
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
8
|
+
const jun = useRuntimeConfig().public.jun ?? {};
|
|
9
|
+
const apiBase = jun.apiBase ?? "/api/_jun";
|
|
10
|
+
const docCacheOn = jun.features?.docCache !== false;
|
|
11
|
+
let lastWarnedAt = null;
|
|
12
|
+
let lastState = null;
|
|
13
|
+
let timer = null;
|
|
14
|
+
async function look() {
|
|
15
|
+
const storage = useStorage();
|
|
16
|
+
const [tree, slugs, bodyKeys, beat] = await Promise.all([
|
|
17
|
+
junDocTree(),
|
|
18
|
+
junSlugMap(),
|
|
19
|
+
storage.getKeys("doc-cache:html"),
|
|
20
|
+
junHeartbeat()
|
|
21
|
+
]);
|
|
22
|
+
const heartbeatAgeMs = beat && beat.at >= junBootedAt() ? Date.now() - beat.at : null;
|
|
23
|
+
const verdict = junReadiness({
|
|
24
|
+
treeSize: Object.keys(tree).length,
|
|
25
|
+
slugCount: Object.keys(slugs).length,
|
|
26
|
+
bodyCount: bodyKeys.length,
|
|
27
|
+
ageMs: Date.now() - junBootedAt(),
|
|
28
|
+
heartbeatAgeMs,
|
|
29
|
+
expectHeartbeat: docCacheOn
|
|
30
|
+
});
|
|
31
|
+
if (verdict.state === "ready" && lastState !== "ready") {
|
|
32
|
+
console.log(`[jun:watchdog] SSR is ready \u2014 ${verdict.reason}`);
|
|
33
|
+
lastWarnedAt = null;
|
|
34
|
+
}
|
|
35
|
+
if (junShouldWarn(verdict.state, lastWarnedAt, Date.now(), WARN_EVERY_MS)) {
|
|
36
|
+
lastWarnedAt = Date.now();
|
|
37
|
+
const log = verdict.state === "dead" ? console.error : console.warn;
|
|
38
|
+
log(
|
|
39
|
+
`[jun:watchdog] THIS DEPLOYMENT CANNOT SERVER-RENDER \u2014 ${verdict.reason}
|
|
40
|
+
[jun:watchdog] ${verdict.hint ?? ""}
|
|
41
|
+
[jun:watchdog] Details: GET ${apiBase}/health (503 while this lasts). The site still works in a browser, which is exactly why this needs saying.`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
lastState = verdict.state;
|
|
45
|
+
}
|
|
46
|
+
const first = setTimeout(() => {
|
|
47
|
+
void look();
|
|
48
|
+
timer = setInterval(() => void look(), TICK_MS);
|
|
49
|
+
}, TICK_MS);
|
|
50
|
+
nitroApp.hooks.hook("close", () => {
|
|
51
|
+
clearTimeout(first);
|
|
52
|
+
if (timer) clearInterval(timer);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineEventHandler, getQuery, setResponseHeader } from "h3";
|
|
2
|
+
import { junBrandIdentity, junIconScale } from "../utils/junBrand.js";
|
|
3
|
+
import { junRenderIcon } from "../utils/junIcon.js";
|
|
4
|
+
const SIZES = [32, 64, 120, 152, 167, 180, 192, 256, 384, 512];
|
|
5
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
const q = getQuery(event);
|
|
7
|
+
const requested = Number.parseInt(String(q.size ?? "180"), 10);
|
|
8
|
+
const size = SIZES.includes(requested) ? requested : 180;
|
|
9
|
+
const maskable = q.maskable === "1" || q.maskable === "true";
|
|
10
|
+
const brand = await junBrandIdentity();
|
|
11
|
+
const png = await junRenderIcon({
|
|
12
|
+
mark: brand.mark,
|
|
13
|
+
size,
|
|
14
|
+
// A home-screen icon is not theme-aware, so it commits to ONE scheme: the
|
|
15
|
+
// DARK mark on the dark tile. That pairing is deliberate — the tile is the
|
|
16
|
+
// site's `themeColor` (near-black by default), and the light mark's ink is
|
|
17
|
+
// near-black too, which would render an invisible icon.
|
|
18
|
+
colors: brand.dark,
|
|
19
|
+
background: brand.tile,
|
|
20
|
+
scale: junIconScale(brand.mark, maskable)
|
|
21
|
+
});
|
|
22
|
+
setResponseHeader(event, "content-type", "image/png");
|
|
23
|
+
setResponseHeader(event, "cache-control", "public, max-age=31536000, immutable");
|
|
24
|
+
return new Uint8Array(png);
|
|
25
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineEventHandler, setResponseHeader } from "h3";
|
|
2
|
+
import { junFaviconSvg } from "../../utils/junMark.js";
|
|
3
|
+
import { junBrandIdentity } from "../utils/junBrand.js";
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
const brand = await junBrandIdentity();
|
|
6
|
+
setResponseHeader(event, "content-type", "image/svg+xml; charset=utf-8");
|
|
7
|
+
setResponseHeader(event, "cache-control", "public, max-age=31536000, immutable");
|
|
8
|
+
return junFaviconSvg(brand.mark, brand.light, brand.dark);
|
|
9
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineEventHandler, getQuery, setResponseHeader } from "h3";
|
|
2
|
+
import { JUN_IOS_SCREENS } from "../../utils/junIdentity.js";
|
|
3
|
+
import { junBrandIdentity } from "../utils/junBrand.js";
|
|
4
|
+
import { junRenderIcon } from "../utils/junIcon.js";
|
|
5
|
+
const MARK_SCALE = 0.26;
|
|
6
|
+
const ALLOWED = new Set(
|
|
7
|
+
JUN_IOS_SCREENS.flatMap(({ w, h, dpr }) => [
|
|
8
|
+
`${w * dpr}x${h * dpr}`,
|
|
9
|
+
`${h * dpr}x${w * dpr}`
|
|
10
|
+
])
|
|
11
|
+
);
|
|
12
|
+
export default defineEventHandler(async (event) => {
|
|
13
|
+
const q = getQuery(event);
|
|
14
|
+
const w = Number.parseInt(String(q.w ?? ""), 10);
|
|
15
|
+
const h = Number.parseInt(String(q.h ?? ""), 10);
|
|
16
|
+
if (!ALLOWED.has(`${w}x${h}`)) {
|
|
17
|
+
const fallback = JUN_IOS_SCREENS[0];
|
|
18
|
+
return renderSplash(event, fallback.w * fallback.dpr, fallback.h * fallback.dpr);
|
|
19
|
+
}
|
|
20
|
+
return renderSplash(event, w, h);
|
|
21
|
+
});
|
|
22
|
+
async function renderSplash(event, w, h) {
|
|
23
|
+
const brand = await junBrandIdentity();
|
|
24
|
+
const png = await junRenderIcon({
|
|
25
|
+
mark: brand.mark,
|
|
26
|
+
size: w,
|
|
27
|
+
height: h,
|
|
28
|
+
// The DARK mark on the tile, same pairing as the home-screen icon — this
|
|
29
|
+
// image sits directly behind that icon's own launch animation.
|
|
30
|
+
colors: brand.dark,
|
|
31
|
+
background: brand.tile,
|
|
32
|
+
scale: MARK_SCALE
|
|
33
|
+
});
|
|
34
|
+
setResponseHeader(event, "content-type", "image/png");
|
|
35
|
+
setResponseHeader(event, "cache-control", "public, max-age=31536000, immutable");
|
|
36
|
+
return new Uint8Array(png);
|
|
37
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { defineEventHandler, setResponseHeader } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
+
export default defineEventHandler((event) => {
|
|
4
|
+
const config = useRuntimeConfig();
|
|
5
|
+
const jun = config.public.jun;
|
|
6
|
+
const build = config.app?.buildId ?? "dev";
|
|
7
|
+
const apiBase = jun?.apiBase ?? "/api/_jun";
|
|
8
|
+
setResponseHeader(event, "content-type", "text/javascript; charset=utf-8");
|
|
9
|
+
setResponseHeader(event, "service-worker-allowed", "/");
|
|
10
|
+
setResponseHeader(event, "cache-control", "no-cache");
|
|
11
|
+
if (import.meta.dev) {
|
|
12
|
+
return `/* @abraca/junis \u2014 DEV tombstone. Removes any worker left by a production build. */
|
|
13
|
+
self.addEventListener('install', () => self.skipWaiting())
|
|
14
|
+
self.addEventListener('activate', (event) => {
|
|
15
|
+
event.waitUntil((async () => {
|
|
16
|
+
const names = await caches.keys()
|
|
17
|
+
await Promise.all(names.filter(n => n.startsWith('jun-')).map(n => caches.delete(n)))
|
|
18
|
+
await self.registration.unregister()
|
|
19
|
+
// Reload whatever this was controlling, so the tab lands on the dev server
|
|
20
|
+
// rather than on the last thing the old worker cached.
|
|
21
|
+
const clients = await self.clients.matchAll({ type: 'window' })
|
|
22
|
+
for (const client of clients) client.navigate(client.url)
|
|
23
|
+
})())
|
|
24
|
+
})
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
return `/* @abraca/junis service worker \u2014 generated, do not edit */
|
|
28
|
+
const CACHE = 'jun-${build}'
|
|
29
|
+
const API_BASE = ${JSON.stringify(apiBase)}
|
|
30
|
+
|
|
31
|
+
/** Immutable by construction: content-hashed, or fingerprinted in ?v=. */
|
|
32
|
+
function isImmutable(url) {
|
|
33
|
+
return url.pathname.startsWith('/_nuxt/')
|
|
34
|
+
|| url.pathname === '/jun-icon.png'
|
|
35
|
+
|| url.pathname === '/jun-icon.svg'
|
|
36
|
+
|| url.pathname === '/jun-splash.png'
|
|
37
|
+
|| url.pathname === '/apple-touch-icon.png'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Never touched: live data, and anything whose freshness is the point. */
|
|
41
|
+
function isPassThrough(url) {
|
|
42
|
+
return url.pathname.startsWith(API_BASE)
|
|
43
|
+
|| url.pathname.startsWith('/api/')
|
|
44
|
+
|| url.pathname.startsWith('/uploads/')
|
|
45
|
+
|| url.pathname === '/manifest.webmanifest'
|
|
46
|
+
|| url.pathname === '/feed.xml'
|
|
47
|
+
|| url.pathname === '/feed.json'
|
|
48
|
+
|| url.pathname === '/sitemap.xml'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
self.addEventListener('install', () => {
|
|
52
|
+
// No precache \u2014 see the header. Take over immediately so a deploy does not
|
|
53
|
+
// wait for every tab to close.
|
|
54
|
+
self.skipWaiting()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
self.addEventListener('activate', (event) => {
|
|
58
|
+
event.waitUntil((async () => {
|
|
59
|
+
const names = await caches.keys()
|
|
60
|
+
await Promise.all(names.map(n => (n !== CACHE && n.startsWith('jun-') ? caches.delete(n) : null)))
|
|
61
|
+
await self.clients.claim()
|
|
62
|
+
})())
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
self.addEventListener('message', (event) => {
|
|
66
|
+
if (event.data === 'jun:skip-waiting') self.skipWaiting()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
async function networkFirst(request) {
|
|
70
|
+
const cache = await caches.open(CACHE)
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetch(request)
|
|
73
|
+
// Only a real, complete answer is worth keeping. An opaque or errored
|
|
74
|
+
// response cached here would be served back as the offline page.
|
|
75
|
+
if (response && response.ok && response.type === 'basic') {
|
|
76
|
+
cache.put(request, response.clone())
|
|
77
|
+
}
|
|
78
|
+
return response
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
const hit = await cache.match(request)
|
|
82
|
+
if (hit) return hit
|
|
83
|
+
// Nothing cached for this URL: fall back to the last page this visitor
|
|
84
|
+
// actually saw, so offline lands on the site rather than on a browser
|
|
85
|
+
// error. Still a miss for a first visit, which is correct.
|
|
86
|
+
const any = await cache.match('/')
|
|
87
|
+
if (any) return any
|
|
88
|
+
throw err
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function cacheFirst(request) {
|
|
93
|
+
const cache = await caches.open(CACHE)
|
|
94
|
+
const hit = await cache.match(request)
|
|
95
|
+
if (hit) return hit
|
|
96
|
+
const response = await fetch(request)
|
|
97
|
+
if (response && response.ok && response.type === 'basic') {
|
|
98
|
+
cache.put(request, response.clone())
|
|
99
|
+
}
|
|
100
|
+
return response
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
self.addEventListener('fetch', (event) => {
|
|
104
|
+
const request = event.request
|
|
105
|
+
if (request.method !== 'GET') return
|
|
106
|
+
|
|
107
|
+
let url
|
|
108
|
+
try { url = new URL(request.url) }
|
|
109
|
+
catch { return }
|
|
110
|
+
|
|
111
|
+
// Same-origin only. The CRDT backend is a different origin and its websocket
|
|
112
|
+
// and REST calls must never come anywhere near this.
|
|
113
|
+
if (url.origin !== self.location.origin) return
|
|
114
|
+
if (isPassThrough(url)) return
|
|
115
|
+
|
|
116
|
+
if (isImmutable(url)) {
|
|
117
|
+
event.respondWith(cacheFirst(request))
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (request.mode === 'navigate') {
|
|
122
|
+
event.respondWith(networkFirst(request))
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
`;
|
|
126
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
|
|
2
|
+
shortcuts?: {
|
|
3
|
+
name: string;
|
|
4
|
+
url: string;
|
|
5
|
+
}[] | undefined;
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
short_name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
start_url: string;
|
|
11
|
+
scope: string;
|
|
12
|
+
display: string;
|
|
13
|
+
display_override: string[];
|
|
14
|
+
orientation: string;
|
|
15
|
+
background_color: string;
|
|
16
|
+
theme_color: string;
|
|
17
|
+
icons: {
|
|
18
|
+
src: string;
|
|
19
|
+
sizes: string;
|
|
20
|
+
type: string;
|
|
21
|
+
purpose: string;
|
|
22
|
+
}[];
|
|
23
|
+
}>>;
|
|
24
|
+
export default _default;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { defineEventHandler, setResponseHeader } from "h3";
|
|
2
|
+
import { junDocTree, junRootDocId, junSlugMap } from "../utils/junCache.js";
|
|
3
|
+
import { junBrandIdentity } from "../utils/junBrand.js";
|
|
4
|
+
import { isJunOwnerOnlyDoc } from "../utils/junVisibility.js";
|
|
5
|
+
const MAX_SHORTCUTS = 4;
|
|
6
|
+
export default defineEventHandler(async (event) => {
|
|
7
|
+
const brand = await junBrandIdentity();
|
|
8
|
+
const v = brand.version;
|
|
9
|
+
const icon = (size, maskable = false) => ({
|
|
10
|
+
src: `/jun-icon.png?size=${size}&v=${v}${maskable ? "&maskable=1" : ""}`,
|
|
11
|
+
sizes: `${size}x${size}`,
|
|
12
|
+
type: "image/png",
|
|
13
|
+
purpose: maskable ? "maskable" : "any"
|
|
14
|
+
});
|
|
15
|
+
let shortcuts = [];
|
|
16
|
+
try {
|
|
17
|
+
const rootDocId = junRootDocId();
|
|
18
|
+
const [tree, idToSlug] = await Promise.all([junDocTree(), junSlugMap()]);
|
|
19
|
+
shortcuts = Object.entries(tree).filter(
|
|
20
|
+
([id, e]) => !!e && !e.trashed && id !== rootDocId && (!e.parentId || e.parentId === rootDocId) && e.meta?.hidden !== true && e.meta?.draft !== true && !isJunOwnerOnlyDoc(e) && !!idToSlug[id]
|
|
21
|
+
).sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0)).slice(0, MAX_SHORTCUTS).map(([id, e]) => ({ name: e.label || "Untitled", url: `/${idToSlug[id]}` }));
|
|
22
|
+
} catch {
|
|
23
|
+
shortcuts = [];
|
|
24
|
+
}
|
|
25
|
+
setResponseHeader(event, "content-type", "application/manifest+json; charset=utf-8");
|
|
26
|
+
setResponseHeader(event, "cache-control", "public, max-age=300");
|
|
27
|
+
return {
|
|
28
|
+
id: "/",
|
|
29
|
+
name: brand.name,
|
|
30
|
+
short_name: brand.shortName,
|
|
31
|
+
description: brand.description,
|
|
32
|
+
start_url: "/",
|
|
33
|
+
scope: "/",
|
|
34
|
+
display: "standalone",
|
|
35
|
+
// `display_override` is how a desktop install gets the tab-strip-free
|
|
36
|
+
// window; browsers that do not know `window-controls-overlay` fall through
|
|
37
|
+
// to `standalone`, which is the same thing `display` already said.
|
|
38
|
+
display_override: ["standalone", "minimal-ui"],
|
|
39
|
+
orientation: "any",
|
|
40
|
+
background_color: brand.themeColor,
|
|
41
|
+
theme_color: brand.themeColor,
|
|
42
|
+
icons: [
|
|
43
|
+
icon(192),
|
|
44
|
+
icon(512),
|
|
45
|
+
icon(512, true),
|
|
46
|
+
// An `any`-size vector, for the launchers that prefer one.
|
|
47
|
+
{ src: `/jun-icon.svg?v=${v}`, sizes: "any", type: "image/svg+xml", purpose: "any" }
|
|
48
|
+
],
|
|
49
|
+
...shortcuts.length ? { shortcuts } : {}
|
|
50
|
+
};
|
|
51
|
+
});
|
|
@@ -14,6 +14,8 @@ export default defineEventHandler(async (event) => {
|
|
|
14
14
|
if (e.meta?.draft === true) return false;
|
|
15
15
|
if (e.meta?.signerId) return false;
|
|
16
16
|
if ((e.type ?? "").endsWith("-redirect")) return false;
|
|
17
|
+
if (e.meta?.paneDoc || e.meta?.paneWidget) return false;
|
|
18
|
+
if (e.meta?.t != null) return false;
|
|
17
19
|
return true;
|
|
18
20
|
}).map(([, slug]) => `${site}/${slug}`);
|
|
19
21
|
setResponseHeader(event, "content-type", "application/xml; charset=utf-8");
|