git ssb

2+

arj / dat-share



Tree: 1b9093405deadf26da6cab9aefb5cdf7ec500421

Files: 1b9093405deadf26da6cab9aefb5cdf7ec500421 / index.js

1131 bytesRaw
1#!/usr/bin/env node
2
3var Dat = require('dat-node')
4var program = require('commander');
5var uri = require('urijs')
6var pull = require('pull-stream')
7
8program
9 .option('-f, --folder [value]', 'Folder for sharing')
10 .parse(process.argv);
11
12require('ssb-client')((err, sbot) => {
13 if (err) throw err;
14
15 console.log("Looking for dat links")
16
17 pull(
18 sbot.createLogStream({ reverse: true, limit: 10000 }),
19 pull.filter((msg) => {
20 return !msg.value ||
21 msg.value.content.type == 'post' &&
22 typeof msg.value.content.text == "string" &&
23 msg.value.content.text.indexOf("dat://") != -1
24 }),
25 pull.collect((err, log) => {
26 if (err) throw err;
27
28 console.log("Found " + log.length)
29
30 log.forEach(msg => {
31 uri.withinString(msg.value.content.text, (datLink) => {
32 if (!datLink.startsWith("dat://")) return
33
34 console.log("Saving to:", program.folder + "/" + datLink.substring(6))
35
36 Dat(program.folder + "/" + datLink.substring(6), {
37 key: datLink
38 }, function (err, dat) {
39 if (err) throw err
40
41 console.log("sharing:", datLink)
42 dat.joinNetwork()
43 })
44 })
45 })
46 })
47 )
48})
49

Built with git-ssb-web