Skip to content

Commit 5ffdc86

Browse files
committed
Test fixes
1 parent ca1c01a commit 5ffdc86

2 files changed

Lines changed: 84 additions & 160 deletions

File tree

src/index.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FilebaseClient {
2929
#VALID_FORMATS = ["ipns-record", "raw", "car"];
3030

3131
#default_bucket;
32-
#default_gateway = this.#PUBLIC_IPFS_GATEWAY;
32+
#default_gateway;
3333

3434
#ipfs_credentials;
3535
#ipfs_client;
@@ -88,11 +88,7 @@ class FilebaseClient {
8888
Authorization: `Bearer ${Buffer.from(ipfsCredentials).toString("base64")}`,
8989
},
9090
},
91-
method: "POST",
9291
responseType: "text",
93-
validateStatus: function (status) {
94-
return status === 200;
95-
},
9692
});
9793
//endregion
9894

@@ -129,6 +125,11 @@ class FilebaseClient {
129125
},
130126
});
131127
//endregion
128+
129+
//region IPFS Gateway Client
130+
this.#default_gateway =
131+
options?.gateway.endpoint || this.#PUBLIC_IPFS_GATEWAY;
132+
//endregion
132133
}
133134

134135
//region Utility Methods
@@ -269,19 +270,30 @@ class FilebaseClient {
269270
//region File Methods
270271
async #uploadFiles(formData, options) {
271272
options.headers = options.headers || {};
273+
options.headers = {
274+
...options.headers,
275+
};
272276
options.headers["Authorization"] =
273277
`Bearer ${this.#getIpfsCredentials(options?.bucket)}`;
274278
options.searchParams = options.searchParams || {};
275279
options.searchParams["preserve-filenames"] = "true";
276280

277-
const downloadResponse = await axios.request({
281+
const downloadResponse = await this.#ipfs_client.request({
282+
method: "POST",
278283
url: "api/v0/add",
279284
headers: options.headers,
280285
params: options.searchParams,
286+
data: formData,
287+
validateStatus: function (status) {
288+
return status === 200;
289+
},
281290
});
282291

283292
const pins = [];
284293
for (const entry of downloadResponse.data.split("\n")) {
294+
if (entry === "") {
295+
continue;
296+
}
285297
const parsedEntry = JSON.parse(entry);
286298
pins.push({
287299
name: parsedEntry["Name"],
@@ -455,7 +467,8 @@ class FilebaseClient {
455467
}
456468

457469
async pinFile(path, cid, options) {
458-
await axios.request({
470+
await this.#ipfs_client.request({
471+
method: "POST",
459472
url: "api/v0/pin/add",
460473
headers: {
461474
Authorization: `Bearer ${this.#getIpfsCredentials(options?.bucket)}`,
@@ -464,6 +477,9 @@ class FilebaseClient {
464477
name: path,
465478
arg: cid,
466479
},
480+
validateStatus: function (status) {
481+
return status === 200;
482+
},
467483
});
468484
return true;
469485
}
@@ -490,16 +506,7 @@ class FilebaseClient {
490506
}
491507

492508
async uploadFiles(formData, options) {
493-
let encodedCredentials = this.#getIpfsCredentials(options?.bucket);
494-
const uploadOptions = {
495-
headers: {
496-
Authorization: `Bearer ${encodedCredentials}`,
497-
},
498-
params: {
499-
"preserve-filenames": "true",
500-
},
501-
};
502-
509+
const uploadOptions = {};
503510
return await this.#uploadFiles(formData, uploadOptions);
504511
}
505512
//endregion

0 commit comments

Comments
 (0)