Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const NotesOptions = ({
const format = editor?.package_info?.file_type || 'txt'
return `${note.title}.${format}`
},
[application],
[application.componentManager],
)

const downloadSelectedItems = useCallback(async () => {
Expand All @@ -239,7 +239,7 @@ const NotesOptions = ({
await application.getArchiveService().downloadDataAsZip(
notes.map((note) => {
return {
filename: getNoteFileName(note),
name: getNoteFileName(note),
content: new Blob([note.text]),
}
}),
Expand Down
18 changes: 15 additions & 3 deletions packages/web/src/javascripts/Services/ArchiveManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function zippableFileName(name: string, suffix = '', format = 'txt'): string {
}

type ZippableData = {
filename: string
name: string
content: Blob
}[]

Expand Down Expand Up @@ -119,9 +119,21 @@ export class ArchiveManager {
const zip = await import('@zip.js/zip.js')
const writer = new zip.ZipWriter(new zip.BlobWriter('application/zip'))

const filenameCounts: Record<string, number> = {}

for (let i = 0; i < data.length; i++) {
const { name, ext } = parseFileName(data[i].filename)
await writer.add(zippableFileName(name, '', ext), new zip.BlobReader(data[i].content))
const file = data[i]

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()
Expand Down