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: lazy load content-type
Abdullah Attaece142e8d853
diff --git a/packages/core/src/api/vault.ts b/packages/core/src/api/vault.tsindex 25a237764..cfb3b76bf 100644--- a/packages/core/src/api/vault.ts+++ b/packages/core/src/api/vault.ts@@ -352,7 +352,7 @@ export default class Vault {}const decryptedContent = await this.decryptContent(content, password);- if (this.db.content.preProcess(decryptedContent)) {+ if (await this.db.content.preProcess(decryptedContent)) {if (!password) password = await this.getVaultPassword();await this.encryptContent(decryptedContent,diff --git a/packages/core/src/collections/content.ts b/packages/core/src/collections/content.tsindex 7dd4ae431..30fd8357f 100644--- a/packages/core/src/collections/content.ts+++ b/packages/core/src/collections/content.ts@@ -174,7 +174,7 @@ export class Content implements ICollection {async get(id: string) {const content = await this.collection.get(id);if (!content || isDeleted(content)) return;- if (!content.locked && this.preProcess(content)) {+ if (!content.locked && (await this.preProcess(content))) {await this.collection.update([content.id], content, { modify: false });}return content;@@ -242,7 +242,7 @@ export class Content implements ICollection {.selectAll().executeTakeFirst()) as ContentItem;if (!content || isDeleted(content)) return;- if (!content.locked && this.preProcess(content)) {+ if (!content.locked && (await this.preProcess(content))) {await this.collection.update([content.id], content, { modify: false });}return content;@@ -267,7 +267,10 @@ export class Content implements ICollection {contentItem: { type: ContentType; data: string },notify = true) {- const content = getContentFromData(contentItem.type, contentItem.data);+ const content = await getContentFromData(+ contentItem.type,+ contentItem.data+ );if (!content) return contentItem;contentItem.data = await content.insertMedia(async (hashes) => {const attachments = await this.db.attachments.all@@ -300,13 +303,16 @@ export class Content implements ICollection {async removeAttachments(id: string, hashes: string[]) {const contentItem = await this.get(id);if (!contentItem || isCipher(contentItem.data)) return;- const content = getContentFromData(contentItem.type, contentItem.data);+ const content = await getContentFromData(+ contentItem.type,+ contentItem.data+ );if (!content) return;contentItem.data = content.removeAttachments(hashes);await this.add(contentItem);}- preProcess(content: NoteContent<false>) {+ async preProcess(content: NoteContent<false>) {let changed = false;// #MIGRATION: convert tiny to tiptap@@ -318,9 +324,8 @@ export class Content implements ICollection {// add block id on all appropriate nodesif (!content.data.includes("data-block-id")) {- content.data = getContentFromData(- content.type,- content.data+ content.data = (+ await getContentFromData(content.type, content.data)).insertBlockIds();changed = true;}@@ -329,7 +334,10 @@ export class Content implements ICollection {}async postProcess(contentItem: NoteContent<false> & { noteId: string }) {- const content = getContentFromData(contentItem.type, contentItem.data);+ const content = await getContentFromData(+ contentItem.type,+ contentItem.data+ );if (!content) return contentItem.data;const { data, hashes, internalLinks } = await content.postProcess(this.db.attachments.save.bind(this.db.attachments)diff --git a/packages/core/src/collections/notes.ts b/packages/core/src/collections/notes.tsindex 59690683b..04d044e77 100644--- a/packages/core/src/collections/notes.ts+++ b/packages/core/src/collections/notes.ts@@ -88,7 +88,7 @@ export class Notes implements ICollection {logger.debug("saving content", { id });const { type, data } = item.content;- const content = getContentFromData(type, data);+ const content = await getContentFromData(type, data);if (!content) throw new Error("Invalid content type.");headline = getNoteHeadline(content);@@ -293,7 +293,7 @@ export class Notes implements ICollection {false): contentItem;- const content = getContentFromData(type, data);+ const content = await getContentFromData(type, data);return format === "html"? content.toHTML(): format === "md"@@ -420,15 +420,16 @@ export class Notes implements ICollection {const content = await this.db.content.findByNoteId(id);if (!content || content.locked) return [];- return getContentFromData(content.type, content.data).extract("blocks")- .blocks;+ return (await getContentFromData(content.type, content.data)).extract(+ "blocks"+ ).blocks;}async contentBlocksWithLinks(id: string) {const content = await this.db.content.findByNoteId(id);if (!content || content.locked) return [];- return getContentFromData(content.type, content.data).extract(+ return (await getContentFromData(content.type, content.data)).extract("blocksWithLink").blocks;}@@ -437,7 +438,7 @@ export class Notes implements ICollection {const content = await this.db.content.findByNoteId(id);if (!content || content.locked) return [];- return getContentFromData(content.type, content.data).extract(+ return (await getContentFromData(content.type, content.data)).extract("internalLinks").internalLinks;}diff --git a/packages/core/src/content-types/index.ts b/packages/core/src/content-types/index.tsindex fa892b09e..722772180 100644--- a/packages/core/src/content-types/index.ts+++ b/packages/core/src/content-types/index.ts@@ -18,17 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import { ContentType } from "../types.js";-import { Tiptap } from "./tiptap.js";-export function getContentFromData(type: ContentType, data: string) {+export async function getContentFromData(type: ContentType, data: string) {switch (type) {- case "tiptap":+ case "tiptap": {+ const { Tiptap } = await import("./tiptap.js");return new Tiptap(data);+ }default:throw new Error(`Unknown content type: "${type}". Please report this error at [email protected].`);}}--export * from "./tiptap.js";diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex dd28d9038..f624f0ff1 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -43,3 +43,4 @@ export { VAULT_ERRORS } from "./api/vault.js";export type { SyncOptions } from "./api/sync/index.js";export { sanitizeTag } from "./collections/tags.js";export { default as DataURL } from "./utils/dataurl.js";+export { type ResolveInternalLink } from "./content-types/tiptap.js";