forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: jsipfs pin improvements (ipfs#1249)
* initial sweep through to understand how pin works. Did make some changes but mostly minor. * refactor pb schema to it's own file * fix: don't pin files during files.add if opts.pin === false * feat: add some http qs parsing, http route/resources cleanup, cleanup core/utils.parseIpfsPath * feat: expand pin tests. \nFirst draft. still needs some further work. * feat: Add logging for entry/exit of pins: add/rm/flush/load. Clean some documentation. * feat: add --pin to files.add, fix: improper pin option parsing in core. * feat: Use ipfs.files.add to add init-docs instead of directly using the unix-fs importer. * feat(tests): Add tests for cli --pin option. I know this should be more of an integration test. Should be written in /core. Maybe talk with Victor about testing different layers * feat: use isIPFS to valiate a multihash.
- Loading branch information
Showing
18 changed files
with
1,419 additions
and
36 deletions.
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
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,30 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
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: recursive }, (err, results) => { | ||
if (err) { throw err } | ||
results.forEach((res) => { | ||
print(`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,42 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
module.exports = { | ||
// bracket syntax with '...' tells yargs to optionally accept a list | ||
command: 'ls [ipfs-path...]', | ||
|
||
describe: 'List objects pinned to local storage.', | ||
|
||
builder: { | ||
type: { | ||
type: 'string', | ||
alias: 't', | ||
default: 'all', | ||
choices: ['direct', 'indirect', 'recursive', 'all'], | ||
describe: 'The type of pinned keys to list.' | ||
}, | ||
quiet: { | ||
type: 'boolean', | ||
alias: 'q', | ||
default: false, | ||
describe: 'Write just hashes of objects.' | ||
} | ||
}, | ||
|
||
handler: (argv) => { | ||
const paths = argv.ipfsPath || '' | ||
const type = argv.type | ||
const quiet = argv.quiet | ||
argv.ipfs.pin.ls(paths, { type: type }, (err, results) => { | ||
if (err) { throw err } | ||
results.forEach((res) => { | ||
let line = res.hash | ||
if (!quiet) { | ||
line += ` ${res.type}` | ||
} | ||
print(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,29 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
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 | ||
argv.ipfs.pin.rm(paths, { recursive: recursive }, (err, results) => { | ||
if (err) { throw err } | ||
results.forEach((res) => { | ||
print(`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
Oops, something went wrong.