This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-23
lines changed
src/core/components/files-regular Expand file tree Collapse file tree 2 files changed +14
-23
lines changed Original file line number Diff line number Diff line change 152
152
"peer-id" : " ~0.12.3" ,
153
153
"peer-info" : " ~0.15.0" ,
154
154
"progress" : " ^2.0.1" ,
155
+ "promise-nodeify" : " 3.0.1" ,
155
156
"promisify-es6" : " ^1.0.3" ,
156
157
"protons" : " ^1.0.1" ,
157
158
"pull-abortable" : " ^4.1.1" ,
Original file line number Diff line number Diff line change 2
2
3
3
const { URL } = require ( 'iso-url' )
4
4
const { default : ky } = require ( 'ky-universal' )
5
+ const nodeify = require ( 'promise-nodeify' )
5
6
6
- module . exports = ( self ) => {
7
- return async ( url , options , callback ) => {
8
- if ( typeof options === 'function' ) {
9
- callback = options
10
- options = { }
11
- }
12
-
13
- let files
14
- try {
15
- const res = await ky . get ( url )
16
- const path = decodeURIComponent ( new URL ( res . url ) . pathname . split ( '/' ) . pop ( ) )
17
- const content = Buffer . from ( await res . arrayBuffer ( ) )
18
- files = await self . add ( { content, path } , options )
19
- } catch ( err ) {
20
- if ( callback ) {
21
- return callback ( err )
22
- }
23
- throw err
24
- }
7
+ module . exports = ( ipfs ) => {
8
+ const addFromURL = async ( url , opts = { } ) => {
9
+ const res = await ky . get ( url )
10
+ const path = decodeURIComponent ( new URL ( res . url ) . pathname . split ( '/' ) . pop ( ) )
11
+ const content = Buffer . from ( await res . arrayBuffer ( ) )
12
+ return ipfs . add ( { content, path } , opts )
13
+ }
25
14
26
- if ( callback ) {
27
- callback ( null , files )
15
+ return ( name , opts = { } , cb ) => {
16
+ if ( typeof opts === 'function' ) {
17
+ cb = opts
18
+ opts = { }
28
19
}
29
-
30
- return files
20
+ return nodeify ( addFromURL ( name , opts ) , cb )
31
21
}
32
22
}
You can’t perform that action at this time.
0 commit comments