This commit is contained in:
Karl 2021-09-20 19:30:47 +00:00
parent 51e9d71d72
commit 6e235425f9
4 changed files with 64 additions and 19 deletions

View File

@ -147,22 +147,16 @@ async function userCheck(accountData) {
return user
})
// try {
for (let i = 0; i < userAccounts.length; ++i) {
const userAccount = userAccounts[i];
if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) {
setExpired(userAccount)
} else {
await updateAccountDNS(userAccount, streamURLS)
// console.log(a)
}
}
console.log(Date.now())
return true
// } catch (error) {
// return true
// console.error(error);
// }
}
@ -200,8 +194,46 @@ async function singleCheck(accountData) {
}
}
const axios = require('axios')
async function singleAccountCheck(accountData) {
streamURLS = await getStreamsNew()
accountData
urlList = []
for (let index = 0; index < streamURLS.length; index++) {
const streamURL = streamURLS[index];
urlList.push(await buildURL(streamURL, accountData.username, accountData.password))
}
for (let index = 0; index < urlList.length; index++) {
const streamURL = urlList[index];
try {
const response = await axios.get(streamURL)
if (response.status == 200 && response.data !== "") {
try {
let data = response.data
if (data.user_info.auth) {
var date = new Date(data.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
// process.stdout.write('\n')
console.log(`${accountData.username} - ${accountData.stream} - ${streamURL} - Expires ${date}.`)
await updateStreamData(accountData, streamURL, data.user_info.exp_date)
return true
}
} catch (error) {
}
} else {
}
} catch (error) {
}
}
}
module.exports = {
newCheck,
singleCheck,
userCheck
userCheck,
singleAccountCheck
}

13
package-lock.json generated
View File

@ -175,6 +175,14 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz",
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA=="
},
"axios": {
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"requires": {
"follow-redirects": "^1.14.0"
}
},
"babel-runtime": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
@ -572,6 +580,11 @@
"unpipe": "~1.0.0"
}
},
"follow-redirects": {
"version": "1.14.4",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz",
"integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g=="
},
"forever-agent": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",

View File

@ -6,6 +6,7 @@
"start": "node ./bin/www"
},
"dependencies": {
"axios": "^0.21.4",
"bcrypt": "^5.0.0",
"cryptr": "^6.0.2",
"express": "~4.16.1",

View File

@ -3,7 +3,7 @@ var router = express.Router();
const { storeAccountToDB } = require('../lib/Accounts')
const { getUserId } = require('../lib/getUser')
const { singleCheck } = require('../lib/checker')
const { singleAccountCheck } = require('../lib/checker')
@ -17,19 +17,18 @@ router.post('/', async function (req, res, next) {
postData.username = postData.username.replace("O", "0")
}
postData.userId = getUserId(req.auth.user)
let userName = req.auth.user
let result = await storeAccountToDB(postData)
console.log(result)
if (result.affectedRows < 1) {
res.send('Adding account failed')
} else {
a = await singleCheck(postData)
// let result = await storeAccountToDB(postData)
// console.log(result)
// if (result.affectedRows < 1) {
// res.send('Adding account failed')
// } else {
a = await singleAccountCheck(postData)
if (a) {
res.send('Account ' + postData.username + ' Added successfully to ' + userName)
res.send('Account ' + postData.username + ' Added successfully to ' + req.auth.user)
} else {
res.send(500);
}
}
// }
});
module.exports = router;