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 { updateStreamData } = require('./updateStreams')
const { updateStreamData, updateOtherURLs } = require('./updateStreams')
const { decryptPassword } = require('./password')
const { getUserAccountsCheck, getAllUniqueAccounts, getAllUserAccounts, getUserUniqueAccounts } = require('./getUser')
const { storeAccountToDB } = require('../lib/Accounts')
@ -54,20 +54,19 @@ async function splitURL(url) {
}
async function updateAccounts(userAccounts, data, url) {
try {
let URL = await splitURL(url)
let urlData = 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({
"username": account.username,
"password": account.password,
"userId": account.userId
}, URL.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' })
console.log(`${userAccount.username} - - ${URL.extractedUrl} - Expires ${date}.`)
} catch (error) {
}
await updateStreamData({
"username": account.username,
"password": account.password,
"userId": account.userId
}, 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' })
console.log(`${urlData.extractedUrl}.`)
await updateOtherURLs(account.stream, urlData.extractedUrl)
}
@ -90,191 +89,103 @@ async function addNewAccount(userAccount, data, url) {
}
}
async function urlChecker(userAccounts, urlList) {
// async function urlChecker(userAccounts) {
// 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 {
// let response = await inst.get(url, axiosOptions)
// if (response.data.user_info.auth) {
// await updateAccounts(userAccounts, response.data, url)
// updateCount++
// break
// }
// } catch (error) {
// try {
// if (error.response.status == 403) {
// let response2 = await axios.get(url, axiosOptions)
// if (response2.data.user_info.auth) {
// try {
// await updateAccounts(userAccounts, response2.data, url)
// updateCount++
// break
// } catch (error) {
// continue
// }
// }
// }
// } catch (error) {
// continue
// }
// }
// }
// }
// syncApache()
// return {
// "updatedCount": updateCount,
// "totalAccounts": userAccounts.length
// }
// }
async function urlChecker(userAccounts) {
let ip = await inst.get('http://api.ipify.org')
console.log(ip.data);
// for (let index = 0; index < userAccounts.length; index++) {
// const userAccount = userAccounts[index];
// console.log('account ' + index+1 + ' of ' + userAccounts.length)
// 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(url)
// try {
// let response = await inst.get(url, axiosOptions)
// if (response.data.user_info.auth) {
// updateAccounts(userAccounts, response.data, url)
// console.log(url)
// console.log('New Account Added')
// // syncApache()
// // return true
// continue
// }
// } catch (error) {
// try {
// if (error.response.status == 403) {
// let response2 = await axios.get(url, axiosOptions)
// if (response2.data.user_info.auth) {
// try {
// await updateAccounts(userAccounts, response2.data, url)
// console.log('URL updated')
// continue
// } catch (error) {
// continue
// }
// }
// }
// } catch (error) {
// continue
// }
// }
// }
// }
// }
let updateCount = 0
for (let index = 0; index < urlList.length; index++) {
const url = urlList[index];
console.log(index + 1 + ' of ' + urlList.length + ' urls checked')
try {
let response = await inst.get(url, axiosOptions)
if (response.data.user_info.auth) {
updateAccounts(userAccounts, response.data, url)
console.log('URL updated')
// syncApache()
// return true
continue
}
} catch (error) {
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 {
if (error.response.status == 403) {
let response2 = await axios.get(url, axiosOptions)
if (response2.data.user_info.auth) {
try {
await updateAccounts(userAccounts, response2.data, url)
console.log('URL updated')
continue
} catch (error) {
continue
}
}
let response = await inst.get(url, axiosOptions)
if (response.data.user_info.auth) {
await updateAccounts(userAccounts, response.data, url)
updateCount++
break
}
} catch (error) {
continue
try {
if (error.response.status == 403) {
let response2 = await axios.get(url, axiosOptions)
if (response2.data.user_info.auth) {
try {
await updateAccounts(userAccounts, response2.data, url)
updateCount++
break
} catch (error) {
continue
}
}
}
} catch (error) {
continue
}
}
}
}
return false
syncApache()
return {
"updatedCount": updateCount,
"totalAccounts": userAccounts.length
}
}
// await Promise.all(urlList.map(async (url) => {
// try {
// let response
// 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) {
let start = Date.now()
console.log(start)
@ -296,25 +207,19 @@ async function userCheck(accountData) {
userAccount.urls.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, 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 = {
values = await urlChecker(userAccounts)
if (values.updatedCount > 0) {
return {
"update": true,
"count": updatedCount
"count": values.updatedCount
}
} else {
}
else {
return endresponse = false
}
}
async function accountChecker(accountData, urlList) {
@ -373,7 +278,6 @@ async function singleAccountCheck(accountData) {
module.exports = {
userCheck,
singleAccountCheck,
// allUserCheck
}
// singleAccountCheck({ "username": "Karl0ss01", "password": "YqQjYH9Nzw", "userId": 1, "stream": "Badger" })

View File

@ -10,7 +10,21 @@ async function updateStreamData(userAccount, streamURL, expiaryDate) {
}
}
module.exports = {
updateStreamData
async function updateOtherURLs(streamName, newUrl) {
// 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
}