filecoin-pin
Version:
Bridge IPFS content to Filecoin Onchain Cloud using familiar tools
64 lines • 2.37 kB
TypeScript
/**
* Shared Synapse upload functionality
*
* This module provides a reusable upload pattern for CAR files to Filecoin
* via Synapse SDK, used by both the import command and pinning server.
*/
import type { PieceCID } from '@filoz/synapse-sdk';
import { type ProviderInfo } from '@filoz/synapse-sdk';
import type { CID } from 'multiformats/cid';
import type { Logger } from 'pino';
import type { SynapseService } from '../synapse/index.js';
import type { ProgressEvent, ProgressEventHandler } from '../utils/types.js';
export type UploadProgressEvents = ProgressEvent<'onUploadComplete', {
pieceCid: PieceCID;
}> | ProgressEvent<'onPieceAdded', {
txHash: `0x${string}` | undefined;
}> | ProgressEvent<'onPieceConfirmed', {
pieceIds: number[];
}>;
export interface SynapseUploadOptions {
/**
* Optional callbacks for monitoring upload progress
*/
onProgress?: ProgressEventHandler<UploadProgressEvents>;
/**
* Context identifier for logging (e.g., pinId, import job ID)
*/
contextId?: string;
/**
* Optional metadata to associate with the upload
*/
pieceMetadata?: Record<string, string>;
}
export interface SynapseUploadResult {
pieceCid: string;
pieceId?: number | undefined;
dataSetId: string;
providerInfo: ProviderInfo;
}
/**
* Get the direct download URL for a piece from a provider
*/
export declare function getDownloadURL(providerInfo: ProviderInfo, pieceCid: string): string;
/**
* Get the service URL from provider info
*/
export declare function getServiceURL(providerInfo: ProviderInfo): string;
/**
* Upload a CAR file to Filecoin via Synapse.
*
* This function encapsulates the common upload pattern:
* 1. Submit CAR data to Synapse storage
* 2. Track upload progress via callbacks
* 3. Return piece information
*
* @param synapseService - Initialized Synapse service
* @param carData - CAR file data as Uint8Array
* @param rootCid - The IPFS root CID to associate with this piece
* @param logger - Logger instance for tracking
* @param options - Optional callbacks and context
* @returns Upload result with piece information
*/
export declare function uploadToSynapse(synapseService: SynapseService, carData: Uint8Array, rootCid: CID, logger: Logger, options?: SynapseUploadOptions): Promise<SynapseUploadResult>;
//# sourceMappingURL=synapse.d.ts.map