RangerMauve / js-ipfs-fetch

Use the same `fetch()` API browsers provide for HTTP, but for IPFS
https://youtu.be/kI9Issf3MNc?t=1606
MIT License
65 stars 8 forks source link

error: paths must start with a leading slash #9

Closed resession closed 2 years ago

resession commented 2 years ago

when i make a post request with both ipfs:// and ipfs:///, i get the following a leading slash error

here is the result from running npm run test

> js-ipfs-fetch@3.4.0 test
> standard --fix && node test

TAP version 13
# Load a file via fetch
ok 1 Able to make create fetch instance
ok 2 Got a response object
ok 3 Got OK in response
ok 4 Got expected content type
ok 5 Got expected file content
# Load a file from just the CID
ok 6 Able to make create fetch instance
ok 7 Got a response object
ok 8 Got OK in response
ok 9 Got expected content type
ok 10 Got expected file content
# Load a range from a file
ok 11 Able to make create fetch instance
ok 12 Got a response object
ok 13 Got partial response
ok 14 Got expected file content
# Get expected headers from HEAD
ok 15 Able to make create fetch instance
ok 16 Got a response object
ok 17 Got OK in response
ok 18 Got expected content length
# Load a directory listing via fetch
ok 19 Able to make create fetch instance
ok 20 Got a response object
ok 21 Got OK in response
ok 22 Got directory listing
ok 23 Listing has first file
ok 24 Listing has second file
ok 25 Got OK in response
ok 26 Got files in JSON form
# Resolve index.html from a directory
ok 27 Able to make create fetch instance
ok 28 Got a response object
ok 29 Got OK in response
not ok 30 Got index from directory
  ---
    operator: equal
    expected: 'Hello World!'
    actual:   ''
    at: Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:224:7)
    stack: |-
      Error: Got index from directory
          at Test.assert [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:314:54)
          at Test.bound [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.strictEqual (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:478:10)
          at Test.bound [as equal] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:224:7)
  ...
ok 31 Got OK in response
ok 32 Got files in JSON form
ok 33 Got a response object
ok 34 Got OK in response
not ok 35 Got index from directory
  ---
    operator: equal
    expected: 'Hello World!'
    actual:   ''
    at: Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:241:7)
    stack: |-
      Error: Got index from directory
          at Test.assert [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:314:54)
          at Test.bound [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.strictEqual (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:478:10)
          at Test.bound [as equal] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:241:7)
  ...
# POST a file into IPFS
ok 36 Able to make create fetch instance
Error: paths must start with a leading slash
    at toMfsPath (F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-core\src\components\files\utils\to-mfs-path.js:120:19)
    at async F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-core\src\components\files\write.js:101:21
    at async F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-core\src\components\files\utils\create-lock.js:36:18
    at async mfsWrite (F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-core\src\components\files\write.js:99:5)
    at async uploadData (F:\Proj\Development\js-ipfs-fetch\index.js:139:9)
    at async F:\Proj\Development\js-ipfs-fetch\index.js:197:26
    at async fetch (F:\Proj\Development\js-ipfs-fetch\node_modules\make-fetch\index.js:35:9)
    at async Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:261:22)
ok 37 Got a response object
not ok 38 Got OK in response
  ---
    operator: equal
    expected: 200
    actual:   500
    at: Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:267:7)
    stack: |-
      Error: Got OK in response
          at Test.assert [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:314:54)
          at Test.bound [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.strictEqual (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:478:10)
          at Test.bound [as equal] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:267:7)
  ...
not ok 39 returned IPFS url with CID
  ---
    operator: match
    expected: |-
      /^ipfs:\/\/\w+\/example.txt$/
    actual: |-
      'Error: paths must start with a leading slash\n    at toMfsPath (F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\ipfs-core\\src\\components\\files\\utils\\to-mfs-path.js:120:19)\n    at async 
F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\ipfs-core\\src\\components\\files\\write.js:101:21\n    at async F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\ipfs-core\\src\\components\\files\\utils\\create-lock.js:36:18\n    at async mfsWrite (F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\ipfs-core\\src\\components\\files\\write.js:99:5)\n    at async uploadData (F:\\Proj\\Development\\js-ipfs-fetch\\index.js:139:9)\n    at async F:\\Proj\\Development\\js-ipfs-fetch\\index.js:197:26\n    at async fetch (F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\make-fetch\\index.js:35:9)\n    at async Test.<anonymous> (F:\\Proj\\Development\\js-ipfs-fetch\\test.js:261:22)'
    at: Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:270:7)
    stack: |-
      Error: returned IPFS url with CID
          at Test.assert [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:314:54)
          at Test.bound [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.match (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:733:14)
          at Test.bound [as match] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:270:7)
  ...
