refactor: handle larger files in importer (#2692)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user