This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree 2 files changed +25
-31
lines changed 2 files changed +25
-31
lines changed Original file line number Diff line number Diff line change 59
59
"err-code" : " ^2.0.0" ,
60
60
"hamt-sharding" : " ~0.0.2" ,
61
61
"interface-datastore" : " ~0.7.0" ,
62
- "ipfs-multipart" : " ~0.1 .0" ,
62
+ "ipfs-multipart" : " ~0.2 .0" ,
63
63
"ipfs-unixfs" : " ~0.1.16" ,
64
64
"ipfs-unixfs-exporter" : " ~0.38.0" ,
65
65
"ipfs-unixfs-importer" : " ~0.40.0" ,
Original file line number Diff line number Diff line change @@ -28,39 +28,33 @@ const mfsWrite = {
28
28
shardSplitThreshold
29
29
} = request . query
30
30
31
- const fileStream = await new Promise ( ( resolve , reject ) => {
32
- const parser = multipart . reqParser ( request . payload )
33
- let fileStream
31
+ let files = 0
34
32
35
- parser . on ( 'file' , ( _ , stream ) => {
36
- if ( fileStream ) {
37
- return reject ( Boom . badRequest ( 'Please only send one file' ) )
38
- }
39
-
40
- fileStream = stream
41
- resolve ( fileStream )
42
- } )
33
+ for await ( const entry of multipart ( request ) ) {
34
+ if ( entry . type === 'file' ) {
35
+ files ++
43
36
44
- parser . on ( 'error' , ( error ) => {
45
- reject ( error )
46
- } )
47
- } )
37
+ if ( files > 1 ) {
38
+ throw Boom . badRequest ( 'Please only send one file' )
39
+ }
48
40
49
- await ipfs . files . write ( arg , fileStream , {
50
- offset,
51
- length,
52
- create,
53
- truncate,
54
- rawLeaves,
55
- cidVersion,
56
- hashAlg,
57
- format,
58
- parents,
59
- progress,
60
- strategy,
61
- flush,
62
- shardSplitThreshold
63
- } )
41
+ await ipfs . files . write ( arg , entry . content , {
42
+ offset,
43
+ length,
44
+ create,
45
+ truncate,
46
+ rawLeaves,
47
+ cidVersion,
48
+ hashAlg,
49
+ format,
50
+ parents,
51
+ progress,
52
+ strategy,
53
+ flush,
54
+ shardSplitThreshold
55
+ } )
56
+ }
57
+ }
64
58
65
59
return h . response ( )
66
60
} ,
You can’t perform that action at this time.
0 commit comments