diff --git a/apps/sim/.env.example b/apps/sim/.env.example index 0b47f1ca0..fc42b3b54 100644 --- a/apps/sim/.env.example +++ b/apps/sim/.env.example @@ -14,18 +14,3 @@ ENCRYPTION_KEY=your_encryption_key # Use `openssl rand -hex 32` to generate # Freestyle API Key (Required for sandboxed code execution for functions/custom-tools) # FREESTYLE_API_KEY= # Uncomment and add your key from https://docs.freestyle.sh/Getting-Started/run - -# S3 Storage Configuration (Optional) -# Set USE_S3=true to enable S3 storage in development -# USE_S3=true - -# AWS Credentials (Required when USE_S3=true) -# AWS_ACCESS_KEY_ID=your-access-key-id -# AWS_SECRET_ACCESS_KEY=your-secret-access-key - -# S3 Configuration (Required when USE_S3=true) -# S3_BUCKET_NAME=your-bucket-name -# AWS_REGION=us-east-1 - -# Optional: Custom S3 Base URL (for custom domains or non-AWS S3-compatible storage) -# S3_BASE_URL=https://your-custom-domain.com \ No newline at end of file diff --git a/apps/sim/app/api/files/delete/route.ts b/apps/sim/app/api/files/delete/route.ts index 2ded3e2e3..d0a86d03c 100644 --- a/apps/sim/app/api/files/delete/route.ts +++ b/apps/sim/app/api/files/delete/route.ts @@ -5,7 +5,6 @@ import type { NextRequest } from 'next/server' import { createLogger } from '@/lib/logs/console-logger' import { deleteFromS3 } from '@/lib/uploads/s3-client' import { UPLOAD_DIR, USE_S3_STORAGE } from '@/lib/uploads/setup' -// Import to ensure the uploads directory is created import '@/lib/uploads/setup.server' import { diff --git a/apps/sim/blocks/blocks/file.ts b/apps/sim/blocks/blocks/file.ts index a382e5df3..1dfd0630f 100644 --- a/apps/sim/blocks/blocks/file.ts +++ b/apps/sim/blocks/blocks/file.ts @@ -6,15 +6,8 @@ import type { BlockConfig, SubBlockConfig, SubBlockLayout, SubBlockType } from ' const logger = createLogger('FileBlock') -// Create a safe client-only env subset to avoid server-side env access errors -const clientEnv = { - USE_S3: process.env.USE_S3, -} +const shouldEnableURLInput = isProd -const isS3Enabled = clientEnv.USE_S3 -const shouldEnableURLInput = isProd || isS3Enabled - -// Define sub-blocks conditionally const inputMethodBlock: SubBlockConfig = { id: 'inputMethod', title: 'Select Input Method', @@ -26,18 +19,6 @@ const inputMethodBlock: SubBlockConfig = { ], } -const fileUrlBlock: SubBlockConfig = { - id: 'filePath', - title: 'File URL', - type: 'short-input' as SubBlockType, - layout: 'full' as SubBlockLayout, - placeholder: 'Enter URL to a file (https://example.com/document.pdf)', - condition: { - field: 'inputMethod', - value: 'url', - }, -} - const fileUploadBlock: SubBlockConfig = { id: 'file', title: 'Upload Files', @@ -62,7 +43,23 @@ export const FileBlock: BlockConfig = { bgColor: '#40916C', icon: DocumentIcon, subBlocks: [ - ...(shouldEnableURLInput ? [inputMethodBlock, fileUrlBlock] : []), + ...(shouldEnableURLInput ? [inputMethodBlock] : []), + { + id: 'filePath', + title: 'File URL', + type: 'short-input' as SubBlockType, + layout: 'full' as SubBlockLayout, + placeholder: 'Enter URL to a file (https://example.com/document.pdf)', + ...(shouldEnableURLInput + ? { + condition: { + field: 'inputMethod', + value: 'url', + }, + } + : {}), + }, + { ...fileUploadBlock, ...(shouldEnableURLInput ? { condition: { field: 'inputMethod', value: 'upload' } } : {}), diff --git a/apps/sim/blocks/blocks/mistral_parse.ts b/apps/sim/blocks/blocks/mistral_parse.ts index 76648baf4..dd87c2a60 100644 --- a/apps/sim/blocks/blocks/mistral_parse.ts +++ b/apps/sim/blocks/blocks/mistral_parse.ts @@ -3,15 +3,8 @@ import { isProd } from '@/lib/environment' import type { MistralParserOutput } from '@/tools/mistral/types' import type { BlockConfig, SubBlockConfig, SubBlockLayout, SubBlockType } from '../types' -// Create a safe client-only env subset to avoid server-side env access errors -const clientEnv = { - USE_S3: process.env.USE_S3, -} +const shouldEnableFileUpload = isProd -const isS3Enabled = clientEnv.USE_S3 -const shouldEnableFileUpload = isProd || isS3Enabled - -// Define the input method selector block when needed const inputMethodBlock: SubBlockConfig = { id: 'inputMethod', title: 'Select Input Method', @@ -23,7 +16,6 @@ const inputMethodBlock: SubBlockConfig = { ], } -// Define the file upload block when needed const fileUploadBlock: SubBlockConfig = { id: 'fileUpload', title: 'Upload PDF', diff --git a/apps/sim/lib/env.ts b/apps/sim/lib/env.ts index 42a7ccb95..a247f0095 100644 --- a/apps/sim/lib/env.ts +++ b/apps/sim/lib/env.ts @@ -66,7 +66,6 @@ export const env = createEnv({ AWS_SECRET_ACCESS_KEY: z.string().optional(), S3_BUCKET_NAME: z.string().optional(), S3_LOGS_BUCKET_NAME: z.string().optional(), - USE_S3: z.coerce.boolean().optional(), CRON_SECRET: z.string().optional(), FREE_PLAN_LOG_RETENTION_DAYS: z.string().optional(), NODE_ENV: z.string().optional(), diff --git a/apps/sim/lib/uploads/setup.ts b/apps/sim/lib/uploads/setup.ts index f3a8f1280..b113c2820 100644 --- a/apps/sim/lib/uploads/setup.ts +++ b/apps/sim/lib/uploads/setup.ts @@ -1,27 +1,23 @@ import { existsSync } from 'fs' import { mkdir } from 'fs/promises' import path, { join } from 'path' +import { isProd } from '@/lib/environment' import { createLogger } from '@/lib/logs/console-logger' import { env } from '../env' const logger = createLogger('UploadsSetup') -// Define project root - this works regardless of how the app is started const PROJECT_ROOT = path.resolve(process.cwd()) -// Define the upload directory path using project root export const UPLOAD_DIR = join(PROJECT_ROOT, 'uploads') -export const USE_S3_STORAGE = env.NODE_ENV === 'production' || env.USE_S3 +export const USE_S3_STORAGE = isProd export const S3_CONFIG = { bucket: env.S3_BUCKET_NAME || '', region: env.AWS_REGION || '', } -/** - * Ensures that the uploads directory exists (for local storage) - */ export async function ensureUploadsDirectory() { if (USE_S3_STORAGE) { logger.info('Using S3 storage, skipping local uploads directory creation')