From d4a025fadd7d4ea6a6ad76bc8769967cd5b45a5a Mon Sep 17 00:00:00 2001 From: Karl Date: Tue, 21 Sep 2021 15:59:29 +0000 Subject: [PATCH] update --- lib/checker.js | 52 +++++++++++++++++++-------------------- routes/addAccount.js | 2 +- routes/getUserAccounts.js | 9 +++++++ 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/lib/checker.js b/lib/checker.js index ba4760d..7eb6c7f 100644 --- a/lib/checker.js +++ b/lib/checker.js @@ -185,32 +185,32 @@ async function newCheck() { // })); // } -async function updateAccounts(userAccount, streamURLS) { - return new Promise(async (resolve, reject) => { - await streamURLS.forEach(async streamURL => { - process.stdout.write('.') - let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped) - console.log('tested url ' + url) - let t = await gotRequest(url) - let body = t.body - if (t.statusCode == 200 && body !== "") { - try { - body = JSON.parse(body) - 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' }) - // process.stdout.write('\n') - console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`) - await updateStreamData(userAccount, streamURL, body.user_info.exp_date) - resolve(true) - } - } catch (error) { - } - } else { - } - }) - reject(userAccount) - }) -} +// async function updateAccounts(userAccount, streamURLS) { +// return new Promise(async (resolve, reject) => { +// await streamURLS.forEach(async streamURL => { +// process.stdout.write('.') +// let url = await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped) +// console.log('tested url ' + url) +// let t = await gotRequest(url) +// let body = t.body +// if (t.statusCode == 200 && body !== "") { +// try { +// body = JSON.parse(body) +// 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' }) +// // process.stdout.write('\n') +// console.log(`${userAccount.username} - ${userAccount.stream} - ${streamURL} - Expires ${date}.`) +// await updateStreamData(userAccount, streamURL, body.user_info.exp_date) +// resolve(true) +// } +// } catch (error) { +// } +// } else { +// } +// }) +// reject(userAccount) +// }) +// } diff --git a/routes/addAccount.js b/routes/addAccount.js index 93fb2ef..2f84b81 100644 --- a/routes/addAccount.js +++ b/routes/addAccount.js @@ -21,7 +21,7 @@ router.post('/', async function (req, res, next) { if (a) { res.send('Account ' + postData.username + ' Added successfully to ' + req.auth.user) } else { - res.send(500); + res.sendStatus(500); } // } }); diff --git a/routes/getUserAccounts.js b/routes/getUserAccounts.js index 9f81623..3530f4b 100644 --- a/routes/getUserAccounts.js +++ b/routes/getUserAccounts.js @@ -16,4 +16,13 @@ router.get('/', async function (req, res, next) { res.send(data) }); +router.get('/count', async function (req, res, next) { + try { + let data = await getUserAccounts(await getUserId(req.auth.user)) + res.json({"streamCount": data.length}) + } catch (error) { + res.sendStatus(500) + } +}); + module.exports = router;