fix(file-upload): re-enabled file upload for mistral & url for file upload (#408)

* re-enabled file upload for mistral & url for file upload

* consolidated env checks
This commit is contained in:
Waleed Latif
2025-05-24 20:58:49 -07:00
committed by GitHub
parent 79b761c022
commit 950e055a8d
6 changed files with 21 additions and 53 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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<FileParserOutput> = {
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' } } : {}),

View File

@@ -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',

View File

@@ -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(),

View File

@@ -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')