mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-25 16:09:42 +01:00
core: support monograph.publishUrl field
Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
@@ -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";
|
||||
@@ -64,6 +64,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(
|
||||
@@ -95,23 +98,27 @@ 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 : ""}
|
||||
</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()}
|
||||
@@ -425,6 +432,7 @@ type ResolvedMonograph = {
|
||||
selfDestruct: boolean;
|
||||
publishedAt?: number;
|
||||
password?: string;
|
||||
publishUrl?: string;
|
||||
};
|
||||
|
||||
async function resolveMonograph(
|
||||
@@ -435,6 +443,7 @@ async function resolveMonograph(
|
||||
return {
|
||||
id: monographId,
|
||||
selfDestruct: !!monograph.selfDestruct,
|
||||
publishUrl: monograph.publishUrl,
|
||||
publishedAt: monograph.datePublished,
|
||||
password: monograph.password
|
||||
? await db.monographs.decryptPassword(monograph.password)
|
||||
|
||||
@@ -41,7 +41,10 @@ export type MonographAnalytics = {
|
||||
totalViews: number;
|
||||
};
|
||||
|
||||
export type PublishOptions = { password?: string; selfDestruct?: boolean };
|
||||
export type PublishOptions = {
|
||||
password?: string;
|
||||
selfDestruct?: boolean;
|
||||
};
|
||||
export class Monographs {
|
||||
monographs: string[] = [];
|
||||
constructor(private readonly db: Database) {}
|
||||
@@ -130,7 +133,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
|
||||
@@ -142,7 +145,8 @@ export class Monographs {
|
||||
title: monograph.title,
|
||||
selfDestruct: monograph.selfDestruct,
|
||||
datePublished: datePublished,
|
||||
password: monograph.password
|
||||
password: monograph.password,
|
||||
publishUrl: publishUrl
|
||||
});
|
||||
return id;
|
||||
}
|
||||
@@ -203,4 +207,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 || "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ export class Monographs implements ICollection {
|
||||
datePublished: merged.datePublished,
|
||||
selfDestruct: merged.selfDestruct,
|
||||
password: merged.password,
|
||||
publishUrl: merged.publishUrl,
|
||||
type: "monograph"
|
||||
});
|
||||
}
|
||||
|
||||
@@ -404,6 +404,14 @@ export class NNMigrationProvider implements MigrationProvider {
|
||||
.addColumn("password", "text")
|
||||
.execute();
|
||||
}
|
||||
},
|
||||
"a-2025-11-26": {
|
||||
async up(db) {
|
||||
await db.schema
|
||||
.alterTable("monographs")
|
||||
.addColumn("publishUrl", "text", COLLATE_NOCASE)
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -498,6 +498,7 @@ export interface Monograph extends BaseItem<"monograph"> {
|
||||
datePublished: number;
|
||||
selfDestruct: boolean;
|
||||
password?: Cipher<"base64">;
|
||||
publishUrl?: string;
|
||||
}
|
||||
|
||||
export type Match = {
|
||||
|
||||
Reference in New Issue
Block a user