This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +54
-11
lines changed
Expand file tree Collapse file tree 6 files changed +54
-11
lines changed Original file line number Diff line number Diff line change 6060 "form-data" : " ^2.1.2" ,
6161 "fs-pull-blob-store" : " ^0.4.1" ,
6262 "gulp" : " ^3.9.1" ,
63- "interface-ipfs-core" : " ^0.22.0 " ,
63+ "interface-ipfs-core" : " ^0.22.1 " ,
6464 "left-pad" : " ^1.1.3" ,
6565 "lodash" : " ^4.17.2" ,
6666 "ncp" : " ^2.0.0" ,
8080 "hapi" : " ^16.0.1" ,
8181 "hapi-set-header" : " ^1.0.2" ,
8282 "idb-pull-blob-store" : " ^0.5.1" ,
83- "ipfs-api" : " ^12.0.3 " ,
83+ "ipfs-api" : " ^12.1.0 " ,
8484 "ipfs-bitswap" : " ^0.8.2" ,
8585 "ipfs-block" : " ^0.5.1" ,
8686 "ipfs-block-service" : " ^0.7.1" ,
150150 " nginnever <ginneversource@gmail.com>" ,
151151 " npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>"
152152 ]
153- }
153+ }
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ const log = debug('cli:object')
77log . error = debug ( 'cli:object:error' )
88
99module . exports = {
10- command : 'new' ,
10+ command : 'new [<template>] ' ,
1111
1212 describe : 'Create new ipfs objects' ,
1313
@@ -16,7 +16,7 @@ module.exports = {
1616 handler ( argv ) {
1717 waterfall ( [
1818 ( cb ) => utils . getIPFS ( cb ) ,
19- ( ipfs , cb ) => ipfs . object . new ( cb )
19+ ( ipfs , cb ) => ipfs . object . new ( argv . template , cb )
2020 ] , ( err , node ) => {
2121 if ( err ) {
2222 throw err
Original file line number Diff line number Diff line change 22
33const peerId = require ( 'peer-id' )
44const waterfall = require ( 'async/waterfall' )
5+ const parallel = require ( 'async/parallel' )
56
67const addDefaultAssets = require ( './init-assets' )
78
@@ -51,11 +52,28 @@ module.exports = function init (self) {
5152 } ,
5253 ( cb ) => self . _repo . config . set ( config , cb ) ,
5354 ( cb ) => {
54- if ( typeof addDefaultAssets === 'function' && ! opts . emptyRepo ) {
55- return addDefaultAssets ( self , opts . log , cb )
55+ if ( opts . emptyRepo ) {
56+ return cb ( null , true )
5657 }
5758
58- cb ( null , true )
59+ const tasks = [
60+ // add empty unixfs dir object (go-ipfs assumes this exists)
61+ ( cb ) => self . object . new ( 'unixfs-dir' , cb )
62+ ]
63+
64+ if ( typeof addDefaultAssets === 'function' ) {
65+ tasks . push (
66+ ( cb ) => addDefaultAssets ( self , opts . log , cb )
67+ )
68+ }
69+
70+ parallel ( tasks , ( err ) => {
71+ if ( err ) {
72+ return cb ( err )
73+ }
74+
75+ cb ( null , true )
76+ } )
5977 }
6078 ] , callback )
6179 }
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ const DAGNode = dagPB.DAGNode
77const DAGLink = dagPB . DAGLink
88const CID = require ( 'cids' )
99const mh = require ( 'multihashes' )
10+ const Unixfs = require ( 'ipfs-unixfs' )
11+ const assert = require ( 'assert' )
1012
1113function normalizeMultihash ( multihash , enc ) {
1214 if ( typeof multihash === 'string' ) {
@@ -91,8 +93,22 @@ module.exports = function object (self) {
9193 }
9294
9395 return {
94- new : promisify ( ( callback ) => {
95- DAGNode . create ( new Buffer ( 0 ) , ( err , node ) => {
96+ new : promisify ( ( template , callback ) => {
97+ if ( typeof template === 'function' ) {
98+ callback = template
99+ template = undefined
100+ }
101+
102+ let data
103+
104+ if ( template ) {
105+ assert ( template === 'unixfs-dir' , 'unkown template' )
106+ data = ( new Unixfs ( 'directory' ) ) . marshal ( )
107+ } else {
108+ data = new Buffer ( 0 )
109+ }
110+
111+ DAGNode . create ( data , ( err , node ) => {
96112 if ( err ) {
97113 return callback ( err )
98114 }
Original file line number Diff line number Diff line change @@ -34,8 +34,9 @@ exports.parseKey = (request, reply) => {
3434
3535exports . new = ( request , reply ) => {
3636 const ipfs = request . server . app . ipfs
37+ const template = request . query . arg
3738
38- ipfs . object . new ( ( err , node ) => {
39+ ipfs . object . new ( template , ( err , node ) => {
3940 if ( err ) {
4041 log . error ( err )
4142 return reply ( {
Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ describe('object', () => {
1717 } )
1818 } )
1919
20+ it ( 'new unixfs-dir' , ( ) => {
21+ return ipfs ( 'object new unixfs-dir' ) . then ( ( out ) => {
22+ expect ( out ) . to . be . eql (
23+ 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
24+ )
25+ } )
26+ } )
27+
2028 it ( 'get' , ( ) => {
2129 return ipfs ( 'object get QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n' ) . then ( ( out ) => {
2230 const result = JSON . parse ( out )
You can’t perform that action at this time.
0 commit comments