Skip to content
Merged
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
21 changes: 12 additions & 9 deletions server/api/knowledgeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const { JwtPayloadKey } = config
// Storage configuration for Knowledge Base feature files
const KB_STORAGE_ROOT = join(process.cwd(), "storage", "kb_files")
const MAX_FILE_SIZE = 100 // 100MB max file size
const MAX_ZIP_FILE_SIZE = 25 // 25MB max zip file size
const MAX_ZIP_FILE_SIZE = 35 // 25MB max zip file size

// Initialize storage directory for Knowledge Base files
;(async () => {
Expand Down Expand Up @@ -524,7 +524,6 @@ export const GetCollectionNameForSharedAgentApi = async (c: Context) => {
agentExternalId,
user.workspaceId,
)


if (!agent) {
throw new HTTPException(404, { message: "Agent not found" })
Expand Down Expand Up @@ -1212,15 +1211,15 @@ export const UploadFilesApi = async (c: Context) => {
const file = files[i]
const ext = extname(file.name).toLowerCase()

if (ext === '.zip') {
if (ext === ".zip") {
// Check zip file size before extraction
const zipSizeMB = Math.round(file.size / 1024 / 1024)
if (file.size > MAX_ZIP_FILE_SIZE * 1024 * 1024) {
loggerWithChild({ email: userEmail }).warn(
`Zip file too large: ${file.name} (${zipSizeMB}MB). Maximum is ${MAX_ZIP_FILE_SIZE}MB`,
)
throw new HTTPException(400, {
message: `Zip file too large (${zipSizeMB}MB). Maximum size is ${MAX_ZIP_FILE_SIZE}MB`
message: `Zip file too large (${zipSizeMB}MB). Maximum size is ${MAX_ZIP_FILE_SIZE}MB`,
})
}

Expand Down Expand Up @@ -1287,7 +1286,7 @@ export const UploadFilesApi = async (c: Context) => {
paths = extractedPaths

// Validate file count - allow up to 3000 files for zip extractions
const maxFilesLimit = 3000
const maxFilesLimit = 10000

if (files.length > maxFilesLimit) {
throw new HTTPException(400, {
Expand Down Expand Up @@ -1332,7 +1331,7 @@ export const UploadFilesApi = async (c: Context) => {
let storagePath = ""
try {
// Validate file size
try{
try {
checkFileSize(file.size, MAX_FILE_SIZE)
} catch (error) {
uploadResults.push({
Expand Down Expand Up @@ -1742,7 +1741,7 @@ export const DeleteItemApi = async (c: Context) => {
} catch (error) {
loggerWithChild({ email: userEmail }).error(
`Failed to delete file from Vespa: ${id}`,
{ error: getErrorMessage(error) }
{ error: getErrorMessage(error) },
)
}
}
Expand Down Expand Up @@ -1937,7 +1936,11 @@ export const GetChunkContentApi = async (c: Context) => {
const chunkContent = resp.fields.chunks[index]
let pageIndex: number | undefined

const isSheetFile = getFileType({ type: resp.fields.mimeType || "", name: resp.fields.fileName || "" }) === FileType.SPREADSHEET
const isSheetFile =
getFileType({
type: resp.fields.mimeType || "",
name: resp.fields.fileName || "",
}) === FileType.SPREADSHEET
if (isSheetFile) {
const sheetIndexMatch = docId.match(/_sheet_(\d+)$/)
if (sheetIndexMatch) {
Expand All @@ -1952,7 +1955,7 @@ export const GetChunkContentApi = async (c: Context) => {
? pageNums[0]
: 0
}

if (!chunkContent) {
throw new HTTPException(404, { message: "Chunk content not found" })
}
Expand Down