2018-03-06 17:21:17 +00:00
|
|
|
import fetch from 'node-fetch'
|
2021-07-05 04:19:04 +01:00
|
|
|
import { actions } from './mastodon-data.js'
|
|
|
|
import esMain from 'es-main'
|
2018-03-06 17:21:17 +00:00
|
|
|
|
2018-08-19 22:46:48 +01:00
|
|
|
const numStatuses = actions
|
|
|
|
.map(_ => _.post || _.boost)
|
|
|
|
.filter(Boolean)
|
|
|
|
.filter(_ => _.privacy !== 'direct')
|
|
|
|
.length
|
2018-03-06 17:21:17 +00:00
|
|
|
|
|
|
|
async function waitForMastodonData () {
|
|
|
|
while (true) {
|
|
|
|
try {
|
2019-08-03 21:49:37 +01:00
|
|
|
const json = await ((await fetch('http://127.0.0.1:3000/api/v1/instance')).json())
|
2018-03-06 17:21:17 +00:00
|
|
|
if (json.stats.status_count === numStatuses) {
|
|
|
|
break
|
|
|
|
} else {
|
|
|
|
console.log('Waiting for number of statuses to equal ' +
|
|
|
|
numStatuses + ' (currently ' + json.stats.status_count + ')...')
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.log('Waiting for Mastodon API to be available...')
|
|
|
|
} finally {
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 5000))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('Mastodon data populated')
|
|
|
|
}
|
|
|
|
|
2021-07-05 04:19:04 +01:00
|
|
|
if (esMain(import.meta)) {
|
2018-03-06 17:21:17 +00:00
|
|
|
waitForMastodonData().catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
|
|
|
}
|