MCPcopy
hub / github.com/streetwriters/notesnook / publish

Method publish

packages/core/src/api/monographs.ts:79–157  ·  view source on GitHub ↗

* Publish a note as a monograph

(noteId: string, title: string, opts: PublishOptions = {})

Source from the content-addressed store, hash-verified

77 * Publish a note as a monograph
78 */
79 async publish(noteId: string, title: string, opts: PublishOptions = {}) {
80 if (title === "") throw new Error("Title cannot be empty.");
81
82 if (!this.monographs.length) await this.refresh();
83
84 const update = !!this.isPublished(noteId);
85
86 const user = await this.db.user.getUser();
87 const token = await this.db.tokenManager.getAccessToken();
88 if (!user || !token) throw new Error("Please login to publish a note.");
89
90 const note = await this.db.notes.note(noteId);
91 if (!note) throw new Error("No such note found.");
92 if (!note.contentId) throw new Error("Cannot publish an empty note.");
93
94 const contentItem = await this.db.content.get(note.contentId);
95
96 if (!contentItem || isDeleted(contentItem))
97 throw new Error("Could not find content for this note.");
98
99 if (contentItem.locked) throw new Error("Cannot published locked notes.");
100
101 const content = await this.db.content.downloadMedia(
102 `monograph-${noteId}`,
103 contentItem,
104 false
105 );
106
107 const monographPasswordsKey = await this.db.user.getMonographPasswordsKey();
108 const monograph: MonographApiRequest = {
109 id: noteId,
110 title,
111 userId: user.id,
112 selfDestruct: opts.selfDestruct || false,
113 ...(opts.password
114 ? {
115 password: monographPasswordsKey
116 ? await this.db
117 .storage()
118 .encrypt(monographPasswordsKey, opts.password)
119 : undefined,
120 encryptedContent: await this.db
121 .storage()
122 .encrypt(
123 { password: opts.password },
124 JSON.stringify({ type: content.type, data: content.data })
125 )
126 }
127 : {
128 password: undefined,
129 content: JSON.stringify({
130 type: content.type,
131 data: content.data
132 })
133 })
134 };
135
136 const deviceId = await this.db.kv().read("deviceId");

Callers 15

sync.test.jsFile · 0.45
monographs.test.jsFile · 0.45
sendSyncProgressEventFunction · 0.45
initializeDatabaseFunction · 0.45
upsertMethod · 0.45
softDeleteMethod · 0.45
deleteMethod · 0.45
updateMethod · 0.45
queueDownloadsMethod · 0.45
queueUploadsMethod · 0.45
cancelMethod · 0.45

Calls 13

refreshMethod · 0.95
isPublishedMethod · 0.95
getUserMethod · 0.80
getAccessTokenMethod · 0.80
noteMethod · 0.80
getMethod · 0.65
encryptMethod · 0.65
readMethod · 0.65
isDeletedFunction · 0.50
downloadMediaMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected