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

@@ -3,7 +3,6 @@ import { ContentType } from '@standardnotes/common'
import { readFileAsText } from '../Utils'
import { FeatureIdentifier, NoteType } from '@standardnotes/features'
import { WebApplicationInterface } from '@standardnotes/services'
import { Importer } from '../Importer'
type AegisData = {
db: {
@@ -18,6 +17,8 @@ type AegisData = {
}
}
const AegisEntryTypes = ['hotp', 'totp', 'steam', 'yandex'] as const
type AuthenticatorEntry = {
service: string
account: string
@@ -25,9 +26,26 @@ type AuthenticatorEntry = {
notes: string
}
export class AegisToAuthenticatorConverter extends Importer {
constructor(protected override application: WebApplicationInterface) {
super(application)
export class AegisToAuthenticatorConverter {
constructor(protected application: WebApplicationInterface) {}
static isValidAegisJson(json: any): boolean {
return json.db && json.db.entries && json.db.entries.every((entry: any) => AegisEntryTypes.includes(entry.type))
}
async convertAegisBackupFileToNote(
file: File,
addEditorInfo: boolean,
): Promise<DecryptedTransferPayload<NoteContent>> {
const content = await readFileAsText(file)
const entries = this.parseEntries(content)
if (!entries) {
throw new Error('Could not parse entries')
}
return this.createNoteFromEntries(entries, file, addEditorInfo)
}
createNoteFromEntries(
@@ -57,21 +75,6 @@ export class AegisToAuthenticatorConverter extends Importer {
}
}
async convertAegisBackupFileToNote(
file: File,
addEditorInfo: boolean,
): Promise<DecryptedTransferPayload<NoteContent>> {
const content = await readFileAsText(file)
const entries = this.parseEntries(content)
if (!entries) {
throw new Error('Could not parse entries')
}
return this.createNoteFromEntries(entries, file, addEditorInfo)
}
parseEntries(data: string): AuthenticatorEntry[] | null {
try {
const json = JSON.parse(data) as AegisData