-
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix duplicate file name error when exporting notes and refacto…
…r file name utils (#2877) [skip e2e]
- Loading branch information
1 parent
71d2dbc
commit c3265d7
Showing
16 changed files
with
61 additions
and
56 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
packages/ui-services/src/Import/PlaintextConverter/PlaintextConverter.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
2 changes: 1 addition & 1 deletion
2
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
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,38 @@ | ||
export function parseFileName(fileName: string): { | ||
name: string | ||
ext: string | ||
} { | ||
const pattern = /(?:\.([^.]+))$/ | ||
const extMatches = pattern.exec(fileName) | ||
const ext = extMatches?.[1] || '' | ||
const name = fileName.includes('.') ? fileName.substring(0, fileName.lastIndexOf('.')) : fileName | ||
|
||
return { name, ext } | ||
} | ||
|
||
export function sanitizeFileName(name: string): string { | ||
return name.trim().replace(/[.\\/:"?*|<>]/g, '_') | ||
} | ||
|
||
export function truncateFileName(name: string, maxLength: number): string { | ||
return name.length > maxLength ? name.slice(0, maxLength) : name | ||
} | ||
|
||
const MaxFileNameLength = 100 | ||
|
||
export function createZippableFileName( | ||
name: string, | ||
suffix = '', | ||
format = 'txt', | ||
maxLength = MaxFileNameLength, | ||
): string { | ||
const sanitizedName = sanitizeFileName(name) | ||
const truncatedName = truncateFileName(sanitizedName, maxLength) | ||
const nameEnd = suffix + '.' + format | ||
return truncatedName + nameEnd | ||
} | ||
|
||
export function parseAndCreateZippableFileName(name: string, suffix = '') { | ||
const { name: parsedName, ext } = parseFileName(name) | ||
return createZippableFileName(parsedName, suffix, ext) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
packages/web/src/javascripts/Components/SuperEditor/Lexical/Nodes/FileExportNode.tsx
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
3 changes: 1 addition & 2 deletions
3
packages/web/src/javascripts/NativeMobileWeb/DownloadBlobOnAndroid.tsx
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