A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: add support for server controlled monograph urls (#8995)
01zulfi49b1dd46d1e6
diff --git a/apps/mobile/app/components/sheets/publish-note/index.tsx b/apps/mobile/app/components/sheets/publish-note/index.tsxindex 829896fa8..433e61bfe 100644--- a/apps/mobile/app/components/sheets/publish-note/index.tsx+++ b/apps/mobile/app/components/sheets/publish-note/index.tsx@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { hosts, Monograph, Note } from "@notesnook/core";+import { Note } from "@notesnook/core";import { strings } from "@notesnook/intl";import { useThemeColors } from "@notesnook/theme";import Clipboard from "@react-native-clipboard/clipboard";@@ -53,15 +53,14 @@ async function fetchMonographData(noteId: string) {const monograph = monographId? await db.monographs.get(monographId): undefined;- const analyticsFeature = await isFeatureAvailable("monographAnalytics");- const analytics =- monographId && analyticsFeature- ? await db.monographs.analytics(monographId)- : undefined;++ const metadata = monographId+ ? await db.monographs.metadata(monographId)+ : { publishUrl: "", analytics: { totalViews: 0 } };return {monograph,monographId,- analytics+ metadata};}@@ -86,8 +85,9 @@ const PublishNoteSheet = ({return fetchMonographData(note?.id);}, []);const monograph = monographData.result?.monograph;+ const metadata = monographData.result?.metadata;customTitle.current = monograph?.title || note.title || "";- const publishUrl = monograph && `${hosts.MONOGRAPH_HOST}/${monograph?.id}`;+ const publishUrl = metadata?.publishUrl || monograph?.publishUrl || "";const isPublished = db.monographs.monograph(note?.id);useEffect(() => {@@ -382,7 +382,7 @@ const PublishNoteSheet = ({><Paragraph size={AppFontSize.sm}>{strings.views()}</Paragraph><Paragraph>- {monographData?.result?.analytics?.totalViews || 0}+ {monographData?.result?.metadata?.totalViews || 0}</Paragraph></View></View>@@ -455,4 +455,4 @@ PublishNoteSheet.present = (note: Note) => {});};-export default PublishNoteSheet;+export default PublishNoteSheet;\ No newline at end of filediff --git a/apps/monograph/app/components/monograph-view.tsx b/apps/monograph/app/components/monograph-view.tsxnew file mode 100644index 000000000..63650389c--- /dev/null+++ b/apps/monograph/app/components/monograph-view.tsx@@ -0,0 +1,67 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/+import { Flex, Text } from "@theme-ui/components";+import { MonographPage } from "./monographpost";+import { Header } from "./header";+import { Footer } from "./footer";+import { Monograph } from "./monographpost/types";++type MonographViewProps = {+ monograph: Monograph | null;+ pixel: string | null;+ encodedKey: string | undefined;+};++export function MonographView({+ monograph,+ pixel,+ encodedKey+}: MonographViewProps) {+ return (+ <>+ {monograph ? (+ <MonographPage+ monograph={monograph}+ encodedKey={encodedKey}+ pixel={pixel ?? undefined}+ />+ ) : (+ <>+ <Header />+ <Flex+ sx={{+ justifyContent: "center",+ alignItems: "center",+ flexDirection: "column",+ flex: 1,+ height: "100vh",+ bg: "background"+ }}+ >+ <Text variant="heading" sx={{ fontSize: 42, mt: 20 }}>+ 404+ </Text>+ <Text variant="body">This monograph does not exist.</Text>+ </Flex>+ <Footer />+ </>+ )}+ </>+ );+}diff --git a/apps/monograph/app/components/monographpost/index.tsx b/apps/monograph/app/components/monographpost/index.tsxindex 2c3790f0b..e4b8a3cba 100644--- a/apps/monograph/app/components/monographpost/index.tsx+++ b/apps/monograph/app/components/monographpost/index.tsx@@ -108,11 +108,11 @@ function generateTableOfContents() {export const MonographPage = ({monograph,encodedKey,- apiHost+ pixel}: {monograph: Monograph;encodedKey?: string;- apiHost: string;+ pixel?: string;}) => {const [reportDialogVisible, setReportDialogVisible] = useState(false);const [tableOfContents, setTableOfContents] = useState<TableOfContent[]>([]);@@ -227,10 +227,7 @@ export const MonographPage = ({</Text></Button>)}- <Image- sx={{ display: "none" }}- src={`${apiHost}/monographs/${monograph.id}/view`}- />+ {pixel ? <Image sx={{ display: "none" }} src={pixel} /> : null}</Flex></Box><Flexdiff --git a/apps/monograph/app/components/monographpost/types.ts b/apps/monograph/app/components/monographpost/types.tsindex f507df775..a22cab7c7 100644--- a/apps/monograph/app/components/monographpost/types.ts+++ b/apps/monograph/app/components/monographpost/types.ts@@ -28,4 +28,5 @@ export type Monograph = {encryptedContent?: Cipher<"base64">;datePublished: string;id: string;+ slug?: string;};diff --git a/apps/monograph/app/routes/$id.tsx b/apps/monograph/app/routes/$id.tsxindex f42f70c8f..de37aebb1 100644--- a/apps/monograph/app/routes/$id.tsx+++ b/apps/monograph/app/routes/$id.tsx@@ -17,55 +17,25 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/import type { MetaFunction, LoaderFunctionArgs } from "@remix-run/node";-import { Cipher } from "@notesnook/crypto";-import { Flex, Text } from "@theme-ui/components";import { useLoaderData } from "@remix-run/react";-import { MonographPage } from "../components/monographpost";-import { useHashLocation } from "../utils/use-hash-location";import { isSpam, isSpamCached } from "../utils/spam-filter.server";-import { Header } from "../components/header";-import { Footer } from "../components/footer";import { API_HOST, PUBLIC_URL } from "../utils/env";-import { generateMetaDescriptors } from "../utils/meta";-import { format } from "date-fns/format";--type Monograph = {- title: string;- userId: string;- content?: {- type: string;- data: string;- };- selfDestruct: boolean;- encryptedContent?: Cipher<"base64">;- datePublished: string;- id: string;-};+import {+ buildMonographMeta,+ getMonographMetadata,+ NOT_FOUND_LOADER_DATA+} from "../utils/meta";+import { MonographView } from "../components/monograph-view";+import { useHashLocation } from "../utils/use-hash-location";+import { Monograph } from "../components/monographpost/types";type MonographResponse = Omit<Monograph, "content"> & { content: string };-export const meta: MetaFunction<typeof loader> = ({ data }) => {- if (!data || !data.metadata || !data.monograph) return [];-- const imageUrl = `${PUBLIC_URL}/api/og.jpg?${new URLSearchParams({- title: data?.metadata?.title || "",- description: data?.metadata?.fullDescription- ? Buffer.from(data.metadata.fullDescription, "utf-8").toString("base64")- : "",- date: data?.metadata?.datePublished || ""- }).toString()}`;-- return generateMetaDescriptors({- titleFull: data?.metadata.title + " - Monograph",- titleShort: data?.metadata.title,- description: data?.metadata.shortDescription,- imageAlt: data?.metadata.fullDescription,- imageUrl: imageUrl,- url: data?.monograph ? `${PUBLIC_URL}/${data?.monograph.id}` : undefined,- publishedAt: data?.metadata.datePublished,- type: "article"- });-};+export const meta: MetaFunction<typeof loader> = ({ data }) =>+ buildMonographMeta(+ data,+ data?.monograph ? `${PUBLIC_URL}/${data.monograph.id}` : undefined+ );export async function loader({ params }: LoaderFunctionArgs) {try {@@ -86,122 +56,22 @@ export async function loader({ params }: LoaderFunctionArgs) {return {monograph,metadata,- apiHost: API_HOST+ pixel: `${API_HOST}/monographs/${monographId}/view`};} catch (e) {// console.error(e);- return {- monograph: null,- metadata: {- title: "Not found",- fullDescription: "This monograph does not exist.",- shortDescription: "This monograph does not exist.",- datePublished: ""- },- apiHost: API_HOST- };+ return NOT_FOUND_LOADER_DATA;}}export default function MonographPost() {- const { monograph, apiHost } = useLoaderData<typeof loader>();+ const { monograph, pixel } = useLoaderData<typeof loader>();const [_, hashParams] = useHashLocation();-return (- <>- {monograph ? (- <MonographPage- monograph={monograph}- encodedKey={hashParams.key}- apiHost={apiHost}- />- ) : (- <>- <Header />- <Flex- sx={{- justifyContent: "center",- alignItems: "center",- flexDirection: "column",- flex: 1,- height: "100vh",- bg: "background"- }}- >- <Text variant="heading" sx={{ fontSize: 42, mt: 20 }}>- 404- </Text>- <Text variant="body">This monograph does not exist.</Text>- </Flex>- <Footer />- </>- )}- </>+ <MonographView+ monograph={monograph}+ pixel={pixel}+ encodedKey={hashParams.key}+ />);}--type Metadata = {- title: string;- fullDescription: string;- shortDescription: string;- datePublished: string;-};--function extractFirstWords(html: string, numWords = 30): string {- // Strip HTML tags and normalize whitespace- const plainText = html- .replace(/<[^>]*>/g, " ")- .replace(/\s+/g, " ")- .trim();-- // Split into words and take first N- const words = plainText.split(" ").slice(0, numWords);-- // Add ellipsis if text was truncated- const excerpt = words.join(" ");- return words.length < plainText.split(" ").length ? excerpt + "..." : excerpt;-}--function trimDescription(- str: string,- length: number,- collapse = false-): string {- if (collapse) str = str.replace(/\n/gm, " ").replace(/\s+/gm, " ");- const index = str.indexOf(".", length) - 1;- return addPeriod(- str.substring(- 0,- index < 0 ? Math.min(str.length, length) : Math.min(index, length)- )- );-}--const NOT_ALPHA_REGEX = /[^\w\s']|_/g;-function addPeriod(str: string) {- str = str.trim();- const lastChar = str[str.length - 1];- if (lastChar === ".") return str;- if (NOT_ALPHA_REGEX.test(lastChar)) str = str.slice(0, str.length - 1);- return str + "...";-}--function getMonographMetadata(monograph: Monograph): Metadata {- const title = monograph?.title || "Not found";- const text = monograph?.encryptedContent- ? "This monograph is encrypted. Enter password to view contents."- : monograph?.content- ? extractFirstWords(monograph?.content.data, 100)- : "";- const shortDescription = trimDescription(text, 150, true);- const fullDescription = trimDescription(text, 300, true);- const datePublished = monograph- ? format(monograph.datePublished, "yyyy-MM-dd HH:mm")- : "";- return {- title,- fullDescription,- shortDescription,- datePublished- };-}diff --git a/apps/monograph/app/routes/s.$slug.tsx b/apps/monograph/app/routes/s.$slug.tsxnew file mode 100644index 000000000..0b5866c2d--- /dev/null+++ b/apps/monograph/app/routes/s.$slug.tsx@@ -0,0 +1,77 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/+import type { MetaFunction, LoaderFunctionArgs } from "@remix-run/node";+import { useLoaderData } from "@remix-run/react";+import { isSpam, isSpamCached } from "../utils/spam-filter.server";+import { API_HOST, PUBLIC_URL } from "../utils/env";+import {+ buildMonographMeta,+ getMonographMetadata,+ NOT_FOUND_LOADER_DATA+} from "../utils/meta";+import { MonographView } from "../components/monograph-view";+import { useHashLocation } from "../utils/use-hash-location";+import { Monograph } from "../components/monographpost/types";++type MonographResponse = Omit<Monograph, "content"> & { content: string };++export const meta: MetaFunction<typeof loader> = ({ data }) =>+ buildMonographMeta(+ data,+ data?.monograph ? `${PUBLIC_URL}/s/${data.monograph.id}` : undefined+ );++export default function MonographPost() {+ const { monograph, pixel } = useLoaderData<typeof loader>();+ const [_, hashParams] = useHashLocation();+ return (+ <MonographView+ monograph={monograph}+ pixel={pixel}+ encodedKey={hashParams.key}+ />+ );+}++export async function loader({ params }: LoaderFunctionArgs) {+ try {+ const slug = params["slug"];++ if (slug && (await isSpamCached(slug))) throw new Error();++ const monograph = await fetch(`${API_HOST}/monographs/v2/${slug}`)+ .then((r) => r.json() as Promise<MonographResponse>)+ .then(+ (data) => ({ ...data, content: JSON.parse(data.content) } as Monograph)+ );++ if (!monograph.encryptedContent && (await isSpam(monograph)))+ throw new Error();++ const metadata = getMonographMetadata(monograph);+ return {+ monograph,+ metadata,+ pixel: `${API_HOST}/monographs/v2/${slug}/view`+ };+ } catch (e) {+ // console.error(e);+ return NOT_FOUND_LOADER_DATA;+ }+}diff --git a/apps/monograph/app/utils/meta.ts b/apps/monograph/app/utils/meta.tsindex 90edd94a7..078c0d421 100644--- a/apps/monograph/app/utils/meta.ts+++ b/apps/monograph/app/utils/meta.ts@@ -17,6 +17,9 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/import { ServerRuntimeMetaDescriptor } from "@remix-run/server-runtime";+import { Monograph } from "../components/monographpost/types";+import { format } from "date-fns/format";+import { PUBLIC_URL } from "./env";type MetaProps = {titleFull: string;@@ -70,3 +73,112 @@ export function generateMetaDescriptors(return descriptors;}++type Metadata = {+ title: string;+ fullDescription: string;+ shortDescription: string;+ datePublished: string;+};++function extractFirstWords(html: string, numWords = 30): string {+ // Strip HTML tags and normalize whitespace+ const plainText = html+ .replace(/<[^>]*>/g, " ")+ .replace(/\s+/g, " ")+ .trim();++ // Split into words and take first N+ const words = plainText.split(" ").slice(0, numWords);++ // Add ellipsis if text was truncated+ const excerpt = words.join(" ");+ return words.length < plainText.split(" ").length ? excerpt + "..." : excerpt;+}++function trimDescription(+ str: string,+ length: number,+ collapse = false+): string {+ if (collapse) str = str.replace(/\n/gm, " ").replace(/\s+/gm, " ");+ const index = str.indexOf(".", length) - 1;+ return addPeriod(+ str.substring(+ 0,+ index < 0 ? Math.min(str.length, length) : Math.min(index, length)+ )+ );+}++const NOT_ALPHA_REGEX = /[^\w\s']|_/g;+function addPeriod(str: string) {+ str = str.trim();+ const lastChar = str[str.length - 1];+ if (lastChar === ".") return str;+ if (NOT_ALPHA_REGEX.test(lastChar)) str = str.slice(0, str.length - 1);+ return str + "...";+}++export function getMonographMetadata(monograph: Monograph): Metadata {+ const title = monograph?.title || "Not found";+ const text = monograph?.encryptedContent+ ? "This monograph is encrypted. Enter password to view contents."+ : monograph?.content+ ? extractFirstWords(monograph?.content.data, 100)+ : "";+ const shortDescription = trimDescription(text, 150, true);+ const fullDescription = trimDescription(text, 300, true);+ const datePublished = monograph+ ? format(monograph.datePublished, "yyyy-MM-dd HH:mm")+ : "";+ return {+ title,+ fullDescription,+ shortDescription,+ datePublished+ };+}++export type MonographLoaderData = {+ monograph: Monograph | null;+ metadata: Metadata;+ pixel: string | null;+};++export const NOT_FOUND_LOADER_DATA: MonographLoaderData = {+ monograph: null,+ metadata: {+ title: "Not found",+ fullDescription: "This monograph does not exist.",+ shortDescription: "This monograph does not exist.",+ datePublished: ""+ },+ pixel: null+};++export function buildMonographMeta(+ data: MonographLoaderData | undefined,+ url: string | undefined+): ServerRuntimeMetaDescriptor[] {+ if (!data || !data.metadata || !data.monograph) return [];++ const imageUrl = `${PUBLIC_URL}/api/og.jpg?${new URLSearchParams({+ title: data.metadata.title || "",+ description: data.metadata.fullDescription+ ? Buffer.from(data.metadata.fullDescription, "utf-8").toString("base64")+ : "",+ date: data.metadata.datePublished || ""+ }).toString()}`;++ return generateMetaDescriptors({+ titleFull: data.metadata.title + " - Monograph",+ titleShort: data.metadata.title,+ description: data.metadata.shortDescription,+ imageAlt: data.metadata.fullDescription,+ imageUrl,+ url,+ publishedAt: data.metadata.datePublished,+ type: "article"+ });+}diff --git a/apps/monograph/package-lock.json b/apps/monograph/package-lock.jsonindex 11e58303f..f98bee709 100644--- a/apps/monograph/package-lock.json+++ b/apps/monograph/package-lock.json@@ -148,7 +148,7 @@"@notesnook/intl": "file:../intl","@notesnook/theme": "file:../theme","@notesnook/ui": "file:../ui",- "@social-embed/lib": "^0.1.0-next.7",+ "@social-embed/lib": "^0.1.0-next.11","@tiptap/core": "2.6.6","@tiptap/extension-blockquote": "^2.6.6","@tiptap/extension-bullet-list": "^2.6.6",@@ -2950,6 +2950,22 @@"@styled-system/css": "^5.1.5"}},+ "node_modules/@theme-ui/color-modes": {+ "version": "0.16.2",+ "resolved": "https://registry.npmjs.org/@theme-ui/color-modes/-/color-modes-0.16.2.tgz",+ "integrity": "sha512-jWEWx53lxNgWCT38i/kwLV2rsvJz8lVZgi5oImnVwYba9VejXD23q1ckbNFJHosQ8KKXY87ht0KPC6BQFIiHtQ==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "@theme-ui/core": "^0.16.2",+ "@theme-ui/css": "^0.16.2",+ "deepmerge": "^4.2.2"+ },+ "peerDependencies": {+ "@emotion/react": "^11.11.1",+ "react": ">=18"+ }+ },"node_modules/@theme-ui/components": {"version": "0.16.2","resolved": "https://registry.npmjs.org/@theme-ui/components/-/components-0.16.2.tgz",@@ -2995,6 +3011,22 @@"@emotion/react": "^11.11.1"}},+ "node_modules/@theme-ui/theme-provider": {+ "version": "0.16.2",+ "resolved": "https://registry.npmjs.org/@theme-ui/theme-provider/-/theme-provider-0.16.2.tgz",+ "integrity": "sha512-LRnVevODcGqO0JyLJ3wht+PV3ZoZcJ7XXLJAJWDoGeII4vZcPQKwVy4Lpz/juHsZppQxKcB3U+sQDGBnP25irQ==",+ "license": "MIT",+ "peer": true,+ "dependencies": {+ "@theme-ui/color-modes": "^0.16.2",+ "@theme-ui/core": "^0.16.2",+ "@theme-ui/css": "^0.16.2"+ },+ "peerDependencies": {+ "@emotion/react": "^11.11.1",+ "react": ">=18"+ }+ },"node_modules/@types/acorn": {"version": "4.0.6","resolved": "https://registry.npmjs.org/@types/acorn/-/acorn-4.0.6.tgz",@@ -3124,14 +3156,14 @@"version": "15.7.13","resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.13.tgz","integrity": "sha512-hCZTSvwbzWGvhqxp/RqVqwU999pBf2vp7hzIjiYOsl8wqOmUxkQ6ddw1cV3l8811+kdUFus/q4d1Y3E3SyEifA==",- "dev": true,+ "devOptional": true,"license": "MIT"},"node_modules/@types/react": {"version": "18.3.10","resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.10.tgz","integrity": "sha512-02sAAlBnP39JgXwkAq3PeU9DVaaGpZyF3MGcC0MKgQVkZor5IiiDAipVaxQHtDJAmO4GIy/rVBy/LzVj76Cyqg==",- "dev": true,+ "devOptional": true,"license": "MIT","dependencies": {"@types/prop-types": "*",@@ -12239,7 +12271,7 @@"version": "3.23.8","resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz","integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==",- "dev": true,+ "devOptional": true,"license": "MIT","funding": {"url": "https://github.com/sponsors/colinhacks"diff --git a/apps/web/src/components/publish-view/index.tsx b/apps/web/src/components/publish-view/index.tsxindex 605df4a26..fb89e8006 100644--- a/apps/web/src/components/publish-view/index.tsx+++ b/apps/web/src/components/publish-view/index.tsx@@ -23,7 +23,7 @@ import { Loading, Refresh } from "../icons";import { db } from "../../common/db";import { writeText } from "clipboard-polyfill";import { showToast } from "../../utils/toast";-import { EVENTS, hosts } from "@notesnook/core";+import { EVENTS } from "@notesnook/core";import { useStore } from "../../stores/monograph-store";import { Note } from "@notesnook/core";import { strings } from "@notesnook/intl";@@ -61,10 +61,10 @@ function PublishView(props: PublishViewProps) {const unpublishNote = useStore((store) => store.unpublish);const [monograph, setMonograph] = useState(props.monograph);const monographAnalytics = useIsFeatureAvailable("monographAnalytics");- const analytics = usePromise(async () => {- if (!monographAnalytics?.isAllowed || !monograph) return { totalViews: 0 };- return await db.monographs.analytics(monograph?.id);- }, [monograph?.id, monographAnalytics]);+ const metadata = usePromise(async () => {+ if (!monograph) return { publishUrl: "", analytics: { totalViews: 0 } };+ return await db.monographs.metadata(monograph.id);+ }, [monograph?.id]);useEffect(() => {const fileDownloadedEvent = db.eventManager.subscribe(@@ -96,23 +96,31 @@ function PublishView(props: PublishViewProps) {variant="text.body"as="a"target="_blank"- href={`${hosts.MONOGRAPH_HOST}/${monograph?.id}`}+ href={+ metadata.status === "fulfilled" ? metadata.value.publishUrl : "#"+ }sx={{textOverflow: "ellipsis",whiteSpace: "nowrap",textDecoration: "none",overflow: "hidden",- px: 1+ px: 1,+ opacity: metadata.status === "fulfilled" ? 1 : 0.8}}>- {`${hosts.MONOGRAPH_HOST}/${monograph?.id}`}+ {metadata.status === "fulfilled"+ ? metadata.value.publishUrl+ : monograph?.publishUrl}</Link><Buttonvariant="secondary"className="copyPublishLink"sx={{ flexShrink: 0, m: 0 }}+ disabled={metadata.status !== "fulfilled"}onClick={() => {- writeText(`${hosts.MONOGRAPH_HOST}/${monograph?.id}`);+ if (metadata.status !== "fulfilled") return;++ writeText(metadata.value.publishUrl);}}>{strings.copy()}@@ -172,7 +180,7 @@ function PublishView(props: PublishViewProps) {><Text variant="body">{strings.views()}</Text>{monographAnalytics?.isAllowed ? (- analytics.status === "fulfilled" ? (+ metadata.status === "fulfilled" ? (<Flex sx={{ alignItems: "center", gap: 1 }}><Textvariant="body"@@ -180,14 +188,14 @@ function PublishView(props: PublishViewProps) {color: "paragraph-secondary"}}>- {analytics.value.totalViews}+ {metadata.value.analytics.totalViews}</Text><Buttonvariant="tertiary"onClick={async () => {try {setStatus({ action: "analytics" });- analytics.refresh();+ metadata.refresh();} finally {setStatus(undefined);}@@ -453,6 +461,7 @@ type ResolvedMonograph = {publishedAt?: number;password?: string;title: string;+ publishUrl?: string;};async function resolveMonograph(@@ -463,6 +472,7 @@ async function resolveMonograph(return {id: monographId,selfDestruct: !!monograph.selfDestruct,+ publishUrl: monograph.publishUrl,publishedAt: monograph.datePublished,title: monograph.title,password: monograph.passworddiff --git a/packages/core/src/api/monographs.ts b/packages/core/src/api/monographs.tsindex 5df586979..342eb7305 100644--- a/packages/core/src/api/monographs.ts+++ b/packages/core/src/api/monographs.ts@@ -133,10 +133,13 @@ export class Monographs {})};- const method = update ? http.patch.json : http.post.json;const deviceId = await this.db.kv().read("deviceId");- const { id, datePublished } = await method(- `${Constants.API_HOST}/monographs?deviceId=${deviceId}`,+ const method = update ? http.patch.json : http.post.json;+ const url = update+ ? `${Constants.API_HOST}/monographs?deviceId=${deviceId}`+ : `${Constants.API_HOST}/monographs/v2?deviceId=${deviceId}`;+ const { id, datePublished, publishUrl } = await method(+ url,monograph,token);@@ -147,7 +150,8 @@ export class Monographs {title: monograph.title,selfDestruct: monograph.selfDestruct,datePublished: datePublished,- password: monograph.password+ password: monograph.password,+ publishUrl: publishUrl});return id;}@@ -196,16 +200,23 @@ export class Monographs {return this.db.storage().decrypt(monographPasswordsKey, password);}- async analytics(monographId: string): Promise<MonographAnalytics> {+ async metadata(monographId: string): Promise<{+ publishUrl: string;+ analytics: MonographAnalytics;+ }> {try {const token = await this.db.tokenManager.getAccessToken();- const analytics = (await http.get(- `${Constants.API_HOST}/monographs/${monographId}/analytics`,+ const info = (await http.get(+ `${Constants.API_HOST}/monographs/${monographId}/metadata`,token- )) as MonographAnalytics;- return analytics;+ )) as { publishUrl: string; analytics: MonographAnalytics };+ return info;} catch {- return { totalViews: 0 };+ const monograph = await this.get(monographId);+ return {+ publishUrl: monograph?.publishUrl || "",+ analytics: { totalViews: 0 }+ };}}}diff --git a/packages/core/src/collections/monographs.ts b/packages/core/src/collections/monographs.tsindex c9d0fd439..063a6f11c 100644--- a/packages/core/src/collections/monographs.ts+++ b/packages/core/src/collections/monographs.ts@@ -62,6 +62,7 @@ export class Monographs implements ICollection {datePublished: merged.datePublished,selfDestruct: merged.selfDestruct,password: merged.password,+ publishUrl: merged.publishUrl,type: "monograph"});}diff --git a/packages/core/src/database/migrations.ts b/packages/core/src/database/migrations.tsindex 8aa20c338..03f3f33f9 100644--- a/packages/core/src/database/migrations.ts+++ b/packages/core/src/database/migrations.ts@@ -425,6 +425,14 @@ export class NNMigrationProvider implements MigrationProvider {.addColumn("title", "text").execute();}+ },+ "a-2026-02-11": {+ async up(db) {+ await db.schema+ .alterTable("monographs")+ .addColumn("publishUrl", "text", COLLATE_NOCASE)+ .execute();+ }}};}diff --git a/packages/core/src/types.ts b/packages/core/src/types.tsindex 0252e7a35..203e44c8b 100644--- a/packages/core/src/types.ts+++ b/packages/core/src/types.ts@@ -507,6 +507,7 @@ export interface Monograph extends BaseItem<"monograph"> {datePublished: number;selfDestruct: boolean;password?: Cipher<"base64">;+ publishUrl?: string;}export type Match = {