UNPKG

@subsocial/api

Version:
67 lines (66 loc) 3.3 kB
import { Content, IpfsCid as RuntimeIpfsCid } from '@subsocial/definitions/interfaces'; import { ImportCandidate, IpfsCid, IpfsCommonContent } from '../types'; import { CommonContent, ContentResult, SubsocialContext } from '../types'; import { AnyJson } from '@polkadot/types-codec/types'; declare type HasContentField = { content: Content; }; declare type HasIpfsCidSomewhere = HasContentField; declare type CrustAuthProps = { publicAddress: string; signedAddress: Uint8Array; }; /** Try to resolve a corresponding IPFS CID of a given struct. */ export declare function getIpfsCidOfStruct<S extends HasIpfsCidSomewhere>(struct: S): string | undefined; /** Extract ids of an array of structs. */ export declare function getCidsOfStructs(structs: HasIpfsCidSomewhere[]): string[]; declare type IpfsUrl = string; declare type Headers = Record<string, any>; export declare type SubsocialIpfsProps = SubsocialContext & { ipfsNodeUrl: IpfsUrl; ipfsAdminNodeUrl?: IpfsUrl; ipfsClusterUrl?: IpfsUrl; offchainUrl?: string; headers?: Headers; }; /** Aggregated API to work with IPFS: get the content of the spaces of posts and profiles. */ export declare class SubsocialIpfsApi { /** IPFS node readonly gateway */ private _client; private _adminClient; private readonly _ipfsNodeUrl; private readonly _ipfsAdminNodeUrl; private readonly _ipfsClusterUrl; /** Offchain gateway */ private readonly offchainUrl; private writeHeaders; private pinHeaders; private createIpfsClient; constructor({ ipfsNodeUrl, ipfsAdminNodeUrl, ipfsClusterUrl, offchainUrl, headers }: SubsocialIpfsProps); static generateCrustAuthToken(auth: CrustAuthProps): string; get client(): import("ipfs-http-client/types/src/types").IPFSHTTPClient; get adminClient(): import("ipfs-http-client/types/src/types").IPFSHTTPClient; setWriteHeaders(headers: Headers): void; setPinHeaders(headers: Headers): void; getContentArray<T extends IpfsCommonContent>(cids: IpfsCid[], timeout?: number): Promise<ContentResult<T>>; getContent<T extends IpfsCommonContent>(cid: IpfsCid, timeout?: number): Promise<T | undefined>; /** Return object with contents from IPFS by cids array */ getContentArrayFromIpfs<T extends IpfsCommonContent>(cids: IpfsCid[], timeout?: number): Promise<ContentResult<T>>; /** Pin content in IPFS */ pinContent(cid: IpfsCid, props?: Record<'asLink' | string, any>): Promise<import("axios").AxiosResponse<any, any>>; /** Unpin content in IPFS */ unpinContent(cid: IpfsCid): Promise<import("axios").AxiosResponse<any, any>>; /** Add content in IPFS using Crob format*/ saveContent(content: AnyJson | CommonContent): Promise<string>; /** Add file in IPFS using unixFs */ saveFile(file: ImportCandidate): Promise<string>; /** Add JSON in IPFS using unixFs */ saveJson(json: Record<any, any>): Promise<string>; /** @deprecated Unpin content in IPFS via Offchain */ removeContent(cid: IpfsCid): Promise<void>; /** Add and pin content in IPFS via Offchain */ saveContentToOffchain(content: IpfsCommonContent): Promise<RuntimeIpfsCid | undefined>; /** Add and pit file in IPFS via Offchain */ saveFileToOffchain(file: File | Blob): Promise<any>; } export {};