feat: Added "Import" option in the account menu that allows you to import from plaintext/markdown files, Evernote exports, Simplenote exports, Google Keep exports and also convert Aegis exports to TokenVault notes

This commit is contained in:
Aman Harwara
2022-12-30 01:22:59 +05:30
committed by GitHub
parent f1ae7a53ef
commit 6e4bf2417a
25 changed files with 755 additions and 207 deletions

View File

@@ -0,0 +1,36 @@
import { ContentType } from '@standardnotes/common'
import { parseFileName } from '@standardnotes/filepicker'
import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models'
import { WebApplicationInterface } from '@standardnotes/services'
import { readFileAsText } from '../Utils'
export class PlaintextConverter {
constructor(protected application: WebApplicationInterface) {}
static isValidPlaintextFile(file: File): boolean {
return file.type === 'text/plain' || file.type === 'text/markdown'
}
async convertPlaintextFileToNote(file: File): Promise<DecryptedTransferPayload<NoteContent>> {
const content = await readFileAsText(file)
const { name } = parseFileName(file.name)
const createdAtDate = file.lastModified ? new Date(file.lastModified) : new Date()
const updatedAtDate = file.lastModified ? new Date(file.lastModified) : new Date()
return {
created_at: createdAtDate,
created_at_timestamp: createdAtDate.getTime(),
updated_at: updatedAtDate,
updated_at_timestamp: updatedAtDate.getTime(),
uuid: this.application.generateUUID(),
content_type: ContentType.Note,
content: {
title: name,
text: content,
references: [],
},
}
}
}