Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/small-pillows-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tus/azure-store": patch
---

Fix metadata parsing bug
10 changes: 9 additions & 1 deletion packages/azure-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,15 @@ export class AzureStore extends DataStore {
const upload = JSON.parse(propertyData.metadata.upload) as Upload
// Metadata is base64 encoded to avoid errors for non-ASCII characters
// so we need to decode it separately
upload.metadata = Metadata.parse(JSON.stringify(upload.metadata ?? {}))
let metadataStr
if (typeof upload.metadata === 'string') {
metadataStr = upload.metadata
} else if (upload.metadata && typeof upload.metadata === 'object') {
metadataStr = JSON.stringify(upload.metadata ?? {})
} else {
metadataStr = '{}'
}
upload.metadata = Metadata.parse(metadataStr)
Comment on lines +120 to +128
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is overprotective for no reason? It should be as simple as this? Maybe undefined instead of {} not sure.

Suggested change
let metadataStr
if (typeof upload.metadata === 'string') {
metadataStr = upload.metadata
} else if (upload.metadata && typeof upload.metadata === 'object') {
metadataStr = JSON.stringify(upload.metadata ?? {})
} else {
metadataStr = '{}'
}
upload.metadata = Metadata.parse(metadataStr)
upload.metadata = upload.metadata ? Metadata.parse(JSON.stringify(upload.metadata)) : {}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were cases when upload.metadata was already a string.
That's why I added this check

    if (typeof upload.metadata === 'string') {
      metadataStr = upload.metadata
    }

I could simplify it to look like this

    let metadataStr
    if (typeof upload.metadata === 'string') {
      metadataStr = upload.metadata
    } else if (upload.metadata && typeof upload.metadata === 'object') {
      metadataStr = JSON.stringify(upload.metadata ?? {})
    }
    upload.metadata = metadataStr ? Metadata.parse(metadataStr) : {}


await this.cache.set(appendBlobClient.url, upload)

Expand Down