chore: add skip file type check env (#6839)

This commit is contained in:
Ryo
2026-04-28 16:56:57 +08:00
committed by GitHub
parent 1cb67b38e0
commit 423607ab5c
2 changed files with 15 additions and 2 deletions
@@ -4,6 +4,7 @@ import path from 'node:path';
import type { UploadConstraints } from '../contracts/type';
import { DEFAULT_CONTENT_TYPE, resolveMimeType } from '../utils/mime';
import { normalizeAllowedExtensions, normalizeFileExtension } from '../utils/uploadConstraints';
import { env } from '../../../env';
const defaultInspectBytes = 8192;
const officeZipInspectBytes = 64 * 1024;
@@ -171,6 +172,14 @@ export async function validateUploadFile({
extension,
uploadConstraints
});
if (env.SKIP_FILE_TYPE_CHECK) {
return {
filename: normalizedFileName,
contentType: expectedMime
};
}
const detected = await fileTypeFromBuffer(buffer).catch((error) => {
if (error?.name === 'EndOfStreamError' || error?.message === 'End-Of-Stream') {
return undefined;
+6 -2
View File
@@ -1,9 +1,10 @@
import { createEnv } from '@t3-oss/env-core';
import z from 'zod';
const truthyBoolStrs = ['true', '1', 'yes', 'y'];
const BoolSchema = z
.string()
.transform((val) => val === 'true')
.transform((val) => truthyBoolStrs.includes(val.toLowerCase()))
.pipe(z.boolean());
const NumSchema = z.coerce.number<number>();
@@ -17,6 +18,7 @@ const StorageCosProtocolSchema = z.enum(['https:', 'http:']);
export const env = createEnv({
server: {
FILE_TOKEN_KEY: z.string().min(6, 'FILE_TOKEN_KEY must be at least 6 characters'),
// ===== Agent sandbox =====
AGENT_SANDBOX_PROVIDER: z.enum(['sealosdevbox', 'opensandbox', 'e2b']).optional(),
AGENT_SANDBOX_E2B_API_KEY: z.string().optional(),
@@ -124,7 +126,9 @@ export const env = createEnv({
SHOW_SKILL: BoolSchema.default(false),
// Agent engine selection: 'default' uses the built-in Plan+Step engine, 'pi' uses pi-agent-core
AGENT_ENGINE: z.enum(['default', 'pi']).default('default')
AGENT_ENGINE: z.enum(['default', 'pi']).default('default'),
SKIP_FILE_TYPE_CHECK: BoolSchema.default(false)
},
emptyStringAsUndefined: true,
runtimeEnv: process.env,