-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (45 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const config = require('./config.json')
const Mastodon = require('mastodon')
const Turndown = require('turndown')
const Shaarli = require('shaarli-client')
const masto = new Mastodon(config.mastodon)
const turndown = new Turndown()
const h2p = require('html2plaintext')
const shaarli = new Shaarli(config.shaarli.url, config.shaarli.secret)
const titleLength = 100
masto.get('favourites', {'limit': 40})
.then((res) => {
let data = res.data.reverse()
let aux = function (k) {
sendStatus(data[k], () => {
k++
if (k < data.length) {
aux(k)
}
})
}
aux(0)
})
let sendStatus = function (status, next) {
let description = turndown.turndown(status.content)
let title = h2p(status.content).substring(0, titleLength)
let params = {
'description': description,
'private': false,
'tags': [],
'title': title,
'url': status.url
}
shaarli.postLink(params, (err, res) => {
if (err) {
if (err.message === 'got 409 response') {
console.log('link already added: ' + status.url)
} else {
throw err
}
} else {
console.log('link added: ' + status.url)
}
next()
})
}