Skip to content

Commit

Permalink
Add the extension to the flatten Blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Apr 11, 2024
1 parent 0b8cf26 commit 1cf6a7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/stores/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ export const useProjectStore = defineStore('project', () => {

return `${project.name}_layer=${layer}${lv}_${seq}.${ext}`
}

return path.join('-')
},
})
})
Expand Down
13 changes: 11 additions & 2 deletions src/utils/blobJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {mapPromises, mapValuePromises} from './promise'
type Path = (string | number)[]

interface SaveBlobJsonOptions {
pathToFilename?: (path: Path) => string
pathToFilename?: (path: Path) => string | undefined
saveBlob: (
directoryHandle: FileSystemDirectoryHandle,
filename: string,
Expand Down Expand Up @@ -50,7 +50,16 @@ export async function saveBlobJson(
} else if (isPlainObject(data)) {
return mapValuePromises(data, (value, key) => flat(value, [...path, key]))
} else if (data instanceof Blob) {
const filename = options.pathToFilename?.(path) ?? path.join('-')
let filename = options.pathToFilename?.(path) ?? path.join('.')

if (data instanceof File) {
const ext = data.name.split('.').pop()

if (ext) {
filename += `.${ext}`
}
}

await options.saveBlob(directoryHandle, filename, data)
return {
$type: 'blob',
Expand Down

0 comments on commit 1cf6a7a

Please sign in to comment.