refactor: handle larger files in importer (#2692)

This commit is contained in:
Aman Harwara
2023-12-11 16:30:31 +05:30
committed by GitHub
parent 63e69b5e4b
commit 82d5a36932
22 changed files with 614 additions and 513 deletions

View File

@@ -1,6 +1,7 @@
import { SuperConverterServiceInterface } from '@standardnotes/files'
import { parseFileName } from '@standardnotes/filepicker'
import { Converter } from '../Converter'
import { ConversionResult } from '../ConversionResult'
export class SuperConverter implements Converter {
constructor(private converterService: SuperConverterServiceInterface) {}
@@ -17,9 +18,14 @@ export class SuperConverter implements Converter {
return this.converterService.isValidSuperString(content)
}
convert: Converter['convert'] = async (file, { createNote, readFileAsText }) => {
convert: Converter['convert'] = async (file, { insertNote, readFileAsText }) => {
const content = await readFileAsText(file)
const result: ConversionResult = {
successful: [],
errored: [],
}
if (!this.converterService.isValidSuperString(content)) {
throw new Error('Content is not valid Super JSON')
}
@@ -29,14 +35,16 @@ export class SuperConverter implements Converter {
const createdAtDate = file.lastModified ? new Date(file.lastModified) : new Date()
const updatedAtDate = file.lastModified ? new Date(file.lastModified) : new Date()
return [
createNote({
createdAt: createdAtDate,
updatedAt: updatedAtDate,
title: name,
text: content,
useSuperIfPossible: true,
}),
]
const note = await insertNote({
createdAt: createdAtDate,
updatedAt: updatedAtDate,
title: name,
text: content,
useSuperIfPossible: true,
})
result.successful.push(note)
return result
}
}