fix: exporting multiple notes with same title (#1119)

This commit is contained in:
Aman Harwara
2022-06-19 02:30:49 +05:30
committed by GitHub
parent e7080dfe3f
commit dfbd72b1df
2 changed files with 17 additions and 5 deletions

View File

@@ -222,7 +222,7 @@ const NotesOptions = ({
const format = editor?.package_info?.file_type || 'txt' const format = editor?.package_info?.file_type || 'txt'
return `${note.title}.${format}` return `${note.title}.${format}`
}, },
[application], [application.componentManager],
) )
const downloadSelectedItems = useCallback(async () => { const downloadSelectedItems = useCallback(async () => {
@@ -239,7 +239,7 @@ const NotesOptions = ({
await application.getArchiveService().downloadDataAsZip( await application.getArchiveService().downloadDataAsZip(
notes.map((note) => { notes.map((note) => {
return { return {
filename: getNoteFileName(note), name: getNoteFileName(note),
content: new Blob([note.text]), content: new Blob([note.text]),
} }
}), }),

View File

@@ -20,7 +20,7 @@ function zippableFileName(name: string, suffix = '', format = 'txt'): string {
} }
type ZippableData = { type ZippableData = {
filename: string name: string
content: Blob content: Blob
}[] }[]
@@ -119,9 +119,21 @@ export class ArchiveManager {
const zip = await import('@zip.js/zip.js') const zip = await import('@zip.js/zip.js')
const writer = new zip.ZipWriter(new zip.BlobWriter('application/zip')) const writer = new zip.ZipWriter(new zip.BlobWriter('application/zip'))
const filenameCounts: Record<string, number> = {}
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
const { name, ext } = parseFileName(data[i].filename) const file = data[i]
await writer.add(zippableFileName(name, '', ext), new zip.BlobReader(data[i].content))
const { name, ext } = parseFileName(file.name)
filenameCounts[file.name] = filenameCounts[file.name] == undefined ? 0 : filenameCounts[file.name] + 1
const currentFileNameIndex = filenameCounts[file.name]
await writer.add(
zippableFileName(name, currentFileNameIndex > 0 ? ` - ${currentFileNameIndex}` : '', ext),
new zip.BlobReader(file.content),
)
} }
const zipFileAsBlob = await writer.close() const zipFileAsBlob = await writer.close()