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

Function uploadFiles

packages/cli/src/controller/publish-controller.ts:135–176  ·  view source on GitHub ↗
(
  contents: {path: string; content: string}[],
  authToken?: string,
  isMultichain?: boolean,
  ipfs?: IPFSHTTPClientLite
)

Source from the content-addressed store, hash-verified

133const fileMap = new Map<string | fs.ReadStream, Promise<string>>();
134
135export async function uploadFiles(
136 contents: {path: string; content: string}[],
137 authToken?: string,
138 isMultichain?: boolean,
139 ipfs?: IPFSHTTPClientLite
140): Promise<Map<string, string>> {
141 const fileCidMap: Map<string, string> = new Map();
142
143 if (ipfs) {
144 try {
145 const results = await ipfs.addAll(contents, {wrapWithDirectory: isMultichain});
146
147 for (const result of results) {
148 fileCidMap.set(result.path, result.cid.toString());
149 }
150 } catch (e) {
151 throw new Error(`Publish project to provided IPFS gateway failed`, {cause: e});
152 }
153 }
154
155 const ipfsWrite = new IPFSHTTPClientLite({
156 url: IPFS_WRITE_ENDPOINT,
157 headers: authToken ? {Authorization: `Bearer ${authToken}`} : undefined,
158 });
159
160 try {
161 const results = await ipfsWrite.addAll(contents, {pin: true, cidVersion: 0, wrapWithDirectory: isMultichain});
162 for (const result of results) {
163 fileCidMap.set(result.path, result.cid);
164
165 await ipfsWrite.pinRemoteAdd(result.cid, {service: PIN_SERVICE}).catch((e) => {
166 console.warn(
167 `Failed to pin file ${result.path}. There might be problems with this file being accessible later. ${e}`
168 );
169 });
170 }
171 } catch (e) {
172 throw new Error(`Publish project files to IPFS failed`, {cause: e});
173 }
174
175 return fileCidMap;
176}
177
178export async function uploadFile(
179 contents: {path: string; content: string},

Callers 1

uploadToIpfsFunction · 0.85

Calls 4

addAllMethod · 0.95
pinRemoteAddMethod · 0.95
setMethod · 0.65
warnMethod · 0.45

Tested by

no test coverage detected