Token generator for inv.nadeko.net
All checks were successful
Docker build image / build (push) Successful in 29s
All checks were successful
Docker build image / build (push) Successful in 29s
This commit is contained in:
parent
84770fb410
commit
3a0481112f
1 changed files with 33 additions and 0 deletions
33
index.js
33
index.js
|
@ -3,12 +3,34 @@ const { fetchVisitorData } = require('./lib/workflow')
|
|||
const { Redis } = require('ioredis')
|
||||
|
||||
const redis = new Redis({ host: process.env.HOST || config.host });
|
||||
const sub = new Redis({ host: process.env.HOST || config.host });
|
||||
|
||||
redis.on('error', (error) => {
|
||||
console.error('Could not connect to Redis:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
sub.on('error', (error) => {
|
||||
console.error('Could not connect to Redis:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
sub.subscribe("generate-token", (err, count) => {
|
||||
if (err) {
|
||||
console.error("Failed to subscribe: %s", err.message);
|
||||
} else {
|
||||
console.log(
|
||||
`Subscribed successfully! This client is currently subscribed to ${count} channels.`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
sub.on("message", (channel, user) => {
|
||||
console.log(`${channel}`);
|
||||
console.log(`Generating po_token and visitor_data for ${user}`);
|
||||
userGen(user);
|
||||
});
|
||||
|
||||
const generate = async () => {
|
||||
console.debug("[DEBUG] generate called")
|
||||
try {
|
||||
|
@ -32,6 +54,17 @@ const run = async () => {
|
|||
console.log("New tokens sent to redis")
|
||||
}
|
||||
|
||||
const userGen = async (user) => {
|
||||
try {
|
||||
const { visitorData, poToken } = await generate();
|
||||
redis.set(`invidious:${user}:po_token`, poToken)
|
||||
redis.set(`invidious:${user}:visitor_data`, visitorData)
|
||||
} catch(e) {
|
||||
console.error(`userGen: Error ${e}`)
|
||||
}
|
||||
console.log(`Tokens generated successfully for user: ${user}`)
|
||||
}
|
||||
|
||||
run();
|
||||
setInterval(run, (process.env.RENEW_INTERVAL || 60) * 1000)
|
||||
|
||||
|
|
Loading…
Reference in a new issue