Skip to content

Commit

Permalink
fix(upload-client): filter null values from the files property of…
Browse files Browse the repository at this point in the history
… group info
  • Loading branch information
nd0ut committed Oct 18, 2023
1 parent f2f9a4f commit 55c94fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/upload-client/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export type GroupInfo = {
datetimeStored: string | null
filesCount: string
cdnUrl: string
files: GroupFileInfo[]
// An array may contain null values if a file has been removed.
files: (GroupFileInfo | null)[]
url: string
id: GroupId
}
Expand Down
12 changes: 6 additions & 6 deletions packages/upload-client/src/tools/UploadcareGroup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GroupId, GroupInfo } from '../api/types'
import { GroupFileInfo, GroupId, GroupInfo } from '../api/types'
import defaultSettings from '../defaultSettings'
import { UploadcareFile } from './UploadcareFile'

Expand All @@ -23,16 +23,16 @@ export class UploadcareGroup {
) {
this.uuid = groupInfo.id
this.filesCount = groupInfo.filesCount
this.totalSize = Object.values(groupInfo.files).reduce(
const groupFiles = groupInfo.files.filter(Boolean) as GroupFileInfo[]
this.totalSize = Object.values(groupFiles).reduce(
(acc, file) => acc + file.size,
0
)
this.isStored = !!groupInfo.datetimeStored
this.isImage = !!Object.values(groupInfo.files).filter(
(file) => file.isImage
).length
this.isImage = !!Object.values(groupFiles).filter((file) => file.isImage)
.length
this.cdnUrl = groupInfo.cdnUrl
this.files = groupInfo.files.map(
this.files = groupFiles.map(
(fileInfo) => new UploadcareFile(fileInfo, { baseCDN })
)
this.createdAt = groupInfo.datetimeCreated
Expand Down

0 comments on commit 55c94fd

Please sign in to comment.