Skip to content

Commit f6688da

Browse files
authored
[CHORE] Add .parquet as allowed extension (huggingface#383)
* add .parquet as allowed extension * disable upload action while uploading
1 parent dc95ff4 commit f6688da

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

src/features/import/drag-n-drop.tsx

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const DragAndDrop = component$(() => {
2727
const isDragging = useSignal(false);
2828
const navigate = useNavigate();
2929

30-
const allowedExtensions = ['csv', 'tsv', 'xlsx', 'xls'];
30+
const allowedExtensions = ['csv', 'tsv', 'xlsx', 'xls', 'parquet'];
3131

3232
const uploadErrorMessage = useSignal<string | null>(null);
3333

@@ -38,41 +38,46 @@ export const DragAndDrop = component$(() => {
3838

3939
if (!file.value) return;
4040

41-
const fileName = file.value.name;
42-
const fileExtension = file.value.name.split('.').pop();
43-
44-
if (!fileExtension || !allowedExtensions.includes(fileExtension)) {
45-
uploadErrorMessage.value = `Invalid file type. Supported types: ${allowedExtensions.join(', ')}`;
46-
return;
47-
}
48-
const maxFileSizeMB = 25;
49-
const maxFileSizeBytes = maxFileSizeMB * 1024 * 1024;
50-
51-
if (file.value.size > maxFileSizeBytes) {
52-
uploadErrorMessage.value = `File is too large. Maximum allowed size is ${maxFileSizeMB} MB.`;
53-
return;
41+
try {
42+
const fileName = file.value.name;
43+
const fileExtension = file.value.name.split('.').pop();
44+
45+
if (!fileExtension || !allowedExtensions.includes(fileExtension)) {
46+
uploadErrorMessage.value = `Invalid file type. Supported types: ${allowedExtensions.join(', ')}`;
47+
return;
48+
}
49+
const maxFileSizeMB = 25;
50+
const maxFileSizeBytes = maxFileSizeMB * 1024 * 1024;
51+
52+
if (file.value.size > maxFileSizeBytes) {
53+
uploadErrorMessage.value = `File is too large. Maximum allowed size is ${maxFileSizeMB} MB.`;
54+
return;
55+
}
56+
57+
const value = await file.value.arrayBuffer();
58+
59+
const response = await fetch('/api/upload', {
60+
method: 'POST',
61+
headers: {
62+
'Content-Type': 'application/octet-stream',
63+
'X-Chunk-Size': value.byteLength.toString(),
64+
'X-File-Name': encodeURIComponent(fileName),
65+
},
66+
body: value,
67+
});
68+
69+
if (!response.ok) {
70+
uploadErrorMessage.value =
71+
'Failed to upload file. Please try again or provide another file.';
72+
return;
73+
}
74+
75+
const { id } = await response.json();
76+
navigate('/home/dataset/' + id);
77+
} finally {
78+
file.value = undefined;
79+
isDragging.value = false;
5480
}
55-
56-
const value = await file.value.arrayBuffer();
57-
58-
const response = await fetch('/api/upload', {
59-
method: 'POST',
60-
headers: {
61-
'Content-Type': 'application/octet-stream',
62-
'X-Chunk-Size': value.byteLength.toString(),
63-
'X-File-Name': encodeURIComponent(fileName),
64-
},
65-
body: value,
66-
});
67-
68-
if (!response.ok) {
69-
uploadErrorMessage.value =
70-
'Failed to upload file. Please try again or provide another file.';
71-
return;
72-
}
73-
74-
const { id } = await response.json();
75-
navigate('/home/dataset/' + id);
7681
});
7782

7883
const container = useClickOutside(
@@ -136,6 +141,7 @@ export const DragAndDrop = component$(() => {
136141
gutter={14}
137142
>
138143
<Popover.Trigger
144+
disabled={!!file.value}
139145
class={cn(
140146
buttonVariants({ look: 'outline', size: 'sm' }),
141147
'text-primary-600 disabled:text-neutral-300 disabled:cursor-not-allowed',

0 commit comments

Comments
 (0)