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