This repository has been archived by the owner on Jun 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alan Shaw
committed
Jul 5, 2019
1 parent
3faa412
commit 4bc9318
Showing
31 changed files
with
396 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
'use strict' | ||
|
||
const QueryString = require('querystring') | ||
const { Buffer } = require('buffer') | ||
const configure = require('../lib/configure') | ||
const { ok } = require('../lib/fetch') | ||
|
||
module.exports = configure(({ fetch, apiUrl, apiPath, signal, headers }) => { | ||
module.exports = configure(({ fetch, apiUrl, apiPath, headers }) => { | ||
return async (cid, options) => { | ||
options = options || {} | ||
|
||
const qs = { arg: cid } | ||
const url = `${apiUrl}${apiPath}/block/get?${QueryString.stringify(qs)}` | ||
const url = `${apiUrl}${apiPath}/block/get?arg=${encodeURIComponent(cid)}` | ||
const res = await ok(fetch(url, { | ||
signal: options.signal, | ||
headers: options.headers || headers | ||
})) | ||
return Buffer.from(await res.blob()) | ||
return Buffer.from(await res.arrayBuffer()) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict' | ||
|
||
const QueryString = require('querystring') | ||
const FormData = require('form-data') | ||
const configure = require('../lib/configure') | ||
const { ok } = require('../lib/fetch') | ||
const toCamel = require('../lib/to-camel') | ||
|
||
module.exports = configure(({ fetch, apiUrl, apiPath, headers }) => { | ||
const put = async (data, options) => { | ||
options = options || {} | ||
|
||
const qs = Object.entries({ | ||
format: options.format, | ||
mhtype: options.mhtype, | ||
mhlen: options.mhlen, | ||
pin: options.pin | ||
}).reduce((obj, [key, value]) => { | ||
if (value != null) obj[key] = value | ||
return obj | ||
}, {}) | ||
|
||
const url = `${apiUrl}${apiPath}/block/put?${QueryString.stringify(qs)}` | ||
|
||
const body = new FormData() | ||
body.append('file', data) | ||
|
||
let res | ||
|
||
try { | ||
res = await ok(fetch(url, { | ||
method: 'POST', | ||
signal: options.signal, | ||
headers: options.headers || headers, | ||
body | ||
})) | ||
} catch (err) { | ||
// Retry with "protobuf"/"cbor" format for go-ipfs | ||
// TODO: remove when https://github.com/ipfs/go-cid/issues/75 resolved | ||
if (options.format === 'dag-pb') { | ||
return put(data, { ...options, format: 'protobuf' }) | ||
} else if (options.format === 'dag-cbor') { | ||
return put(data, { ...options, format: 'cbor' }) | ||
} | ||
|
||
throw err | ||
} | ||
|
||
return toCamel(await res.json()) | ||
} | ||
|
||
return put | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
|
||
const configure = require('../lib/configure') | ||
const { ok } = require('../lib/fetch') | ||
const toCamel = require('../lib/to-camel') | ||
|
||
module.exports = configure(({ fetch, apiUrl, apiPath, headers }) => { | ||
return async (cid, options) => { | ||
options = options || {} | ||
|
||
const url = `${apiUrl}${apiPath}/block/stat?arg=${encodeURIComponent(cid)}` | ||
const res = await ok(fetch(url, { | ||
signal: options.signal, | ||
headers: options.headers || headers | ||
})) | ||
return toCamel(await res.json()) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.