feat: Importing markdown files from the Import dialog will now automatically use Super notes
This commit is contained in:
@@ -63,7 +63,7 @@ export class Importer {
|
|||||||
this.aegisConverter = new AegisToAuthenticatorConverter(_generateUuid)
|
this.aegisConverter = new AegisToAuthenticatorConverter(_generateUuid)
|
||||||
this.googleKeepConverter = new GoogleKeepConverter(this.superConverterService, _generateUuid)
|
this.googleKeepConverter = new GoogleKeepConverter(this.superConverterService, _generateUuid)
|
||||||
this.simplenoteConverter = new SimplenoteConverter(_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.evernoteConverter = new EvernoteConverter(this.superConverterService, _generateUuid)
|
||||||
this.htmlConverter = new HTMLConverter(this.superConverterService, _generateUuid)
|
this.htmlConverter = new HTMLConverter(this.superConverterService, _generateUuid)
|
||||||
this.superConverter = new SuperConverter(this.superConverterService, _generateUuid)
|
this.superConverter = new SuperConverter(this.superConverterService, _generateUuid)
|
||||||
@@ -134,7 +134,7 @@ export class Importer {
|
|||||||
} else if (type === 'evernote') {
|
} else if (type === 'evernote') {
|
||||||
return await this.evernoteConverter.convertENEXFileToNotesAndTags(file, isEntitledToSuper)
|
return await this.evernoteConverter.convertENEXFileToNotesAndTags(file, isEntitledToSuper)
|
||||||
} else if (type === 'plaintext') {
|
} else if (type === 'plaintext') {
|
||||||
return [await this.plaintextConverter.convertPlaintextFileToNote(file)]
|
return [await this.plaintextConverter.convertPlaintextFileToNote(file, isEntitledToSuper)]
|
||||||
} else if (type === 'html') {
|
} else if (type === 'html') {
|
||||||
return [await this.htmlConverter.convertHTMLFileToNote(file, isEntitledToSuper)]
|
return [await this.htmlConverter.convertHTMLFileToNote(file, isEntitledToSuper)]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,23 @@ import { parseFileName } from '@standardnotes/filepicker'
|
|||||||
import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models'
|
import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models'
|
||||||
import { readFileAsText } from '../Utils'
|
import { readFileAsText } from '../Utils'
|
||||||
import { GenerateUuid } from '@standardnotes/services'
|
import { GenerateUuid } from '@standardnotes/services'
|
||||||
|
import { SuperConverterServiceInterface } from '@standardnotes/files'
|
||||||
|
import { NativeFeatureIdentifier, NoteType } from '@standardnotes/features'
|
||||||
|
|
||||||
export class PlaintextConverter {
|
export class PlaintextConverter {
|
||||||
constructor(private _generateUuid: GenerateUuid) {}
|
constructor(
|
||||||
|
private superConverterService: SuperConverterServiceInterface,
|
||||||
|
private _generateUuid: GenerateUuid,
|
||||||
|
) {}
|
||||||
|
|
||||||
static isValidPlaintextFile(file: File): boolean {
|
static isValidPlaintextFile(file: File): boolean {
|
||||||
return file.type === 'text/plain' || file.type === 'text/markdown'
|
return file.type === 'text/plain' || file.type === 'text/markdown'
|
||||||
}
|
}
|
||||||
|
|
||||||
async convertPlaintextFileToNote(file: File): Promise<DecryptedTransferPayload<NoteContent>> {
|
async convertPlaintextFileToNote(
|
||||||
|
file: File,
|
||||||
|
isEntitledToSuper: boolean,
|
||||||
|
): Promise<DecryptedTransferPayload<NoteContent>> {
|
||||||
const content = await readFileAsText(file)
|
const content = await readFileAsText(file)
|
||||||
|
|
||||||
const { name } = parseFileName(file.name)
|
const { name } = parseFileName(file.name)
|
||||||
@@ -19,6 +27,8 @@ export class PlaintextConverter {
|
|||||||
const createdAtDate = file.lastModified ? new Date(file.lastModified) : new Date()
|
const createdAtDate = file.lastModified ? new Date(file.lastModified) : new Date()
|
||||||
const updatedAtDate = 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 {
|
return {
|
||||||
created_at: createdAtDate,
|
created_at: createdAtDate,
|
||||||
created_at_timestamp: createdAtDate.getTime(),
|
created_at_timestamp: createdAtDate.getTime(),
|
||||||
@@ -28,8 +38,16 @@ export class PlaintextConverter {
|
|||||||
content_type: ContentType.TYPES.Note,
|
content_type: ContentType.TYPES.Note,
|
||||||
content: {
|
content: {
|
||||||
title: name,
|
title: name,
|
||||||
text: content,
|
text: shouldConvertToSuper
|
||||||
|
? this.superConverterService.convertOtherFormatToSuperString(content, 'md')
|
||||||
|
: content,
|
||||||
references: [],
|
references: [],
|
||||||
|
...(isEntitledToSuper
|
||||||
|
? {
|
||||||
|
noteType: NoteType.Super,
|
||||||
|
editorIdentifier: NativeFeatureIdentifier.TYPES.SuperEditor,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user