Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor(validation): remove Node path import, use plain string extra…
…ction

Replace `import path from 'path'` with a simple `extractExtension` helper
that does `fileName.slice(fileName.lastIndexOf('.') + 1)`. This removes
the only Node module dependency from validation.ts, making it safe to
import from client components without pulling in a Node polyfill.

Deletes the unnecessary validation-constants.ts that was introduced as
a workaround — the constants now live back in validation.ts where they
belong.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
  • Loading branch information
waleedlatif1 and claude committed Apr 5, 2026
commit e31cf4db25383e1bb4d625aa1adc1f46e2ce2799
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Skeleton } from '@/components/emcn'
import { cn } from '@/lib/core/utils/cn'
import type { WorkspaceFileRecord } from '@/lib/uploads/contexts/workspace'
import { getFileExtension } from '@/lib/uploads/utils/file-utils'
import { SUPPORTED_CODE_EXTENSIONS } from '@/lib/uploads/utils/validation-constants'
import { SUPPORTED_CODE_EXTENSIONS } from '@/lib/uploads/utils/validation'
import {
useUpdateWorkspaceFileContent,
useWorkspaceFileBinary,
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/workspace/[workspaceId]/files/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import {
isAudioFileType,
isVideoFileType,
} from '@/lib/uploads/utils/file-utils'
import { SUPPORTED_CODE_EXTENSIONS } from '@/lib/uploads/utils/validation-constants'
import {
isSupportedExtension,
SUPPORTED_AUDIO_EXTENSIONS,
SUPPORTED_CODE_EXTENSIONS,
SUPPORTED_DOCUMENT_EXTENSIONS,
SUPPORTED_VIDEO_EXTENSIONS,
} from '@/lib/uploads/utils/validation'
Expand Down
52 changes: 0 additions & 52 deletions apps/sim/lib/uploads/utils/validation-constants.ts

This file was deleted.

62 changes: 55 additions & 7 deletions apps/sim/lib/uploads/utils/validation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import path from 'path'

export { SUPPORTED_CODE_EXTENSIONS } from '@/lib/uploads/utils/validation-constants'
export type { SupportedCodeExtension } from '@/lib/uploads/utils/validation-constants'

/**
* Checks whether a string is a valid file extension (lowercase alphanumeric only).
* Rejects extensions containing spaces, punctuation, or other non-alphanumeric characters
Expand All @@ -12,6 +7,11 @@ export function isAlphanumericExtension(ext: string): boolean {
return /^[a-z0-9]+$/.test(ext)
}

function extractExtension(fileName: string): string {
const lastDot = fileName.lastIndexOf('.')
return lastDot !== -1 ? fileName.slice(lastDot + 1).toLowerCase() : ''
}

export const MAX_FILE_SIZE = 100 * 1024 * 1024 // 100MB

export const SUPPORTED_DOCUMENT_EXTENSIONS = [
Expand All @@ -32,6 +32,54 @@ export const SUPPORTED_DOCUMENT_EXTENSIONS = [
'yml',
] as const

export const SUPPORTED_CODE_EXTENSIONS = [
'mdx',
'xml',
'css',
'scss',
'less',
'js',
'jsx',
'ts',
'tsx',
'py',
'rb',
'go',
'rs',
'java',
'kt',
'swift',
'c',
'cpp',
'h',
'hpp',
'cs',
'php',
'sh',
'bash',
'zsh',
'fish',
'sql',
'graphql',
'gql',
'toml',
'ini',
'conf',
'cfg',
'env',
'log',
'diff',
'patch',
'dockerfile',
'makefile',
Comment thread
waleedlatif1 marked this conversation as resolved.
'gitignore',
'editorconfig',
'prettierrc',
'eslintrc',
] as const

export type SupportedCodeExtension = (typeof SUPPORTED_CODE_EXTENSIONS)[number]

export const SUPPORTED_AUDIO_EXTENSIONS = [
'mp3',
'm4a',
Expand Down Expand Up @@ -149,7 +197,7 @@ export interface FileValidationError {
* Validate if a file type is supported for document processing
*/
export function validateFileType(fileName: string, mimeType: string): FileValidationError | null {
const raw = path.extname(fileName).toLowerCase().substring(1)
const raw = extractExtension(fileName)
const extension = (isAlphanumericExtension(raw) ? raw : '') as SupportedDocumentExtension

if (!SUPPORTED_DOCUMENT_EXTENSIONS.includes(extension)) {
Expand Down Expand Up @@ -234,7 +282,7 @@ export function validateMediaFileType(
fileName: string,
mimeType: string
): FileValidationError | null {
const raw = path.extname(fileName).toLowerCase().substring(1)
const raw = extractExtension(fileName)
const extension = isAlphanumericExtension(raw) ? raw : ''

const isAudio = SUPPORTED_AUDIO_EXTENSIONS.includes(extension as SupportedAudioExtension)
Expand Down
Loading