-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync.js
32 lines (31 loc) · 934 Bytes
/
sync.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
const Rmoo = require('./index')
const Library = require('./library')
const config = require('./config')
const Promise = require('bluebird')
console.log('Connecting to rclone remote storage')
library = new Library(config)
library.init()
console.log('Initializing rmoo client')
rmoo = new Rmoo(config)
rmoo.init().then(function () {
console.log('Getting rmoo book list')
return rmoo.getLibrary()
}).then(function (response) {
response.included.forEach(function (element, index) {
if (element.type == 'book') library.pushMeta(element)
})
var incomingIds = library.getIncomingIds()
if (incomingIds == 0) {
console.log('No new books available')
process.exit(0)
}
console.log('Downloading', incomingIds.length, 'new books')
return Promise.map(incomingIds, function (id) {
return rmoo.getBookEpub(id)
}, {
concurrency: 2
})
}).then(function () {
library.uploadIncoming()
library.cleanLocal()
})