aboutsummaryrefslogtreecommitdiff
path: root/contrib/scripts/backup.js
blob: 0b1bf89c786c0381be7bd6faf72eb69d079308b0 (plain) (blame)
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
var argv = require('minimist')(process.argv.slice(2))

if (typeof argv.u !== 'string') {
	console.log('username must be specified (-u ugnich)')
	process.exit(1)
}

var messages = []

function getBlogData(blogUrl, callback) {
	fetch(blogUrl)
		.then(function(res) {
			return res.json()
		})
		.then(function(msgs) {
			msgs.forEach(function(message) {
				messages.push(message)
			})
			if (msgs.length == 20) {
				blog.searchParams.set('before_mid', msgs.slice(-1).pop().mid)
				setTimeout(getBlogData, 1000, blog, callback)
			} else {
				// eslint-disable-next-line promise/no-callback-in-promise
				setTimeout(() => callback(), 0)
			}
		})
		.catch(console.error)
}

var blog = new URL('https://api.juick.com/messages')
blog.searchParams.append('uname', argv.u)

getBlogData(blog, function() {
	console.log(JSON.stringify(messages))
})