From 3bf670ece754df3f452a3ae305830c772687d36a Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Mon, 6 Nov 2023 16:08:29 +0530 Subject: [PATCH] feat: Importing markdown files from the Import dialog will now automatically use Super notes --- packages/ui-services/src/Import/Importer.ts | 4 ++-- .../PlaintextConverter/PlaintextConverter.ts | 24 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/ui-services/src/Import/Importer.ts b/packages/ui-services/src/Import/Importer.ts index 5d5ea4d78..636532dbc 100644 --- a/packages/ui-services/src/Import/Importer.ts +++ b/packages/ui-services/src/Import/Importer.ts @@ -63,7 +63,7 @@ export class Importer { this.aegisConverter = new AegisToAuthenticatorConverter(_generateUuid) this.googleKeepConverter = new GoogleKeepConverter(this.superConverterService, _generateUuid) this.simplenoteConverter = new SimplenoteConverter(_generateUuid) - this.plaintextConverter = new PlaintextConverter(_generateUuid) + this.plaintextConverter = new PlaintextConverter(this.superConverterService, _generateUuid) this.evernoteConverter = new EvernoteConverter(this.superConverterService, _generateUuid) this.htmlConverter = new HTMLConverter(this.superConverterService, _generateUuid) this.superConverter = new SuperConverter(this.superConverterService, _generateUuid) @@ -134,7 +134,7 @@ export class Importer { } else if (type === 'evernote') { return await this.evernoteConverter.convertENEXFileToNotesAndTags(file, isEntitledToSuper) } else if (type === 'plaintext') { - return [await this.plaintextConverter.convertPlaintextFileToNote(file)] + return [await this.plaintextConverter.convertPlaintextFileToNote(file, isEntitledToSuper)] } else if (type === 'html') { return [await this.htmlConverter.convertHTMLFileToNote(file, isEntitledToSuper)] } diff --git a/packages/ui-services/src/Import/PlaintextConverter/PlaintextConverter.ts b/packages/ui-services/src/Import/PlaintextConverter/PlaintextConverter.ts index 1b1d965ae..6598d7233 100644 --- a/packages/ui-services/src/Import/PlaintextConverter/PlaintextConverter.ts +++ b/packages/ui-services/src/Import/PlaintextConverter/PlaintextConverter.ts @@ -3,15 +3,23 @@ import { parseFileName } from '@standardnotes/filepicker' import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models' import { readFileAsText } from '../Utils' import { GenerateUuid } from '@standardnotes/services' +import { SuperConverterServiceInterface } from '@standardnotes/files' +import { NativeFeatureIdentifier, NoteType } from '@standardnotes/features' export class PlaintextConverter { - constructor(private _generateUuid: GenerateUuid) {} + constructor( + private superConverterService: SuperConverterServiceInterface, + private _generateUuid: GenerateUuid, + ) {} static isValidPlaintextFile(file: File): boolean { return file.type === 'text/plain' || file.type === 'text/markdown' } - async convertPlaintextFileToNote(file: File): Promise> { + async convertPlaintextFileToNote( + file: File, + isEntitledToSuper: boolean, + ): Promise> { const content = await readFileAsText(file) const { name } = parseFileName(file.name) @@ -19,6 +27,8 @@ export class PlaintextConverter { const createdAtDate = file.lastModified ? new Date(file.lastModified) : new Date() const updatedAtDate = file.lastModified ? new Date(file.lastModified) : new Date() + const shouldConvertToSuper = file.type === 'text/markdown' && isEntitledToSuper + return { created_at: createdAtDate, created_at_timestamp: createdAtDate.getTime(), @@ -28,8 +38,16 @@ export class PlaintextConverter { content_type: ContentType.TYPES.Note, content: { title: name, - text: content, + text: shouldConvertToSuper + ? this.superConverterService.convertOtherFormatToSuperString(content, 'md') + : content, references: [], + ...(isEntitledToSuper + ? { + noteType: NoteType.Super, + editorIdentifier: NativeFeatureIdentifier.TYPES.SuperEditor, + } + : {}), }, } }