new working

This commit is contained in:
Karl 2021-11-19 14:25:42 +00:00
parent e97e8d4462
commit 185b357010
2 changed files with 120 additions and 202 deletions

View File

@ -1,5 +1,5 @@
const { getStreamsNew } = require('../routes/getStreams') const { getStreamsNew } = require('../routes/getStreams')
const { updateStreamData } = require('./updateStreams') const { updateStreamData, updateOtherURLs } = require('./updateStreams')
const { decryptPassword } = require('./password') const { decryptPassword } = require('./password')
const { getUserAccountsCheck, getAllUniqueAccounts, getAllUserAccounts, getUserUniqueAccounts } = require('./getUser') const { getUserAccountsCheck, getAllUniqueAccounts, getAllUserAccounts, getUserUniqueAccounts } = require('./getUser')
const { storeAccountToDB } = require('../lib/Accounts') const { storeAccountToDB } = require('../lib/Accounts')
@ -54,20 +54,19 @@ async function splitURL(url) {
} }
async function updateAccounts(userAccounts, data, url) { async function updateAccounts(userAccounts, data, url) {
try { let urlData = await splitURL(url)
let URL = await splitURL(url)
let account = userAccounts.filter(account => account.username == URL.username && account.passwordDecryped == URL.password)[0] let account = userAccounts.filter(account => account.username == urlData.username && account.passwordDecryped == urlData.password)[0]
await updateStreamData({ await updateStreamData({
"username": account.username, "username": account.username,
"password": account.password, "password": account.password,
"userId": account.userId "userId": account.userId
}, URL.extractedUrl, data.user_info.exp_date) }, urlData.extractedUrl, data.user_info.exp_date)
var date = new Date(data.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }) var date = new Date(data.user_info.exp_date * 1000).toLocaleDateString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
console.log(`${userAccount.username} - - ${URL.extractedUrl} - Expires ${date}.`) console.log(`${urlData.extractedUrl}.`)
} catch (error) {
} await updateOtherURLs(account.stream, urlData.extractedUrl)
} }
@ -90,26 +89,26 @@ async function addNewAccount(userAccount, data, url) {
} }
} }
async function urlChecker(userAccounts, urlList) { // async function urlChecker(userAccounts) {
let ip = await inst.get('http://api.ipify.org') // let ip = await inst.get('http://api.ipify.org')
console.log(ip.data); // console.log(ip.data);
// let updateCount = 0
// for (let index = 0; index < userAccounts.length; index++) { // for (let index = 0; index < userAccounts.length; index++) {
// const userAccount = userAccounts[index]; // const userAccount = userAccounts[index];
// console.log('account ' + index+1 + ' of ' + userAccounts.length) // let count = index + 1
// console.log(count + ' of ' + userAccounts.length + ' ' + userAccount.username)
// for (let index2 = 0; index2 < userAccount.urls.length; index2++) { // for (let index2 = 0; index2 < userAccount.urls.length; index2++) {
// const url = userAccount.urls[index2]; // const url = userAccount.urls[index2];
// console.log('url ' + index2+1 + ' of ' + userAccount.urls.length) // // console.log('url ' + index2 + 1 + ' of ' + userAccount.urls.length)
// // console.log(url) // console.log('.')
// try { // try {
// let response = await inst.get(url, axiosOptions) // let response = await inst.get(url, axiosOptions)
// if (response.data.user_info.auth) { // if (response.data.user_info.auth) {
// updateAccounts(userAccounts, response.data, url) // await updateAccounts(userAccounts, response.data, url)
// console.log(url) // updateCount++
// console.log('New Account Added') // break
// // syncApache()
// // return true
// continue
// } // }
// } catch (error) { // } catch (error) {
// try { // try {
@ -118,8 +117,8 @@ async function urlChecker(userAccounts, urlList) {
// if (response2.data.user_info.auth) { // if (response2.data.user_info.auth) {
// try { // try {
// await updateAccounts(userAccounts, response2.data, url) // await updateAccounts(userAccounts, response2.data, url)
// console.log('URL updated') // updateCount++
// continue // break
// } catch (error) { // } catch (error) {
// continue // continue
// } // }
@ -131,19 +130,34 @@ async function urlChecker(userAccounts, urlList) {
// } // }
// } // }
// } // }
// syncApache()
// return {
// "updatedCount": updateCount,
// "totalAccounts": userAccounts.length
// }
// } // }
for (let index = 0; index < urlList.length; index++) {
const url = urlList[index]; async function urlChecker(userAccounts) {
console.log(index + 1 + ' of ' + urlList.length + ' urls checked') let ip = await inst.get('http://api.ipify.org')
console.log(ip.data);
let updateCount = 0
for (let index = 0; index < userAccounts.length; index++) {
const userAccount = userAccounts[index];
let count = index + 1
console.log(count + ' of ' + userAccounts.length + ' ' + userAccount.username)
for (let index2 = 0; index2 < userAccount.urls.length; index2++) {
const url = userAccount.urls[index2];
// console.log('url ' + index2 + 1 + ' of ' + userAccount.urls.length)
console.log('.')
try { try {
let response = await inst.get(url, axiosOptions) let response = await inst.get(url, axiosOptions)
if (response.data.user_info.auth) { if (response.data.user_info.auth) {
updateAccounts(userAccounts, response.data, url) await updateAccounts(userAccounts, response.data, url)
console.log('URL updated') updateCount++
// syncApache() break
// return true
continue
} }
} catch (error) { } catch (error) {
try { try {
@ -152,8 +166,8 @@ async function urlChecker(userAccounts, urlList) {
if (response2.data.user_info.auth) { if (response2.data.user_info.auth) {
try { try {
await updateAccounts(userAccounts, response2.data, url) await updateAccounts(userAccounts, response2.data, url)
console.log('URL updated') updateCount++
continue break
} catch (error) { } catch (error) {
continue continue
} }
@ -164,116 +178,13 @@ async function urlChecker(userAccounts, urlList) {
} }
} }
} }
return false
} }
syncApache()
// await Promise.all(urlList.map(async (url) => { return {
// try { "updatedCount": updateCount,
// let response "totalAccounts": userAccounts.length
// url }
// response = await inst.get(url, axiosOptions) }
// if (response.status == 200 && response.data !== "") {
// try {
// let data = response.data
// if (data.user_info.auth) {
// console.log('.')
// updateAccounts(userAccounts, data, url)
// return true
// }
// } catch {
// }
// }
// } catch {
// }
// })).then((values) => {
// endresponse = values
// });
// return endresponse
// }
// async function allUserCheck() {
// let start = Date.now()
// console.log(start)
// streamURLS = await getStreamsNew()
// let userAccounts = await getAllUserAccounts()
// userAccounts = userAccounts.map(user => {
// // user.userId = accountData.userId
// user.passwordDecryped = decryptPassword(user.password)
// return user
// })
// urlList = []
// for (let index = 0; index < userAccounts.length; index++) {
// let userAccount = userAccounts[index];
// userAccount.urls = []
// for (let index = 0; index < streamURLS.length; index++) {
// const streamURL = streamURLS[index];
// userAccount.urls.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped))
// urlList.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped))
// }
// }
// values = await urlCheckerNew(userAccounts[3], urlList)
// if (values.includes(true)) {
// let updatedCount = values.filter(function (value) {
// return value === true;
// }).length
// console.log('true ' + updatedCount)
// console.log((Date.now() - start) / 1000)
// return endresponse = {
// "update": true,
// "count": updatedCount
// }
// } else {
// return endresponse = false
// }
// }
// async function allUserCheck() {
// let start = Date.now()
// console.log(start)
// streamURLS = await getStreamsNew()
// let userAccounts = await getAllUserAccounts()
// userAccounts = userAccounts.map(user => {
// // user.userId = accountData.userId
// user.passwordDecryped = decryptPassword(user.password)
// return user
// })
// urlList = []
// for (let index = 0; index < userAccounts.length; index++) {
// let userAccount = userAccounts[index];
// userAccount.urls = []
// for (let index = 0; index < streamURLS.length; index++) {
// const streamURL = streamURLS[index];
// userAccount.urls.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped))
// urlList.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped))
// }
// }
// values = await urlChecker(userAccounts, urlList)
// if (values.includes(true)) {
// let updatedCount = values.filter(function (value) {
// return value === true;
// }).length
// console.log('true ' + updatedCount)
// console.log((Date.now() - start) / 1000)
// return endresponse = {
// "update": true,
// "count": updatedCount
// }
// } else {
// return endresponse = false
// }
// }
async function userCheck(accountData) { async function userCheck(accountData) {
let start = Date.now() let start = Date.now()
@ -296,25 +207,19 @@ async function userCheck(accountData) {
userAccount.urls.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)) userAccount.urls.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped))
urlList.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)) urlList.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped))
} }
userAccount.urls = userAccount.urls.filter(function (e) { return !e.includes('stormtv') && !e.includes('megaott') })
} }
urlList = urlList.filter(function (e) { return !e.includes('stormtv') && !e.includes('megaott') })
values = await urlChecker(userAccounts)
values = await urlChecker(userAccounts, urlList) if (values.updatedCount > 0) {
if (values.includes(true)) { return {
let updatedCount = values.filter(function (value) {
return value === true;
}).length
console.log('true ' + updatedCount)
console.log((Date.now() - start) / 1000)
return endresponse = {
"update": true, "update": true,
"count": updatedCount "count": values.updatedCount
} }
} else { }
else {
return endresponse = false return endresponse = false
} }
} }
async function accountChecker(accountData, urlList) { async function accountChecker(accountData, urlList) {
@ -373,7 +278,6 @@ async function singleAccountCheck(accountData) {
module.exports = { module.exports = {
userCheck, userCheck,
singleAccountCheck, singleAccountCheck,
// allUserCheck
} }
// singleAccountCheck({ "username": "Karl0ss01", "password": "YqQjYH9Nzw", "userId": 1, "stream": "Badger" }) // singleAccountCheck({ "username": "Karl0ss01", "password": "YqQjYH9Nzw", "userId": 1, "stream": "Badger" })

View File

@ -10,7 +10,21 @@ async function updateStreamData(userAccount, streamURL, expiaryDate) {
} }
} }
module.exports = { async function updateOtherURLs(streamName, newUrl) {
updateStreamData // let result
try {
let result = sql.query(`update userAccounts
set userAccounts.streamURL = '${newUrl}'
WHERE userAccounts.stream ='${streamName}'`);
return result
} catch (error) {
console.log(error)
}
}
module.exports = {
updateStreamData,
updateOtherURLs
} }