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.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,359 additions
and
2 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
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.