Error: To parse non base32 or base58btc encoded CID multibase decoder must be provided
    at parseCIDtoBytes (F:\Proj\Development\js-ipfs-fetch\node_modules\multiformats\cjs\src\cid.js:235:15)
    at Function.parse (F:\Proj\Development\js-ipfs-fetch\node_modules\multiformats\cjs\src\cid.js:204:29)
    at cidAndRest (F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-unixfs-exporter\cjs\src\index.js:38:20)
    at walkPath (F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-unixfs-exporter\cjs\src\index.js:45:26)
    at walkPath.next (<anonymous>)
    at Object.last [as default] (F:\Proj\Development\js-ipfs-fetch\node_modules\it-last\index.js:13:20)
    at exporter (F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-unixfs-exporter\cjs\src\index.js:67:48)
    at getStat (F:\Proj\Development\js-ipfs-fetch\index.js:43:14)
    at F:\Proj\Development\js-ipfs-fetch\index.js:243:28
    at fetch (F:\Proj\Development\js-ipfs-fetch\node_modules\make-fetch\index.js:35:15)
not ok 40 Got OK in response
  ---
    operator: equal
    expected: 200
    actual:   500
    at: Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:273:7)
    stack: |-
      Error: Got OK in response
          at Test.assert [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:314:54)
          at Test.bound [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.strictEqual (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:478:10)
          at Test.bound [as equal] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:273:7)
  ...
not ok 41 Able to load POSTed file
  ---
    operator: equal
    expected: |-
      'Hello World!'
    actual: |-
      'Error: To parse non base32 or base58btc encoded CID multibase decoder must be provided\n    at parseCIDtoBytes (F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\multiformats\\cjs\\src\\cid.js:235:15)\n    at Function.parse (F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\multiformats\\cjs\\src\\cid.js:204:29)\n    at cidAndRest (F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\ipfs-unixfs-exporter\\cjs\\src\\index.js:38:20)\n    at walkPath (F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\ipfs-unixfs-exporter\\cjs\\src\\index.js:45:26)\n    at walkPath.next (<anonymous>)\n    at Object.last [as default] (F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\it-last\\index.js:13:20)\n    at exporter (F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\ipfs-unixfs-exporter\\cjs\\src\\index.js:67:48)\n    at getStat (F:\\Proj\\Development\\js-ipfs-fetch\\index.js:43:14)\n    at F:\\Proj\\Development\\js-ipfs-fetch\\index.js:243:28\n    at fetch (F:\\Proj\\Development\\js-ipfs-fetch\\node_modules\\make-fetch\\index.js:35:15)'
    at: Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:276:7)
    stack: |-
      Error: Able to load POSTed file
          at Test.assert [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:314:54)
          at Test.bound [as _assert] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.strictEqual (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:478:10)
          at Test.bound [as equal] (F:\Proj\Development\js-ipfs-fetch\node_modules\tape\lib\test.js:99:32)
          at Test.<anonymous> (F:\Proj\Development\js-ipfs-fetch\test.js:276:7)
  ...
# POST formdata to IPFS
ok 42 Able to make create fetch instance
F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-core\src\components\files\utils\to-mfs-path.js:120
    throw errCode(new Error('paths must start with a leading slash'), 'ERR_INVALID_PATH')
                  ^

Error: paths must start with a leading slash
    at toMfsPath (F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-core\src\components\files\utils\to-mfs-path.js:120:19)
    at async F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-core\src\components\files\write.js:101:21
    at async F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-core\src\components\files\utils\create-lock.js:36:18
    at async mfsWrite (F:\Proj\Development\js-ipfs-fetch\node_modules\ipfs-core\src\components\files\write.js:99:5) {
  code: 'ERR_INVALID_PATH'
}
RangerMauve commented 2 years ago

Try 3.5.0, I think it's fixed.

I'm now running tests on the GitHub CI to make sure they pass on Android.

https://github.com/RangerMauve/js-ipfs-fetch/runs/5517232657?check_suite_focus=true