Document File Resolver (document/utils.ts)

giselle · files, Files / Storage, document, vector-store, mime, file-type, validation

Validates and resolves supported document file types for vector stores based on MIME type or file extension.

// Source: https://github.com/mperkins0155/giselle | License: Apache-2.0 | Copyright 2024 ROUTE06, Inc
// Provided via justclaw.it.com; keep this notice with the code.
import { DOCUMENT_VECTOR_STORE_SUPPORTED_FILE_TYPES } from "./constants";

type SupportedDocumentFileType =
	(typeof DOCUMENT_VECTOR_STORE_SUPPORTED_FILE_TYPES)[number];

function findSupportedFileTypeByMimeType(
	mimeType: string | undefined,
): SupportedDocumentFileType | null {
	if (!mimeType) {
		return null;
	}
	const normalizedMimeType = mimeType.toLowerCase();
	return (
		DOCUMENT_VECTOR_STORE_SUPPORTED_FILE_TYPES.find((fileType) =>
			fileType.mimeTypes.some(
				(supportedMime) => supportedMime.toLowerCase() === normalizedMimeType,
			),
		) ?? null
	);
}

function findSupportedFileTypeByExtension(
	fileName: string

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key