|
@@ -10,6 +10,9 @@ const bodyParser = require('body-parser');
|
|
|
const validator = require('validator');
|
|
|
const API = require('./lib/API');
|
|
|
const mail = require('./notification.js')
|
|
|
+const jsonfile = require('jsonfile')
|
|
|
+const tokenFile = './token.json'
|
|
|
+
|
|
|
|
|
|
let info = {
|
|
|
followers: 99999,
|
|
@@ -22,12 +25,32 @@ let info = {
|
|
|
error: 0
|
|
|
}
|
|
|
|
|
|
+jsonfile.readFile(tokenFile, function (err, obj) {
|
|
|
+ if (err) console.error(err)
|
|
|
+ else {
|
|
|
+ console.dir(obj)
|
|
|
+ obj.access_token = process.env.access_token
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
if (process.env.access_token) {
|
|
|
info.tokens = process.env.access_token
|
|
|
info.active = true
|
|
|
}
|
|
|
+
|
|
|
if (process.env.expire) info.expire = process.env.expire
|
|
|
|
|
|
+function updateTokenEnv(token){
|
|
|
+
|
|
|
+ let reqObj = {"access_token": token}
|
|
|
+
|
|
|
+ jsonfile.writeFile(tokenFile, reqObj, function (err) {
|
|
|
+ if (err) console.error(err)
|
|
|
+ else console.log("Token File updated")
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
async function watchLinkedin(){
|
|
|
|
|
|
if (info.active){
|
|
@@ -50,7 +73,6 @@ async function watchLinkedin(){
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
setInterval(watchLinkedin, info.updateTime)
|
|
@@ -81,6 +103,7 @@ app.get('/callback', async (req, res) => {
|
|
|
info.active = true
|
|
|
process.env.access_token = info.token
|
|
|
process.env.expire = data.expire ? data.expire : 0
|
|
|
+ updateTokenEnv(info.token)
|
|
|
}
|
|
|
res.redirect('/');
|
|
|
} catch(err) {
|