Skip to content

Commit 91be3f1

Browse files
committed
Fix site upload invalid event reason handling
1 parent 562a6bc commit 91be3f1

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

  • src/routes/(console)/project-[region]-[project]/sites/create-site/manual

src/routes/(console)/project-[region]-[project]/sites/create-site/manual/+page.svelte

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,22 @@
138138
}
139139
140140
function handleInvalid(e: CustomEvent) {
141-
const reason = e.detail?.reason ?? '';
141+
let reason = e.detail?.reason ?? '';
142+
143+
if (!reason) {
144+
const nativeEvent = e.detail as Event | undefined;
145+
const input = (nativeEvent?.currentTarget ?? nativeEvent?.target) as
146+
| HTMLInputElement
147+
| undefined;
148+
const pickedFiles = Array.from(input?.files ?? []);
149+
150+
if (pickedFiles.some((file) => file.size > maxSize)) {
151+
reason = InvalidFileType.SIZE;
152+
} else if (pickedFiles.some((file) => !file.name.toLowerCase().endsWith('.tar.gz'))) {
153+
reason = InvalidFileType.EXTENSION;
154+
}
155+
}
156+
142157
if (reason === InvalidFileType.EXTENSION) {
143158
addNotification({
144159
type: 'error',
@@ -147,7 +162,7 @@
147162
} else if (reason === InvalidFileType.SIZE) {
148163
addNotification({
149164
type: 'error',
150-
message: 'File size exceeds 10MB'
165+
message: `File size exceeds ${readableMaxSize.value}${readableMaxSize.unit}`
151166
});
152167
} else {
153168
addNotification({

0 commit comments

Comments
 (0)