working at the moment

This commit is contained in:
Karl 2021-09-20 16:03:43 +00:00
parent 6eb118ca87
commit 53d150b64e
3 changed files with 51 additions and 49 deletions

View File

@ -139,32 +139,29 @@ async function test(userAccount, streamURLS) {
}) })
} }
function updateAccountDNS(userAccount, streamURLS) { async function updateAccountDNS(userAccount, streamURLS) {
return new Promise((resolve, reject) => { // return new Promise(async (resolve, reject) => {
streamURLS.forEach(async streamURL => { await Promise.all(streamURLS.map(async (streamURL) => {
process.stdout.write('.') process.stdout.write('.')
let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped) let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)
// console.log('tested url ' + url) // console.log('tested url ' + url)
let t = await gotRequest(url) let t = await gotRequest(url)
let body = t.body let body = t.body
if (t.statusCode == 200 && body !== "") { if (t.statusCode == 200 && body !== "") {
try { try {
body = JSON.parse(body) body = JSON.parse(body)
if (body.user_info.auth) { if (body.user_info.auth) {
var date = new Date(body.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }) var date = new Date(body.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
// process.stdout.write('\n') // process.stdout.write('\n')
console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`) console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`)
await updateStreamData(userAccount, streamURL, body.user_info.exp_date) await updateStreamData(userAccount, streamURL, body.user_info.exp_date)
resolve(true) resolve(true)
}
} catch (error) {
// break
} }
} else { } catch (error) {
// resolve(false)
} }
}) } else {
}) }
}));
} }
async function updateAccounts(userAccount, streamURLS) { async function updateAccounts(userAccount, streamURLS) {
@ -205,20 +202,22 @@ async function newUserCheck(accountData) {
return user return user
}) })
try { // try {
for (let i = 0; i < userAccounts.length; ++i) { for (let i = 0; i < userAccounts.length; ++i) {
const userAccount = userAccounts[i]; const userAccount = userAccounts[i];
if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) { if (userAccount.expiaryDate != 123 && Math.round(Date.now() / 1000) > userAccount.expiaryDate) {
setExpired(userAccount) setExpired(userAccount)
} else { } else {
await updateAccountDNS(userAccount, streamURLS) await updateAccountDNS(userAccount, streamURLS)
} // console.log(a)
} }
console.log(Date.now())
return true
} catch (error) {
console.error(error);
} }
console.log(Date.now())
return true
// } catch (error) {
// return true
// console.error(error);
// }
} }
@ -326,7 +325,7 @@ async function newSingleCheck(accountData) {
// "username": 'Karl0ss1709', // "username": 'Karl0ss1709',
// "password": 'YEfbZskEH2Zu', // "password": 'YEfbZskEH2Zu',
// "stream": "Badger", // "stream": "Badger",
// "userId": 1 // "userId": 5
// }) // })

View File

@ -5,19 +5,21 @@ const gotRequest = async (url) => {
let options = { let options = {
timeout: 2000 timeout: 2000
} }
await got(url, options) return new Promise(async (resolve, reject) => {
.then((response) => { await got(url, options)
returnResponse = response; .then((response) => {
}) returnResponse = response;
.catch((error) => { })
returnResponse = typeof error.response !== 'undefined' ? error.response : error; .catch((error) => {
returnResponse = typeof error.response !== 'undefined' ? error.response : error;
if (typeof returnResponse.body === 'string' && returnResponse.body.substring(0, 1) === '{') { if (typeof returnResponse.body === 'string' && returnResponse.body.substring(0, 1) === '{') {
returnResponse.body = JSON.parse(returnResponse.body); returnResponse.body = JSON.parse(returnResponse.body);
} }
}); });
return returnResponse; resolve(returnResponse);
})
}; };
module.exports = { module.exports = {

View File

@ -9,6 +9,7 @@ const { newUserCheck } = require('../lib/checker')
router.get('/', async function (req, res, next) { router.get('/', async function (req, res, next) {
let postData = req.body let postData = req.body
postData.userId = getUserId(req.auth.user) postData.userId = getUserId(req.auth.user)
// postData.userId = 5
a = await newUserCheck(postData) a = await newUserCheck(postData)
if (a) { if (a) {
res.send(200) res.send(200)