@@ -22,7 +22,7 @@ import {
2222 type UploadTokenPayload ,
2323 verifyUploadToken ,
2424} from '@/lib/uploads/core/upload-token'
25- import type { StorageConfig } from '@/lib/uploads/shared/types'
25+ import { QUOTA_EXEMPT_STORAGE_CONTEXTS , type StorageConfig } from '@/lib/uploads/shared/types'
2626import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
2727
2828const logger = createLogger ( 'MultipartUploadAPI' )
@@ -135,6 +135,22 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
135135
136136 const config = getStorageConfig ( storageContext )
137137
138+ // Apply storage quota to all user-driven upload contexts (not system/metadata contexts)
139+ if (
140+ ! QUOTA_EXEMPT_STORAGE_CONTEXTS . has ( context as StorageContext ) &&
141+ typeof fileSize === 'number' &&
142+ fileSize > 0
143+ ) {
144+ const { checkStorageQuota } = await import ( '@/lib/billing/storage' )
145+ const quotaCheck = await checkStorageQuota ( userId , fileSize )
146+ if ( ! quotaCheck . allowed ) {
147+ return NextResponse . json (
148+ { error : quotaCheck . error || 'Storage limit exceeded' } ,
149+ { status : 413 }
150+ )
151+ }
152+ }
153+
138154 let customKey : string | undefined
139155 if ( context === 'workspace' || context === 'mothership' ) {
140156 const { MAX_WORKSPACE_FILE_SIZE } = await import ( '@/lib/uploads/shared/types' )
@@ -149,15 +165,6 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
149165 '@/lib/uploads/contexts/workspace/workspace-file-manager'
150166 )
151167 customKey = generateWorkspaceFileKey ( workspaceId , fileName )
152-
153- const { checkStorageQuota } = await import ( '@/lib/billing/storage' )
154- const quotaCheck = await checkStorageQuota ( userId , fileSize )
155- if ( ! quotaCheck . allowed ) {
156- return NextResponse . json (
157- { error : quotaCheck . error || 'Storage limit exceeded' } ,
158- { status : 413 }
159- )
160- }
161168 } else if ( context === 'execution' ) {
162169 const workflowId = ( data as { workflowId ?: unknown } ) . workflowId
163170 const executionId = ( data as { executionId ?: unknown } ) . executionId
0 commit comments