Commit 338baa22ed1a31664b6306c3b58352e256a469ea
Allow memory sharing instead of filesystem
Anders Rune Jensen committed on 9/27/2017, 6:16:21 PMParent: 589659eb2f7557af64874b5dc925456e0cc0764a
Files changed
README.md | changed |
bin.js | changed |
index.js | changed |
lib.js | changed |
package.json | changed |
README.md | ||
---|---|---|
@@ -7,9 +7,11 @@ | ||
7 | 7 | ``` |
8 | 8 | node bin.js -f ./dats |
9 | 9 | ``` |
10 | 10 | |
11 | -Can also take a -i option to only share links from people you follow. | |
11 | +Can also take a -i option to only share links from people you | |
12 | +follow. And can be told to share using memory (-t) instead of from | |
13 | +filesystem. | |
12 | 14 | |
13 | 15 | This should give you something like this: |
14 | 16 | |
15 | 17 | ``` |
@@ -44,6 +46,4 @@ | ||
44 | 46 | |
45 | 47 | https://github.com/datproject/dat-node |
46 | 48 | |
47 | 49 | - var stats = dat.trackStats(), peers |
48 | - - temp: false, // Use random-access-memory as the storage. | |
49 | - |
bin.js | ||
---|---|---|
@@ -6,18 +6,22 @@ | ||
6 | 6 | |
7 | 7 | program |
8 | 8 | .option('-f, --share-folder [value]', 'Folder for sharing') |
9 | 9 | .option('-i, --only-people-i-follow', 'Only seed urls from people or channels I follow') |
10 | + .option('-t, --temp', 'Use memory instead of filesystem for sharing') | |
10 | 11 | .parse(process.argv); |
11 | 12 | |
12 | 13 | require('ssb-client')((err, sbot) => { |
13 | 14 | if (err) throw err; |
14 | 15 | |
15 | 16 | var shareFolder = program.shareFolder || '/tmp' |
16 | - | |
17 | - console.log("Sharing dat links from:", shareFolder) | |
18 | 17 | |
18 | + if (program.temp) | |
19 | + console.log("Sharing dat links in memory mode instead of filesytem") | |
20 | + else | |
21 | + console.log("Sharing dat links from:", shareFolder) | |
22 | + | |
19 | 23 | if (program.onlyPeopleIFollow) |
20 | - lib.getFromPeopleIFollow(sbot, shareFolder) | |
24 | + lib.getFromPeopleIFollow(sbot, shareFolder, program.temp) | |
21 | 25 | else |
22 | - lib.getAll(sbot, shareFolder) | |
26 | + lib.getAll(sbot, shareFolder, program.temp) | |
23 | 27 | }) |
index.js | ||
---|---|---|
@@ -10,8 +10,8 @@ | ||
10 | 10 | |
11 | 11 | console.log("Sharing dat links from:", shareFolder) |
12 | 12 | |
13 | 13 | if (conf.onlyPeopleIFollow) |
14 | - lib.getFromPeopleIFollow(ssb, shareFolder) | |
14 | + lib.getFromPeopleIFollow(ssb, shareFolder, conf.temp) | |
15 | 15 | else |
16 | - lib.getAll(ssb, shareFolder) | |
16 | + lib.getAll(ssb, shareFolder, conf.temp) | |
17 | 17 | } |
lib.js | ||
---|---|---|
@@ -2,9 +2,9 @@ | ||
2 | 2 | var uri = require('urijs') |
3 | 3 | var pull = require('pull-stream') |
4 | 4 | |
5 | 5 | var self = module.exports = { |
6 | - extractLinksAndSeed: function(err, logs, shareFolder) { | |
6 | + extractLinksAndSeed: function(err, logs, shareFolder, useTemp) { | |
7 | 7 | if (err) throw err; |
8 | 8 | |
9 | 9 | console.log("Found " + logs.length) |
10 | 10 | |
@@ -14,9 +14,10 @@ | ||
14 | 14 | |
15 | 15 | console.log("Saving to:", shareFolder + "/" + datLink.substring(6)) |
16 | 16 | |
17 | 17 | Dat(shareFolder + "/" + datLink.substring(6), { |
18 | - key: datLink | |
18 | + key: datLink, | |
19 | + temp: useTemp | |
19 | 20 | }, function (err, dat) { |
20 | 21 | if (err) throw err |
21 | 22 | |
22 | 23 | console.log("sharing:", datLink) |
@@ -25,9 +26,9 @@ | ||
25 | 26 | }) |
26 | 27 | }) |
27 | 28 | }, |
28 | 29 | |
29 | - getAll: function(sbot, shareFolder) { | |
30 | + getAll: function(sbot, shareFolder, useTemp) { | |
30 | 31 | console.log("Looking for dat links in all feeds") |
31 | 32 | |
32 | 33 | pull( |
33 | 34 | sbot.createLogStream({ live: true, reverse: true, limit: 10000 }), |
@@ -37,15 +38,16 @@ | ||
37 | 38 | typeof msg.value.content.text == "string" && |
38 | 39 | msg.value.content.text.indexOf("dat://") != -1 |
39 | 40 | }), |
40 | 41 | pull.collect((err, logs) => self.extractLinksAndSeed(err, logs, |
41 | - shareFolder)) | |
42 | + shareFolder, | |
43 | + useTemp)) | |
42 | 44 | ) |
43 | 45 | }, |
44 | 46 | |
45 | 47 | messagesFromPeopleIFollow: function(sbot, following, |
46 | 48 | channelSubscriptions, |
47 | - shareFolder) { | |
49 | + shareFolder, useTemp) { | |
48 | 50 | console.log("users:", following) |
49 | 51 | console.log("channels:", channelSubscriptions) |
50 | 52 | pull( |
51 | 53 | sbot.createLogStream({ live: true, reverse: true, limit: 10000 }), |
@@ -57,13 +59,14 @@ | ||
57 | 59 | typeof msg.value.content.text == "string" && |
58 | 60 | msg.value.content.text.indexOf("dat://") != -1) |
59 | 61 | }), |
60 | 62 | pull.collect((err, logs) => self.extractLinksAndSeed(err, logs, |
61 | - shareFolder)) | |
63 | + shareFolder, | |
64 | + useTemp)) | |
62 | 65 | ) |
63 | 66 | }, |
64 | 67 | |
65 | - getFromPeopleIFollow: function(sbot, shareFolder) { | |
68 | + getFromPeopleIFollow: function(sbot, shareFolder, useTemp) { | |
66 | 69 | var following = [] |
67 | 70 | var channelSubscriptions = [] |
68 | 71 | |
69 | 72 | console.log("Looking for dat links in people i follow") |
@@ -96,9 +99,9 @@ | ||
96 | 99 | }) |
97 | 100 | |
98 | 101 | self.messagesFromPeopleIFollow(sbot, following, |
99 | 102 | channelSubscriptions, |
100 | - shareFolder) | |
103 | + shareFolder, useTemp) | |
101 | 104 | }) |
102 | 105 | ) |
103 | 106 | }) |
104 | 107 | } |
Built with git-ssb-web