Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions apps/sim/app/workspace/[workspaceId]/files/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
SUPPORTED_AUDIO_EXTENSIONS,
SUPPORTED_CODE_EXTENSIONS,
SUPPORTED_DOCUMENT_EXTENSIONS,
SUPPORTED_IMAGE_EXTENSIONS,
SUPPORTED_VIDEO_EXTENSIONS,
} from '@/lib/uploads/utils/validation'
import type {
Expand Down Expand Up @@ -89,6 +90,7 @@ const SUPPORTED_EXTENSIONS = [
...SUPPORTED_CODE_EXTENSIONS,
...SUPPORTED_AUDIO_EXTENSIONS,
...SUPPORTED_VIDEO_EXTENSIONS,
...SUPPORTED_IMAGE_EXTENSIONS,
] as const

const ACCEPT_ATTR = SUPPORTED_EXTENSIONS.map((ext) => `.${ext}`).join(',')
Expand Down Expand Up @@ -125,6 +127,7 @@ function formatFileType(mimeType: string | null, filename: string): string {

if (mimeType?.startsWith('audio/')) return 'Audio'
if (mimeType?.startsWith('video/')) return 'Video'
if (mimeType?.startsWith('image/')) return 'Image'
Comment thread
waleedlatif1 marked this conversation as resolved.

const ext = getFileExtension(filename)
if (ext) return ext.toUpperCase()
Expand Down Expand Up @@ -246,6 +249,7 @@ export function Files() {
if (typeFilter.includes('document') && isSupportedExtension(ext)) return true
if (typeFilter.includes('audio') && isAudioFileType(f.type)) return true
Comment thread
waleedlatif1 marked this conversation as resolved.
if (typeFilter.includes('video') && isVideoFileType(f.type)) return true
if (typeFilter.includes('image') && f.type?.startsWith('image/')) return true
return false
})
}
Expand Down Expand Up @@ -926,9 +930,14 @@ export function Files() {
typeFilter.length === 0
? 'All'
: typeFilter.length === 1
? (({ document: 'Documents', audio: 'Audio', video: 'Video' } as Record<string, string>)[
typeFilter[0]
] ?? typeFilter[0])
? ((
{
document: 'Documents',
image: 'Images',
audio: 'Audio',
video: 'Video',
} as Record<string, string>
)[typeFilter[0]] ?? typeFilter[0])
: `${typeFilter.length} selected`

const sizeDisplayLabel =
Expand All @@ -954,6 +963,7 @@ export function Files() {
<Combobox
options={[
{ value: 'document', label: 'Documents' },
{ value: 'image', label: 'Images' },
{ value: 'audio', label: 'Audio' },
{ value: 'video', label: 'Video' },
]}
Expand Down Expand Up @@ -1036,6 +1046,7 @@ export function Files() {
if (typeFilter.length > 0) {
const typeLabels: Record<string, string> = {
document: 'Documents',
image: 'Images',
audio: 'Audio',
video: 'Video',
}
Expand Down
29 changes: 26 additions & 3 deletions apps/sim/lib/uploads/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,31 @@ export const SUPPORTED_AUDIO_EXTENSIONS = [

export const SUPPORTED_VIDEO_EXTENSIONS = ['mp4', 'mov', 'avi', 'mkv', 'webm'] as const

export const SUPPORTED_IMAGE_EXTENSIONS = [
'png',
'jpg',
'jpeg',
'gif',
'webp',
'svg',
'bmp',
'tif',
'tiff',
'heic',
'heif',
'avif',
'ico',
] as const

export type SupportedDocumentExtension = (typeof SUPPORTED_DOCUMENT_EXTENSIONS)[number]
export type SupportedAudioExtension = (typeof SUPPORTED_AUDIO_EXTENSIONS)[number]
export type SupportedVideoExtension = (typeof SUPPORTED_VIDEO_EXTENSIONS)[number]
export type SupportedImageExtension = (typeof SUPPORTED_IMAGE_EXTENSIONS)[number]
export type SupportedMediaExtension =
| SupportedDocumentExtension
| SupportedAudioExtension
| SupportedVideoExtension
| SupportedImageExtension

export const SUPPORTED_MIME_TYPES: Record<SupportedDocumentExtension, string[]> = {
pdf: ['application/pdf', 'application/x-pdf'],
Expand Down Expand Up @@ -180,14 +198,19 @@ const SUPPORTED_IMAGE_MIME_TYPES = [
'image/gif',
'image/webp',
'image/svg+xml',
'image/bmp',
'image/tiff',
'image/heic',
'image/heif',
'image/avif',
'image/x-icon',
'image/vnd.microsoft.icon',
]

const SUPPORTED_IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg']

export const CHAT_ACCEPT_ATTRIBUTE = [
ACCEPT_ATTRIBUTE,
...SUPPORTED_IMAGE_MIME_TYPES,
...SUPPORTED_IMAGE_EXTENSIONS,
...SUPPORTED_IMAGE_EXTENSIONS.map((ext) => `.${ext}`),
].join(',')

export interface FileValidationError {
Expand Down