This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: pin #107
Merged
Merged
feat: pin #107
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,15 +93,17 @@ | |
"async": "^2.5.0", | ||
"bl": "^1.2.1", | ||
"boom": "^5.2.0", | ||
"debug": "^3.0.1", | ||
"cids": "^0.5.1", | ||
"debug": "^3.0.1", | ||
"file-type": "^6.1.0", | ||
"filesize": "^3.5.10", | ||
"fnv1a": "^1.0.1", | ||
"fsm-event": "^2.1.0", | ||
"glob": "^7.1.2", | ||
"hapi": "^16.5.2", | ||
"hapi-set-header": "^1.0.2", | ||
"hoek": "^4.2.0", | ||
"interface-datastore": "^0.3.0", | ||
"ipfs-api": "^14.3.5", | ||
"ipfs-bitswap": "~0.17.2", | ||
"ipfs-block": "~0.6.0", | ||
|
@@ -126,6 +128,7 @@ | |
"libp2p-websockets": "~0.10.1", | ||
"lodash.flatmap": "^4.5.0", | ||
"lodash.get": "^4.4.2", | ||
"lodash.set": "^4.3.0", | ||
"lodash.sortby": "^4.7.0", | ||
"lodash.values": "^4.3.0", | ||
"mafmt": "^3.0.1", | ||
|
@@ -139,6 +142,7 @@ | |
"peer-id": "~0.10.1", | ||
"peer-info": "~0.11.0", | ||
"promisify-es6": "^1.0.3", | ||
"protocol-buffers": "^3.2.1", | ||
"pull-file": "^1.0.0", | ||
"pull-paramap": "^1.2.2", | ||
"pull-pushable": "^2.1.1", | ||
|
@@ -216,4 +220,4 @@ | |
"Łukasz Magiera <[email protected]>", | ||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <[email protected]>" | ||
] | ||
} | ||
} |
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,15 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
command: 'pin', | ||
|
||
description: 'Pin and unpin objects to local storage.', | ||
|
||
builder (yargs) { | ||
return yargs | ||
.commandDir('pin') | ||
}, | ||
|
||
handler (argv) { | ||
} | ||
} |
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,28 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
command: 'add <ipfs-path>', | ||
|
||
describe: 'Pins objects to local storage.', | ||
|
||
builder: { | ||
recursive: { | ||
type: 'boolean', | ||
alias: 'r', | ||
default: true, | ||
describe: 'Recursively pin the object linked to by the specified object(s).' | ||
} | ||
}, | ||
|
||
handler (argv) { | ||
const paths = argv['ipfs-path'].split(' ') | ||
const recursive = argv.recursive | ||
const type = recursive ? 'recursive' : 'direct' | ||
argv.ipfs.pin.add(paths[0], { recursive }, (err, results) => { | ||
if (err) { throw err } | ||
results.forEach((res) => { | ||
console.log(`pinned ${res.hash} ${type}ly`) | ||
}) | ||
}) | ||
} | ||
} |
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,43 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
command: 'ls', | ||
|
||
describe: 'List objects pinned to local storage.', | ||
|
||
builder: { | ||
path: { | ||
type: 'string', | ||
describe: 'List pinned state of specific <ipfs-path>.' | ||
}, | ||
type: { | ||
type: 'string', | ||
alias: 't', | ||
default: 'all', | ||
describe: ('The type of pinned keys to list. ' + | ||
'Can be "direct", "indirect", "recursive", or "all".') | ||
}, | ||
quiet: { | ||
type: 'boolean', | ||
alias: 'q', | ||
default: false, | ||
describe: 'Write just hashes of objects.' | ||
} | ||
}, | ||
|
||
handler: (argv) => { | ||
const paths = argv.path && argv.path.split(' ') | ||
const type = argv.type | ||
const quiet = argv.quiet | ||
argv.ipfs.pin.ls(paths, { type }, (err, results) => { | ||
if (err) { throw err } | ||
results.forEach((res) => { | ||
let line = res.hash | ||
if (!quiet) { | ||
line += ` ${res.type}` | ||
} | ||
console.log(line) | ||
}) | ||
}) | ||
} | ||
} |
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,35 @@ | ||
'use strict' | ||
|
||
const utils = require('../../utils') | ||
const debug = require('debug') | ||
const log = debug('cli:pin') | ||
log.error = debug('cli:pin:error') | ||
|
||
module.exports = { | ||
command: 'rm <ipfs-path>', | ||
|
||
describe: 'Removes the pinned object from local storage.', | ||
|
||
builder: { | ||
recursive: { | ||
type: 'boolean', | ||
alias: 'r', | ||
default: true, | ||
describe: 'Recursively unpin the objects linked to by the specified object(s).' | ||
} | ||
}, | ||
|
||
handler: (argv) => { | ||
const paths = argv['ipfs-path'].split(' ') | ||
const recursive = argv.recursive | ||
utils.getIPFS((err, ipfs) => { | ||
if (err) { throw err } | ||
ipfs.pin.rm(paths, { recursive }, (err, results) => { | ||
if (err) { throw err } | ||
results.forEach((res) => { | ||
console.log(`unpinned ${res.hash}`) | ||
}) | ||
}) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const multihashes = require('multihashes') | ||
|
||
module.exports = function KeySet (keys) { | ||
// Buffers with identical data are still different objects, so | ||
// they need to be cast to strings to prevent duplicates in Sets | ||
this.keys = {} | ||
this.add = (key) => { | ||
this.keys[multihashes.toB58String(key)] = key | ||
} | ||
this.delete = (key) => { | ||
delete this.keys[multihashes.toB58String(key)] | ||
} | ||
this.clear = () => { | ||
this.keys = {} | ||
} | ||
this.has = (key) => { | ||
return (multihashes.toB58String(key) in this.keys) | ||
} | ||
this.toArray = () => { | ||
return Object.keys(this.keys).map((hash) => { | ||
return this.keys[hash] | ||
}) | ||
} | ||
this.toStringArray = () => { | ||
return Object.keys(this.keys) | ||
} | ||
keys = keys || [] | ||
keys.forEach(this.add) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To
get
orput
in the datastore, the first argument should be a datastore Key object. Based on the example here it seems like I need to import this likeconst Key = require('interface-datastore').Key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
@dignifiedquire is there any reason why the .get and .put couldn't take a string or a buffer? I understand that
Key
has some utility methods, but the cast could happen internally as well.