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:
@@ -1,14 +1,91 @@
|
||||
import { WebApplicationInterface } from '@standardnotes/services'
|
||||
import { DecryptedTransferPayload } from '@standardnotes/snjs'
|
||||
import { parseFileName } from '@standardnotes/filepicker'
|
||||
import { FeatureStatus, WebApplicationInterface } from '@standardnotes/services'
|
||||
import { FeatureIdentifier } from '@standardnotes/features'
|
||||
import { AegisToAuthenticatorConverter } from './AegisConverter/AegisToAuthenticatorConverter'
|
||||
import { EvernoteConverter } from './EvernoteConverter/EvernoteConverter'
|
||||
import { GoogleKeepConverter } from './GoogleKeepConverter/GoogleKeepConverter'
|
||||
import { PlaintextConverter } from './PlaintextConverter/PlaintextConverter'
|
||||
import { SimplenoteConverter } from './SimplenoteConverter/SimplenoteConverter'
|
||||
import { readFileAsText } from './Utils'
|
||||
import { DecryptedTransferPayload } from '@standardnotes/models'
|
||||
|
||||
export type NoteImportType = 'plaintext' | 'evernote' | 'google-keep' | 'simplenote' | 'aegis'
|
||||
|
||||
export class Importer {
|
||||
constructor(protected application: WebApplicationInterface) {}
|
||||
aegisConverter: AegisToAuthenticatorConverter
|
||||
googleKeepConverter: GoogleKeepConverter
|
||||
simplenoteConverter: SimplenoteConverter
|
||||
plaintextConverter: PlaintextConverter
|
||||
evernoteConverter: EvernoteConverter
|
||||
|
||||
async importFromTransferPayloads(payloads: DecryptedTransferPayload[]): Promise<void> {
|
||||
for (const payload of payloads) {
|
||||
const itemPayload = this.application.items.createPayloadFromObject(payload)
|
||||
const item = this.application.items.createItemFromPayload(itemPayload)
|
||||
await this.application.mutator.insertItem(item)
|
||||
constructor(protected application: WebApplicationInterface) {
|
||||
this.aegisConverter = new AegisToAuthenticatorConverter(application)
|
||||
this.googleKeepConverter = new GoogleKeepConverter(application)
|
||||
this.simplenoteConverter = new SimplenoteConverter(application)
|
||||
this.plaintextConverter = new PlaintextConverter(application)
|
||||
this.evernoteConverter = new EvernoteConverter(application)
|
||||
}
|
||||
|
||||
static detectService = async (file: File): Promise<NoteImportType | null> => {
|
||||
const content = await readFileAsText(file)
|
||||
|
||||
const { ext } = parseFileName(file.name)
|
||||
|
||||
if (ext === 'enex') {
|
||||
return 'evernote'
|
||||
}
|
||||
|
||||
try {
|
||||
const json = JSON.parse(content)
|
||||
|
||||
if (AegisToAuthenticatorConverter.isValidAegisJson(json)) {
|
||||
return 'aegis'
|
||||
}
|
||||
|
||||
if (GoogleKeepConverter.isValidGoogleKeepJson(json)) {
|
||||
return 'google-keep'
|
||||
}
|
||||
|
||||
if (SimplenoteConverter.isValidSimplenoteJson(json)) {
|
||||
return 'simplenote'
|
||||
}
|
||||
} catch {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
if (PlaintextConverter.isValidPlaintextFile(file)) {
|
||||
return 'plaintext'
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
async getPayloadsFromFile(file: File, type: NoteImportType): Promise<DecryptedTransferPayload[]> {
|
||||
if (type === 'aegis') {
|
||||
const isEntitledToAuthenticator =
|
||||
this.application.features.getFeatureStatus(FeatureIdentifier.TokenVaultEditor) === FeatureStatus.Entitled
|
||||
return [await this.aegisConverter.convertAegisBackupFileToNote(file, isEntitledToAuthenticator)]
|
||||
} else if (type === 'google-keep') {
|
||||
return [await this.googleKeepConverter.convertGoogleKeepBackupFileToNote(file, true)]
|
||||
} else if (type === 'simplenote') {
|
||||
return await this.simplenoteConverter.convertSimplenoteBackupFileToNotes(file)
|
||||
} else if (type === 'evernote') {
|
||||
return await this.evernoteConverter.convertENEXFileToNotesAndTags(file, false)
|
||||
} else if (type === 'plaintext') {
|
||||
return [await this.plaintextConverter.convertPlaintextFileToNote(file)]
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
async importFromTransferPayloads(payloads: DecryptedTransferPayload[]) {
|
||||
const insertedItems = await Promise.all(
|
||||
payloads.map(async (payload) => {
|
||||
const itemPayload = this.application.items.createPayloadFromObject(payload)
|
||||
const item = this.application.items.createItemFromPayload(itemPayload)
|
||||
return this.application.mutator.insertItem(item)
|
||||
}),
|
||||
)
|
||||
return insertedItems
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user