-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Empty white list enables all media types upload (#1080)
* Create utils to media (canUpload) * Fix variable name
- Loading branch information
1 parent
d250f77
commit 8cfdf86
Showing
4 changed files
with
34 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const canUploadFile = (file, serverInfo) => { | ||
const { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize } = serverInfo; | ||
if (!(file && file.path)) { | ||
return true; | ||
} | ||
if (file.size > FileUpload_MaxFileSize) { | ||
return false; | ||
} | ||
// if white list is empty, all media types are enabled | ||
if (!FileUpload_MediaTypeWhiteList) { | ||
return true; | ||
} | ||
const allowedMime = FileUpload_MediaTypeWhiteList.split(','); | ||
if (allowedMime.includes(file.mime)) { | ||
return true; | ||
} | ||
const wildCardGlob = '/*'; | ||
const wildCards = allowedMime.filter(item => item.indexOf(wildCardGlob) > 0); | ||
if (wildCards.includes(file.mime.replace(/(\/.*)$/, wildCardGlob))) { | ||
return true; | ||
} | ||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters