Skip to content

Commit

Permalink
refactor: importer
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Dec 7, 2023
1 parent 2cc2ddd commit 620cd96
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class AegisToAuthenticatorConverter implements Converter {
text,
noteType: NoteType.Authentication,
editorIdentifier: NativeFeatureIdentifier.TYPES.TokenVaultEditor,
useSuperIfPossible: false,
}),
]
}
Expand Down
1 change: 1 addition & 0 deletions packages/ui-services/src/Import/Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type CreateNoteFn = (options: {
pinned?: boolean
trashed?: boolean
editorIdentifier?: NoteContent['editorIdentifier']
useSuperIfPossible: boolean
}) => DecryptedTransferPayload<NoteContent>

export type CreateTagFn = (options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import utc from 'dayjs/plugin/utc'
import { GenerateUuid } from '@standardnotes/services'
import { NoteType } from '@standardnotes/features'
import MD5 from 'crypto-js/md5'
import Base64 from 'crypto-js/enc-base64'
import { Converter } from '../Converter'
Expand Down Expand Up @@ -109,7 +108,7 @@ export class EvernoteConverter implements Converter {
updatedAt: updatedAtDate,
title: !title ? `Imported note ${index + 1} from Evernote` : title,
text,
noteType: NoteType.Super,
useSuperIfPossible: canUseSuper,
})

const xmlTags = xmlNote.getElementsByTagName('tag')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models'
import { NoteType } from '@standardnotes/features'
import { Converter, CreateNoteFn } from '../Converter'

type Content =
Expand Down Expand Up @@ -125,7 +124,7 @@ export class GoogleKeepConverter implements Converter {
updatedAt: date,
title: title,
text: content,
noteType: NoteType.Super,
useSuperIfPossible: true,
})
}

Expand Down Expand Up @@ -181,7 +180,7 @@ export class GoogleKeepConverter implements Converter {
archived: Boolean(parsed.isArchived),
trashed: Boolean(parsed.isTrashed),
pinned: Boolean(parsed.isPinned),
noteType: NoteType.Super,
useSuperIfPossible: true,
})
} catch (e) {
console.error(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { NoteType } from '@standardnotes/features'
import { parseFileName } from '@standardnotes/filepicker'
import { Converter } from '../Converter'

Expand Down Expand Up @@ -33,7 +32,7 @@ export class HTMLConverter implements Converter {
updatedAt: updatedAtDate,
title: name,
text,
noteType: NoteType.Super,
useSuperIfPossible: true,
}),
]
}
Expand Down
7 changes: 5 additions & 2 deletions packages/ui-services/src/Import/Importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class Importer {
trashed,
archived,
pinned,
useSuperIfPossible,
}) => {
if (noteType === NoteType.Super && !this.isEntitledToSuper()) {
noteType = undefined
Expand All @@ -111,6 +112,8 @@ export class Importer {
editorIdentifier = undefined
}

const shouldUseSuper = useSuperIfPossible && this.isEntitledToSuper()

return {
created_at: createdAt,
created_at_timestamp: createdAt.getTime(),
Expand All @@ -122,11 +125,11 @@ export class Importer {
title,
text,
references: [],
noteType,
noteType: shouldUseSuper ? NoteType.Super : noteType,
trashed,
archived,
pinned,
editorIdentifier,
editorIdentifier: shouldUseSuper ? NativeFeatureIdentifier.TYPES.SuperEditor : editorIdentifier,
},
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { parseFileName } from '@standardnotes/filepicker'
import { Converter } from '../Converter'
import { NoteType } from '@standardnotes/features'

export class PlaintextConverter implements Converter {
constructor() {}
Expand Down Expand Up @@ -35,7 +34,7 @@ export class PlaintextConverter implements Converter {
updatedAt: updatedAtDate,
title: name,
text: convertMarkdownToSuper(content),
noteType: NoteType.Super,
useSuperIfPossible: true,
}),
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class SimplenoteConverter implements Converter {
title,
text: content,
trashed,
useSuperIfPossible: true,
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SuperConverterServiceInterface } from '@standardnotes/files'
import { parseFileName } from '@standardnotes/filepicker'
import { NoteType } from '@standardnotes/features'
import { Converter } from '../Converter'

export class SuperConverter implements Converter {
Expand Down Expand Up @@ -36,7 +35,7 @@ export class SuperConverter implements Converter {
updatedAt: updatedAtDate,
title: name,
text: content,
noteType: NoteType.Super,
useSuperIfPossible: true,
}),
]
}
Expand Down

0 comments on commit 620cd96

Please sign in to comment.