Skip to main content
Glama
extract.ts1.89 kB
import { ExtractInputRequest, RequestOptions } from "@superglue/client"; import { SupportedFileType } from "@superglue/shared"; import { GraphQLResolveInfo } from "graphql"; import { parseFile } from "../../files/index.js"; import { logMessage } from "../../utils/logs.js"; import { telemetryClient } from "../../utils/telemetry.js"; import { maskCredentials } from "../../utils/helpers.js"; import { Context, Metadata } from '../types.js'; export const extractResolver = async ( _: any, { input, payload, credentials, options }: { input: ExtractInputRequest; payload: any; credentials: Record<string, string>; options: RequestOptions; }, context: Context, info: GraphQLResolveInfo ) => { const callId = crypto.randomUUID(); const startedAt = new Date(); const metadata: Metadata = { runId: input.id || callId, orgId: context.orgId }; try { if (!input.file) { logMessage('error', "Extract call failed. No file provided", metadata); return { id: callId, success: false, error: "No file provided", startedAt, completedAt: new Date(), }; } const { createReadStream, filename } = await input.file as any; const stream = createReadStream(); const chunks: Buffer[] = []; for await (const chunk of stream) { chunks.push(chunk); } const buffer = Buffer.concat(chunks); const data = await parseFile(buffer, SupportedFileType.AUTO); return { id: callId, success: true, data, startedAt, completedAt: new Date(), }; } catch (error: any) { const maskedError = maskCredentials(error.message, credentials); telemetryClient?.captureException(maskedError, context.orgId); return { id: callId, success: false, error: maskedError, startedAt, completedAt: new Date(), }; } };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/superglue-ai/superglue'

If you have feedback or need assistance with the MCP directory API, please join our Discord server