2021-12-12 05:10:03 +01:00
|
|
|
const { db, logger } = require('../core')
|
|
|
|
|
|
|
|
async function main() {
|
2022-02-07 05:12:33 +01:00
|
|
|
logger.info(`loading streams...`)
|
|
|
|
await db.streams.load()
|
|
|
|
let streams = await db.streams.find({})
|
2021-12-12 05:10:03 +01:00
|
|
|
|
2022-02-07 05:12:33 +01:00
|
|
|
logger.info(`removing broken links...`)
|
2021-12-12 06:43:43 +01:00
|
|
|
let removed = 0
|
2022-02-07 05:12:33 +01:00
|
|
|
const buffer = {}
|
2021-12-12 06:43:43 +01:00
|
|
|
for (const stream of streams) {
|
2022-02-07 05:12:33 +01:00
|
|
|
const duplicate = buffer[stream.channel_id]
|
2021-12-12 06:43:43 +01:00
|
|
|
if (duplicate && ['offline', 'timeout'].includes(stream.status.code)) {
|
2022-02-07 05:12:33 +01:00
|
|
|
await db.streams.remove({ _id: stream._id })
|
2021-12-12 06:43:43 +01:00
|
|
|
removed++
|
|
|
|
} else {
|
2022-02-07 05:12:33 +01:00
|
|
|
buffer[stream.channel_id] = stream
|
2021-12-12 06:43:43 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-07 05:12:33 +01:00
|
|
|
db.streams.compact()
|
2021-12-12 05:10:03 +01:00
|
|
|
|
2022-02-07 05:12:33 +01:00
|
|
|
logger.info(`removed ${removed} links`)
|
2021-12-12 05:10:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|