MCPcopy
hub / github.com/subquery/subql / uploadToIpfs

Function uploadToIpfs

packages/cli/src/controller/publish-controller.ts:31–97  ·  view source on GitHub ↗
(
  projectPaths: string[],
  authToken?: string,
  multichainProjectPath?: string,
  ipfsEndpoint?: string,
  directory?: string
)

Source from the content-addressed store, hash-verified

29}
30
31export async function uploadToIpfs(
32 projectPaths: string[],
33 authToken?: string,
34 multichainProjectPath?: string,
35 ipfsEndpoint?: string,
36 directory?: string
37): Promise<Map<string, string>> {
38 const projectToReader: Record<string, Reader> = {};
39
40 await Promise.all(
41 projectPaths.map(async (projectPath) => {
42 const reader = await ReaderFactory.create(projectPath);
43 projectToReader[projectPath] = reader;
44 })
45 );
46
47 const contents: {path: string; content: string}[] = [];
48
49 let ipfs: IPFSHTTPClientLite | undefined;
50 if (ipfsEndpoint) {
51 ipfs = new IPFSHTTPClientLite({url: ipfsEndpoint});
52 }
53
54 for (const project in projectToReader) {
55 const reader = projectToReader[project];
56 const schema = await reader.getProjectSchema();
57
58 validateCommonProjectManifest(schema);
59
60 const networkFamily = getProjectNetwork(schema);
61 const module = loadDependency(networkFamily, project);
62 assert(module, `Failed to load module for network ${networkFamily}`);
63
64 let manifest;
65
66 try {
67 manifest = module.parseProjectManifest(schema).asImpl;
68 } catch (e) {
69 throw new Error(`Failed to parse project manifest for network ${networkFamily}`, {cause: e});
70 }
71
72 if (manifest === null) {
73 throw new Error('Unable to parse project manifest');
74 }
75
76 assert(reader.root, 'Reader root is not set');
77 // the JSON object conversion must occur on manifest.deployment
78 const deployment = await replaceFileReferences(reader.root, manifest.deployment, authToken, ipfs);
79
80 // Use JSON.* to convert Map to Object
81 contents.push({
82 path: path.join(directory ?? '', path.basename(project)),
83 content: deployment.toYaml(),
84 });
85 }
86
87 if (multichainProjectPath) {
88 const content = fs.readFileSync(multichainProjectPath);

Callers 3

publishAdapterFunction · 0.90

Calls 10

getProjectNetworkFunction · 0.90
loadDependencyFunction · 0.90
replaceFileReferencesFunction · 0.85
uploadFilesFunction · 0.85
mapMethod · 0.80
parseProjectManifestMethod · 0.80
getProjectSchemaMethod · 0.65
toYamlMethod · 0.65
createMethod · 0.45

Tested by

no test coverage detected