Skip to content

Commit

Permalink
fix: content-type charset (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenos authored Jan 11, 2024
1 parent 3909fd4 commit 9b1f22b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export class Storage {
)
}

if (!type.match(/^[a-zA-Z0-9\-\+]+\/([a-zA-Z0-9\-\+\.]+$)|\*$/)) {
if (
!type.match(/^([a-zA-Z0-9\-+.]+)\/([a-zA-Z0-9\-+.]+)(;\s*charset=[a-zA-Z0-9\-]+)?$|\*$/)
) {
throw new StorageBackendError(
'invalid_mime_type',
422,
Expand Down
9 changes: 6 additions & 3 deletions src/storage/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ export class Uploader {
continue
}

if (allowedMime[0] === type && allowedMime[1] === '*') {
const [allowedType, allowedExtension] = allowedMime

if (allowedType === type && allowedExtension === '*') {
return true
}

if (allowedMime[0] === type && allowedMime[1] === ext) {
if (allowedType === type && allowedExtension === ext) {
return true
}
}
Expand Down Expand Up @@ -267,7 +269,8 @@ export class Uploader {
const cacheTime = formData.fields.cacheControl?.value

body = formData.file
mimeType = formData.mimetype
/* @ts-expect-error: https://github.com/aws/aws-sdk-js-v3/issues/2085 */
mimeType = formData.fields.contentType?.value || formData.mimetype
cacheControl = cacheTime ? `max-age=${cacheTime}` : 'no-cache'
isTruncated = () => formData.file.truncated
} catch (e) {
Expand Down

0 comments on commit 9b1f22b

Please sign in to comment.