-
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: super note import option in import modal
- Loading branch information
1 parent
21b34a5
commit 4207348
Showing
9 changed files
with
128 additions
and
33 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages/files/src/Domain/Service/SuperConverterServiceInterface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export interface SuperConverterServiceInterface { | ||
isValidSuperString(superString: string): boolean | ||
convertString: (superString: string, toFormat: 'txt' | 'md' | 'html' | 'json') => string | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/ui-services/src/Import/HTMLConverter/HTMLConverter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { GenerateUuid } from '@standardnotes/services' | ||
|
||
export class HTMLConverter { | ||
constructor(_generateUuid: GenerateUuid) {} | ||
|
||
static isHTMLFile(file: File): boolean { | ||
return file.type === 'text/html' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/ui-services/src/Import/SuperConverter/SuperConverter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { SuperConverterServiceInterface } from '@standardnotes/files' | ||
import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models' | ||
import { GenerateUuid } from '@standardnotes/services' | ||
import { readFileAsText } from '../Utils' | ||
import { parseFileName } from '@standardnotes/filepicker' | ||
import { ContentType } from '@standardnotes/domain-core' | ||
import { NativeFeatureIdentifier, NoteType } from '@standardnotes/features' | ||
|
||
export class SuperConverter { | ||
constructor( | ||
private converterService: SuperConverterServiceInterface, | ||
private _generateUuid: GenerateUuid, | ||
) {} | ||
|
||
async convertSuperFileToNote(file: File): Promise<DecryptedTransferPayload<NoteContent>> { | ||
const content = await readFileAsText(file) | ||
|
||
if (!this.converterService.isValidSuperString(content)) { | ||
throw new Error('Content is not valid Super JSON') | ||
} | ||
|
||
const { name } = parseFileName(file.name) | ||
|
||
const createdAtDate = file.lastModified ? new Date(file.lastModified) : new Date() | ||
const updatedAtDate = file.lastModified ? new Date(file.lastModified) : new Date() | ||
|
||
return { | ||
created_at: createdAtDate, | ||
created_at_timestamp: createdAtDate.getTime(), | ||
updated_at: updatedAtDate, | ||
updated_at_timestamp: updatedAtDate.getTime(), | ||
uuid: this._generateUuid.execute().getValue(), | ||
content_type: ContentType.TYPES.Note, | ||
content: { | ||
title: name, | ||
text: content, | ||
references: [], | ||
noteType: NoteType.Super, | ||
editorIdentifier: NativeFeatureIdentifier.TYPES.SuperEditor, | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters