2024-08-06 10:03:42 +08:00
|
|
|
const { createTask } = require('./lib/task')
|
|
|
|
const { fetchVisitorData } = require('./lib/workflow')
|
2024-10-12 01:57:18 -03:00
|
|
|
const { Redis } = require('ioredis')
|
|
|
|
|
|
|
|
const redis = new Redis({ host: process.env.HOST || config.host });
|
|
|
|
|
|
|
|
redis.on('error', (error) => {
|
2024-10-12 02:32:56 -03:00
|
|
|
console.error('Could not connect to Redis:', error);
|
|
|
|
process.exit(1);
|
2024-10-12 01:57:18 -03:00
|
|
|
});
|
2024-08-06 10:03:42 +08:00
|
|
|
|
|
|
|
const generate = async () => {
|
2024-10-12 02:32:56 -03:00
|
|
|
console.debug("[DEBUG] generate called")
|
|
|
|
try {
|
|
|
|
const visitorData = await fetchVisitorData()
|
|
|
|
const task = await createTask(visitorData)
|
|
|
|
const { poToken } = await task.start()
|
|
|
|
return { visitorData, poToken }
|
|
|
|
} catch (e) {
|
|
|
|
console.error(`generate: Error ${e}`)
|
|
|
|
}
|
2024-08-06 10:03:42 +08:00
|
|
|
}
|
|
|
|
|
2024-10-12 01:57:18 -03:00
|
|
|
const run = async () => {
|
|
|
|
try {
|
|
|
|
const { visitorData, poToken } = await generate();
|
2024-10-12 02:32:56 -03:00
|
|
|
redis.set("invidious:po_token", poToken)
|
|
|
|
redis.set("invidious:visitor_data", visitorData)
|
2024-10-12 01:57:18 -03:00
|
|
|
} catch(e) {
|
2024-10-12 02:32:56 -03:00
|
|
|
console.error(`run: Error ${e}`)
|
2024-10-12 01:57:18 -03:00
|
|
|
}
|
|
|
|
console.log("New tokens sent to redis")
|
|
|
|
}
|
|
|
|
|
|
|
|
run();
|
2024-10-12 02:32:56 -03:00
|
|
|
setInterval(run, (process.env.RENEW_INTERVAL || 60) * 1000)
|
2024-10-12 01:57:18 -03:00
|
|
|
|
2024-08-06 10:03:42 +08:00
|
|
|
module.exports = { generate }
|