2023-03-03 16:44:40 +00:00
|
|
|
const Redis = require('ioredis')
|
2023-03-25 17:37:22 +00:00
|
|
|
const fs = require('node:fs')
|
|
|
|
|
2023-03-03 16:44:40 +00:00
|
|
|
const logger = require("./logger.js")
|
|
|
|
|
|
|
|
const redis = new Redis({
|
|
|
|
host: process.env.REDIS_HOST,
|
|
|
|
port: process.env.REDIS_PORT,
|
|
|
|
password: process.env.REDIS_PASS,
|
|
|
|
});
|
|
|
|
|
2023-03-25 13:13:52 +00:00
|
|
|
redis.on('ready', async function () {
|
2023-03-03 16:44:40 +00:00
|
|
|
logger.info({ message: 'Connected to redis!' })
|
2023-03-25 13:13:52 +00:00
|
|
|
|
|
|
|
const keys = await redis.keys('*')
|
|
|
|
const filteredKeys = keys.filter(key => !key.startsWith('blacklist:'))
|
2023-03-25 13:20:43 +00:00
|
|
|
if (filteredKeys.length) await redis.del(filteredKeys)
|
2023-03-25 13:13:52 +00:00
|
|
|
|
2024-01-01 17:23:28 +00:00
|
|
|
setInterval(async () => {
|
|
|
|
const files = fs.readdirSync('videos')
|
|
|
|
const webmFiles = files.filter((file) => file.endsWith('.webm'))
|
|
|
|
webmFiles.forEach(async (f) => {
|
|
|
|
const videoId = f.replace('.webm', '')
|
|
|
|
const isActive = await redis.get(videoId)
|
|
|
|
if (!isActive) {
|
|
|
|
fs.unlinkSync(`./videos/${f}`)
|
|
|
|
logger.info({ message: `deleted file ${f} because there is no active download of it` })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}, 5*60000)
|
2023-03-25 17:37:22 +00:00
|
|
|
})
|
2023-03-03 16:44:40 +00:00
|
|
|
|
|
|
|
module.exports = redis
|