This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +30
-5
lines changed
Expand file tree Collapse file tree 4 files changed +30
-5
lines changed 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 @@ -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