Skip to content

Commit d8b1266

Browse files
AmeanAsadguanzo
andauthored
fix: update file format usage (#39)
* feat: update file format usage * Update src/client.js Co-authored-by: Eric Guan <[email protected]> --------- Co-authored-by: Eric Guan <[email protected]>
1 parent 362c97e commit d8b1266

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/client.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class Saturn {
3232
* @param {string} [config.customerFallbackURL]
3333
* @param {number} [config.fallbackLimit]
3434
* @param {boolean} [config.experimental]
35+
* @param {string} [config.format]
3536
* @param {import('./storage/index.js').Storage} [config.storage]
3637
*/
3738
constructor (config = {}) {
@@ -41,6 +42,7 @@ export class Saturn {
4142
logURL: 'https://twb3qukm2i654i3tnvx36char40aymqq.lambda-url.us-west-2.on.aws/',
4243
orchURL: 'https://orchestrator.strn.pl/nodes?maxNodes=100',
4344
authURL: 'https://su4hesnyinnwvtk3h2rkauh5ja0qrisq.lambda-url.us-west-2.on.aws/',
45+
format: 'car',
4446
fallbackLimit: 5,
4547
connectTimeout: 5_000,
4648
downloadTimeout: 0
@@ -68,7 +70,7 @@ export class Saturn {
6870
* @returns {Promise<object>}
6971
*/
7072
async fetchCIDWithRace (cidPath, opts = {}) {
71-
const options = Object.assign({}, this.config, { format: 'car' }, opts)
73+
const options = Object.assign({}, this.config, opts)
7274
if (!opts.originFallback) {
7375
const [cid] = (cidPath ?? '').split('/')
7476
CID.parse(cid)
@@ -159,7 +161,7 @@ export class Saturn {
159161
* @returns {Promise<object>}
160162
*/
161163
async fetchCID (cidPath, opts = {}) {
162-
const options = Object.assign({}, this.config, { format: 'car' }, opts)
164+
const options = Object.assign({}, this.config, opts)
163165
if (!opts.originFallback) {
164166
const [cid] = (cidPath ?? '').split('/')
165167
CID.parse(cid)
@@ -264,7 +266,7 @@ export class Saturn {
264266
})
265267
}
266268
let byteCount = 0
267-
const fetchOptions = Object.assign(opts, { format: 'car' }, options)
269+
const fetchOptions = Object.assign(opts, options)
268270
const byteChunks = await this.fetchContent(cidPath, fetchOptions)
269271
for await (const chunk of byteChunks) {
270272
// avoid sending duplicate chunks
@@ -347,6 +349,7 @@ export class Saturn {
347349
*/
348350
async * fetchContent (cidPath, opts = {}) {
349351
let res, controller, log
352+
opts = Object.assign({}, this.config, opts)
350353

351354
if (opts.raceNodes) {
352355
({ res, controller, log } = await this.fetchCIDWithRace(cidPath, opts))
@@ -365,10 +368,10 @@ export class Saturn {
365368

366369
try {
367370
const itr = metricsIterable(asAsyncIterable(res.body))
368-
if (opts.format === 'car') {
369-
yield * extractVerifiedContent(cidPath, itr)
370-
} else {
371+
if (!opts.format) {
371372
yield * itr
373+
} else {
374+
yield * extractVerifiedContent(cidPath, itr)
372375
}
373376
} catch (err) {
374377
log.error = err.message

0 commit comments

Comments
 (0)