core: support monograph.publishUrl field

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2025-11-25 11:45:00 +05:00
parent e87f5e5f89
commit 8ec3702df9
5 changed files with 43 additions and 7 deletions

View File

@@ -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 { EV, EVENTS, hosts, MonographAnalytics } from "@notesnook/core";
import { EV, EVENTS, hosts } from "@notesnook/core";
import { useStore } from "../../stores/monograph-store";
import { Note } from "@notesnook/core";
import { strings } from "@notesnook/intl";
@@ -65,6 +65,9 @@ function PublishView(props: PublishViewProps) {
if (!monographAnalytics?.isAllowed || !monograph) return { totalViews: 0 };
return await db.monographs.analytics(monograph?.id);
}, [monograph?.id, monographAnalytics]);
const publishUrl = usePromise(async () => {
return await db.monographs.publishUrl(note.id);
}, [monograph?.id, monograph?.publishUrl]);
useEffect(() => {
const fileDownloadedEvent = EV.subscribe(
@@ -96,23 +99,29 @@ function PublishView(props: PublishViewProps) {
variant="text.body"
as="a"
target="_blank"
href={`${hosts.MONOGRAPH_HOST}/${monograph?.id}`}
href={publishUrl.status === "fulfilled" ? publishUrl.value : "#"}
sx={{
textOverflow: "ellipsis",
whiteSpace: "nowrap",
textDecoration: "none",
overflow: "hidden",
px: 1
px: 1,
opacity: publishUrl.status === "fulfilled" ? 1 : 0.8
}}
>
{`${hosts.MONOGRAPH_HOST}/${monograph?.id}`}
{publishUrl.status === "fulfilled"
? publishUrl.value
: monograph?.publishUrl}
</Link>
<Button
variant="secondary"
className="copyPublishLink"
sx={{ flexShrink: 0, m: 0 }}
disabled={publishUrl.status !== "fulfilled"}
onClick={() => {
writeText(`${hosts.MONOGRAPH_HOST}/${monograph?.id}`);
if (publishUrl.status !== "fulfilled") return;
writeText(publishUrl.value);
}}
>
{strings.copy()}
@@ -453,6 +462,7 @@ type ResolvedMonograph = {
publishedAt?: number;
password?: string;
title: string;
publishUrl?: string;
};
async function resolveMonograph(
@@ -463,6 +473,7 @@ async function resolveMonograph(
return {
id: monographId,
selfDestruct: !!monograph.selfDestruct,
publishUrl: monograph.publishUrl,
publishedAt: monograph.datePublished,
title: monograph.title,
password: monograph.password

View File

@@ -135,7 +135,7 @@ 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(
const { id, datePublished, publishUrl } = await method(
`${Constants.API_HOST}/monographs?deviceId=${deviceId}`,
monograph,
token
@@ -147,7 +147,8 @@ export class Monographs {
title: monograph.title,
selfDestruct: monograph.selfDestruct,
datePublished: datePublished,
password: monograph.password
password: monograph.password,
publishUrl: publishUrl
});
return id;
}
@@ -208,4 +209,18 @@ export class Monographs {
return { totalViews: 0 };
}
}
async publishUrl(monographId: string): Promise<string> {
try {
const token = await this.db.tokenManager.getAccessToken();
const { publishUrl } = (await http.get(
`${Constants.API_HOST}/monographs/${monographId}/publish-url`,
token
)) as { publishUrl: string };
return publishUrl;
} catch {
const monograph = await this.get(monographId);
return monograph?.publishUrl || "";
}
}
}

View File

@@ -62,6 +62,7 @@ export class Monographs implements ICollection {
datePublished: merged.datePublished,
selfDestruct: merged.selfDestruct,
password: merged.password,
publishUrl: merged.publishUrl,
type: "monograph"
});
}

View File

@@ -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();
}
}
};
}

View File

@@ -507,6 +507,7 @@ export interface Monograph extends BaseItem<"monograph"> {
datePublished: number;
selfDestruct: boolean;
password?: Cipher<"base64">;
publishUrl?: string;
}
export type Match = {