@oap75/api
Version:
JavaScript API for Subsocial blockchain.
145 lines (144 loc) • 7.24 kB
TypeScript
import { Content, IpfsCid as RuntimeIpfsCid } from '@subsocial/types/substrate/interfaces';
import { CommonContent, SpaceContent, PostContent, CommentContent, CID, IpfsCid, ProfileContent } from '@subsocial/types/offchain';
import { SubsocialContext, ContentResult } from '../types';
import { SocialAccountWithId } from '@subsocial/types/dto';
/** Return IPFS cid by social account struct */
export declare function getIpfsCidOfSocialAccount(struct: SocialAccountWithId): string | undefined;
declare type HasContentField = {
content: Content;
};
declare type HasIpfsCidSomewhere = HasContentField | SocialAccountWithId;
/** 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;
export declare type SubsocialIpfsProps = SubsocialContext & {
ipfsNodeUrl: IpfsUrl;
offchainUrl: string;
};
/** 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 ipfsNodeUrl;
/** Offchain gateway */
private offchainUrl;
private useServer?;
/** Sets values for ptivate fields from props and trying to make a test connection */
constructor(props: SubsocialIpfsProps);
/** Trying to make a test connection */
private testConnection;
/** Makes a request to the IPFS node */
private ipfsNodeRequest;
/** Return unique cids from cids array */
getUniqueCids(cids: IpfsCid[], contentName?: string): CID[];
/** Return object with contents from IPFS by cids array */
getContentArrayFromIpfs<T extends CommonContent>(cids: IpfsCid[], contentName?: string): Promise<ContentResult<T>>;
/** Return object with contents from IPFS through offchain by cids array */
getContentArrayFromOffchain<T extends CommonContent>(cids: IpfsCid[], contentName?: string): Promise<ContentResult<T>>;
getContentArray<T extends CommonContent>(cids: IpfsCid[], contentName?: string): Promise<ContentResult<T>>;
/**
* Find and load an array of off-chain information about spaces from IPFS by a given array of `cids`.
*
* Space information only exists if there is a corresponding JSON file that represents the spaces' content on IPFS.
*
* @param cids - An array of IPFS content ids of desired spaces.
*
* @returns An array of data about desired spaces from IPFS. If no corresponding spaces to given array of `cids`, an
* empty array is returned.
*/
findSpaces(cids: IpfsCid[]): Promise<ContentResult<SpaceContent>>;
/**
* Find and load an array of off-chain information about posts from IPFS by a given array of `cids`.
*
* Post information only exists if there is a corresponding JSON file that represents the posts' content on IPFS.
*
* @param cids - An array of IPFS content ids of desired posts.
*
* @returns An array of data about desired posts from IPFS. If no corresponding posts to given array of `cids`, an
* empty array is returned.
*/
findPosts(cids: IpfsCid[]): Promise<ContentResult<PostContent>>;
/**
* Find and load an array of off-chain information about comments from IPFS by a given array of `cids`.
*
* Comment information only exists if there is a corresponding JSON file that represents the comments' content on
* IPFS.
*
* @param cids - An array of IPFS content ids of desired comments.
*
* @returns An array of data about desired comments from IPFS. If no corresponding comments to given array of `cids`,
* an empty array is returned.
*/
findComments(cids: IpfsCid[]): Promise<ContentResult<CommentContent>>;
/**
* Find and load an array of off-chain information about profiles from IPFS by a given array of `cids`.
*
* Profile information only exists if there is a corresponding JSON file that represents the profiles' content on
* IPFS.
*
* @param cids - An array of IPFS content ids of desired profiles.
*
* @returns An array of data about desired profiles from IPFS. If no corresponding profiles to given array of `cids`,
* an empty array is returned.
*/
findProfiles(cids: IpfsCid[]): Promise<ContentResult<ProfileContent>>;
getContent<T extends CommonContent>(cid: IpfsCid, contentName?: string): Promise<T | undefined>;
/**
* Find and load off-chain information about a space from IPFS by a given `cid`.
*
* Space information only exists if there is a corresponding JSON file that represents the space's content on IPFS.
*
* @param cid - IPFS content id of a desired space.
*
* @returns Data about a desired space from IPFS. If no corresponding space to given `id`, `undefined` is returned.
*/
findSpace(cid: IpfsCid): Promise<SpaceContent | undefined>;
/**
* Find and load off-chain information about a post from IPFS by a given `cid`.
*
* Post information only exists if there is a corresponding JSON file that represents the post's content on IPFS.
*
* @param cid - IPFS content id of a desired post.
*
* @returns Data about a desired post from IPFS. If no corresponding post to given `id`, `undefined` is returned.
*/
findPost(cid: IpfsCid): Promise<PostContent | undefined>;
/**
* Find and load off-chain information about a comment from IPFS by a given `cid`.
*
* Comment information only exists if there is a corresponding JSON file that represents the comment's content on
* IPFS.
*
* @param cid - IPFS content id of a desired comment.
*
* @returns Data about a desired comment from IPFS. If no corresponding comments to given `id`, `undefined` is
* returned.
*/
findComment(cid: IpfsCid): Promise<CommentContent | undefined>;
/**
* Find and load off-chain information about a profile from IPFS by a given `cid`.
*
* Profile information only exists if there is a corresponding JSON file that represents the profile's content on
* IPFS.
*
* @param cid - IPFS content id of a desired profile.
*
* @returns Data about a desired profile from IPFS. If no corresponding profiles to given `id`, `undefined` is
* returned.
*/
findProfile(cid: IpfsCid): Promise<ProfileContent | undefined>;
/** Unpin content in IPFS */
removeContent(cid: IpfsCid): Promise<void>;
/** Add and pin content in IPFS */
saveContent(content: CommonContent): Promise<RuntimeIpfsCid | undefined>;
/** Add and pit file in IPFS */
saveFile(file: File | Blob): Promise<any>;
/** Add and pin space content in IPFS */
saveSpace(content: SpaceContent): Promise<RuntimeIpfsCid | undefined>;
/** Add and pin post content in IPFS */
savePost(content: PostContent): Promise<RuntimeIpfsCid | undefined>;
/** Add and pin comment content in IPFS */
saveComment(content: CommentContent): Promise<RuntimeIpfsCid | undefined>;
}
export {};