Skip to content

Commit b85f1e3

Browse files
committed
Update component to use kb instead of mb
1 parent 9e56201 commit b85f1e3

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

addon/components/au-file-upload.gts

+20-19
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface AuFileUploadSignature {
2020
helpTextDragDrop?: string;
2121
helpTextFileNotSupported?: string;
2222
maxFileSizeMB?: number;
23-
minFileSizeMB?: number;
23+
minFileSizeKB?: number;
2424
multiple?: boolean;
2525
onFinishUpload?: (uploadedFile: number, queueInfo: QueueInfo) => void;
2626
onQueueUpdate?: (queueInfo: QueueInfo) => void;
@@ -88,8 +88,8 @@ export default class AuFileUpload extends Component<AuFileUploadSignature> {
8888
return this.args.maxFileSizeMB || 20;
8989
}
9090

91-
get minFileSizeMB() {
92-
return this.args.minFileSizeMB || 0;
91+
get minFileSizeKB() {
92+
return this.args.minFileSizeKB || 0;
9393
}
9494

9595
get hasErrors() {
@@ -143,18 +143,19 @@ export default class AuFileUpload extends Component<AuFileUploadSignature> {
143143
}
144144
}
145145

146-
if (!isValidFileSize(file.size, this.minFileSizeMB, this.maxFileSizeMB)) {
147-
if (file.size < this.minFileSizeMB * Math.pow(1024, 2)) {
148-
this.addError(
149-
file,
150-
`Bestand is te klein (min ${this.minFileSizeMB} MB)`,
151-
);
152-
} else {
153-
this.addError(
154-
file,
155-
`Bestand is te groot (max ${this.maxFileSizeMB} MB)`,
156-
);
157-
}
146+
if (file.size < this.minFileSizeKB * 1024) {
147+
this.addError(
148+
file,
149+
`Bestand is te klein (min ${this.minFileSizeKB} KB)`,
150+
);
151+
return false;
152+
}
153+
154+
if (file.size >= this.maxFileSizeMB * Math.pow(1024, 2)) {
155+
this.addError(
156+
file,
157+
`Bestand is te groot (max ${this.maxFileSizeMB} MB)`,
158+
);
158159
return false;
159160
}
160161

@@ -319,11 +320,11 @@ function isValidExtension(
319320

320321
function isValidFileSize(
321322
fileSize: number,
322-
minimumSize: number,
323-
maximumSize: number,
323+
minimumSizeKB: number,
324+
maximumSizeMB: number,
324325
): boolean {
325326
return (
326-
fileSize >= minimumSize * Math.pow(1024, 2) &&
327-
fileSize < maximumSize * Math.pow(1024, 2)
327+
fileSize >= minimumSizeKB * 1024 &&
328+
fileSize < maximumSizeMB * Math.pow(1024, 2)
328329
);
329330
}

0 commit comments

Comments
 (0)