Skip to content

Commit 86c87c6

Browse files
authored
fix import file size + extension validation (#1060)
* change max file import size to 50mb * allow all extensions on FileInput to show errors on Error modal
1 parent 551d432 commit 86c87c6

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

packages/@dcl/inspector/src/components/FileInput/FileInput.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function parseAccept(accept: PropTypes['accept']) {
88
for (const [key, values] of Object.entries(accept ?? {})) {
99
value += `${key},${values.join(',')},`
1010
}
11-
return value
11+
return value || '*'
1212
}
1313

1414
export interface InputRef {
@@ -27,7 +27,8 @@ export const FileInput = React.forwardRef<InputRef, React.PropsWithChildren<Prop
2727
if (onDrop) onDrop(item.files)
2828
},
2929
canDrop(item: { files: File[] }) {
30-
return !disabled && item.files.every((file) => !!acceptExtensions.find((ext) => file.name.endsWith(ext)))
30+
if (disabled || acceptExtensions.length === 0) return !disabled
31+
return item.files.every((file) => !!acceptExtensions.find((ext) => file.name.endsWith(ext)))
3132
},
3233
collect: (monitor) => ({
3334
isHover: monitor.canDrop() && monitor.isOver()

packages/@dcl/inspector/src/components/ImportAsset/ImportAsset.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,7 @@ const ImportAsset = React.forwardRef<InputRef, PropsWithChildren<PropTypes>>(({
121121

122122
return (
123123
<div className={cx('ImportAsset', { ImportAssetHover: isHover })}>
124-
<FileInput
125-
disabled={!!files.length}
126-
onDrop={handleDrop}
127-
onHover={handleHover}
128-
ref={inputRef}
129-
accept={ACCEPTED_FILE_TYPES}
130-
multiple
131-
>
124+
<FileInput disabled={!!files.length} onDrop={handleDrop} onHover={handleHover} ref={inputRef} multiple>
132125
{isImportActive && (
133126
<>
134127
<div className="upload-icon">

packages/@dcl/inspector/src/components/ImportAsset/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const ACCEPTED_FILE_TYPES = {
105105
'video/mp4': ['.mp4']
106106
}
107107

108-
const ONE_GB_IN_BYTES = 1024 * 1024 * 1024
108+
const FIFTY_MB_IN_BYTES = 50 * 1024 * 1024
109109
const VALID_EXTENSIONS = new Set(
110110
Object.values(ACCEPTED_FILE_TYPES)
111111
.flat()
@@ -159,7 +159,7 @@ export function formatFileName(file: BaseAsset): string {
159159
}
160160

161161
function validateFileSize(size: number): ValidationError {
162-
return size <= ONE_GB_IN_BYTES ? undefined : { type: 'size', message: 'Max file size: 1 GB' }
162+
return size <= FIFTY_MB_IN_BYTES ? undefined : { type: 'size', message: 'Max file size: 50 MB' }
163163
}
164164

165165
function validateExtension(extension: string): ValidationError {

0 commit comments

Comments
 (0)