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

Method lockNote

packages/core/src/api/vault.ts:288–343  ·  view source on GitHub ↗
(
    item: {
      content?: NoteContent<false>;
      sessionId?: string;
      id: string;
    },
    password: string
  )

Source from the content-addressed store, hash-verified

286 }
287
288 private async lockNote(
289 item: {
290 content?: NoteContent<false>;
291 sessionId?: string;
292 id: string;
293 },
294 password: string
295 ) {
296 const vault = await this.db.vaults.default();
297 if (!vault) throw new Error(VAULT_ERRORS.noVault);
298
299 const { id, content, sessionId } = item;
300 let { type, data } = content || {};
301
302 const locked = await this.db.relations.from(vault, "note").has(id);
303
304 // Case: when note is being newly locked
305 if (!locked && (!data || !type)) {
306 const rawContent = await this.db.content.findByNoteId(id);
307 if (rawContent?.locked) {
308 await this.db.relations.add(vault, {
309 id,
310 type: "note"
311 });
312 return id;
313 }
314 // NOTE:
315 // At this point, the note already has all the attachments extracted
316 // so we should just encrypt it as normal.
317 data = rawContent?.data || "<p></p>";
318 type = rawContent?.type || "tiptap";
319 } else if (data && type) {
320 data = await this.db.content.postProcess({
321 data,
322 type,
323 noteId: id
324 });
325 }
326
327 await this.db.notes.add({
328 id,
329 headline: "",
330 dateEdited: Date.now(),
331 contentId:
332 data && type
333 ? await this.encryptContent({ data, type }, id, password, sessionId)
334 : undefined
335 });
336
337 await this.db.relations.add(vault, {
338 id,
339 type: "note"
340 });
341
342 return id;
343 }
344
345 private async unlockNote(

Callers 2

addMethod · 0.95
saveMethod · 0.95

Calls 7

encryptContentMethod · 0.95
defaultMethod · 0.80
fromMethod · 0.80
findByNoteIdMethod · 0.80
hasMethod · 0.45
addMethod · 0.45
postProcessMethod · 0.45

Tested by

no test coverage detected