update
This commit is contained in:
parent
1863addb17
commit
340fccdf46
@ -1,6 +1,3 @@
|
||||
|
||||
|
||||
|
||||
const { getStreamsNew } = require('../routes/getStreams')
|
||||
|
||||
const { updateStreamData } = require('./updateStreams')
|
||||
@ -15,6 +12,9 @@ const { setExpired } = require('./setExpired')
|
||||
|
||||
const { removeAccountFromDB, storeAccountToDB } = require('../lib/Accounts')
|
||||
|
||||
const axios = require('axios')
|
||||
axios.defaults.timeout = 10000;
|
||||
|
||||
const delay = ms => new Promise(res => setTimeout(res, ms));
|
||||
|
||||
|
||||
@ -23,46 +23,53 @@ async function buildURL(streamURL, username, password) {
|
||||
return url
|
||||
}
|
||||
|
||||
async function splitURL(userAccounts, data, url) {
|
||||
async function splitURL(url) {
|
||||
try {
|
||||
re = /[^/]*\/\/[^/]*/
|
||||
let starturl = url.match(/[^/]*\/\/[^/]*/)[0]
|
||||
let nextbit = url.match(/\/player_api\.php\?username=([\s\S]*)$/)[1]
|
||||
let a = nextbit.split('&password=')
|
||||
let extractedURL = url.match(/[^/]*\/\/[^/]*/)[0]
|
||||
let extractedUserPass = url.match(/\/player_api\.php\?username=([\s\S]*)$/)[1]
|
||||
let UserPass = extractedUserPass.split('&password=')
|
||||
return {
|
||||
"extractedUrl": extractedURL,
|
||||
"username": UserPass[0],
|
||||
"password": UserPass[1]
|
||||
}
|
||||
} catch {
|
||||
|
||||
let account = userAccounts.filter(account => account.username == a[0] && account.passwordDecryped == a[1])[0]
|
||||
}
|
||||
}
|
||||
|
||||
async function updateAccounts(userAccounts, data, url) {
|
||||
try {
|
||||
let URL = await splitURL(url)
|
||||
|
||||
let account = userAccounts.filter(account => account.username == URL.username && account.passwordDecryped == URL.password)[0]
|
||||
|
||||
await updateStreamData({
|
||||
"username": account.username,
|
||||
"password": account.password,
|
||||
"userId": account.userId
|
||||
}, starturl, data.user_info.exp_date)
|
||||
}, 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(`${a[0]} - - ${starturl} - Expires ${date}.`)
|
||||
console.log(`${userAccount.username} - - ${URL.extractedUrl} - Expires ${date}.`)
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
async function addNewAccount(userAccount, data, url) {
|
||||
try {
|
||||
re = /[^/]*\/\/[^/]*/
|
||||
let extractedURL = url.match(/[^/]*\/\/[^/]*/)[0]
|
||||
let extractedUserPass = url.match(/\/player_api\.php\?username=([\s\S]*)$/)[1]
|
||||
let UserPass = extractedUserPass.split('&password=')
|
||||
let URL = await splitURL(url)
|
||||
|
||||
await storeAccountToDB({
|
||||
"username": userAccount.username,
|
||||
"password": userAccount.password,
|
||||
"userId": userAccount.userId,
|
||||
"streamName": userAccount.stream,
|
||||
"streamURL": extractedURL,
|
||||
"streamURL": URL.extractedUrl,
|
||||
"expiryDate": data.user_info.exp_date
|
||||
}, extractedURL, data.user_info.exp_date)
|
||||
}, 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(`${UserPass[0]} - - ${extractedURL} - Expires ${date}.`)
|
||||
console.log(`${userAccount.username} - - ${URL.extractedUrl} - Expires ${date}.`)
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
@ -100,7 +107,7 @@ async function userCheck(accountData) {
|
||||
try {
|
||||
let data = response.data
|
||||
if (data.user_info.auth) {
|
||||
splitURL(userAccounts, data, url)
|
||||
updateAccounts(userAccounts, data, url)
|
||||
return true
|
||||
} else {
|
||||
return true
|
||||
@ -241,9 +248,6 @@ async function singleCheck(accountData) {
|
||||
}
|
||||
}
|
||||
|
||||
const axios = require('axios')
|
||||
axios.defaults.timeout = 10000;
|
||||
|
||||
|
||||
async function singleAccountCheck(accountData) {
|
||||
let endresponse
|
||||
@ -260,9 +264,9 @@ async function singleAccountCheck(accountData) {
|
||||
|
||||
await Promise.all(urlList.map(async (url) => {
|
||||
try {
|
||||
console.log(url)
|
||||
// console.log(url)
|
||||
const response = await axios.get(url)
|
||||
console.log(response)
|
||||
// console.log(response)
|
||||
if (response.status == 200 && response.data !== "") {
|
||||
try {
|
||||
let data = response.data
|
||||
|
@ -17,11 +17,6 @@ router.post('/', async function (req, res, next) {
|
||||
postData.username = postData.username.replace("O", "0")
|
||||
}
|
||||
postData.userId = getUserId(req.auth.user)
|
||||
// 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 ' + req.auth.user)
|
||||
|
Loading…
x
Reference in New Issue
Block a user