switching ips
This commit is contained in:
parent
61ba7f4cbf
commit
fa3a9ce85b
58
index.js
58
index.js
|
@ -153,8 +153,8 @@ app.ws('/download/:id/:quality', async (ws, req) => {
|
||||||
let speedInMBps = (videoDownloaded / (1024 * 1024)) / elapsedTime;
|
let speedInMBps = (videoDownloaded / (1024 * 1024)) / elapsedTime;
|
||||||
let remainingTime = (videoTotal - videoDownloaded) / (speedInMBps * 1024 * 1024);
|
let remainingTime = (videoTotal - videoDownloaded) / (speedInMBps * 1024 * 1024);
|
||||||
|
|
||||||
if (videoPrecentages.includes((progress*100).toFixed(0))) continue
|
if (videoPrecentages.includes((progress * 100).toFixed(0))) continue
|
||||||
videoPrecentages.push((progress*100).toFixed(0))
|
videoPrecentages.push((progress * 100).toFixed(0))
|
||||||
|
|
||||||
ws.send(`[video] ${(progress * 100).toFixed(2)}% of ${hr.fromBytes(videoTotal)} at ${speedInMBps.toFixed(2)} MB/s ETA ${secondsToTime(remainingTime.toFixed(0))}`)
|
ws.send(`[video] ${(progress * 100).toFixed(2)}% of ${hr.fromBytes(videoTotal)} at ${speedInMBps.toFixed(2)} MB/s ETA ${secondsToTime(remainingTime.toFixed(0))}`)
|
||||||
}
|
}
|
||||||
|
@ -184,8 +184,8 @@ app.ws('/download/:id/:quality', async (ws, req) => {
|
||||||
let speedInMBps = (audioDownloaded / (1024 * 1024)) / elapsedTime;
|
let speedInMBps = (audioDownloaded / (1024 * 1024)) / elapsedTime;
|
||||||
let remainingTime = (audioTotal - audioDownloaded) / (speedInMBps * 1024 * 1024);
|
let remainingTime = (audioTotal - audioDownloaded) / (speedInMBps * 1024 * 1024);
|
||||||
|
|
||||||
if (audioPrecentages.includes((progress*100).toFixed(0))) continue
|
if (audioPrecentages.includes((progress * 100).toFixed(0))) continue
|
||||||
audioPrecentages.push((progress*100).toFixed(0))
|
audioPrecentages.push((progress * 100).toFixed(0))
|
||||||
|
|
||||||
ws.send(`[audio] ${(progress * 100).toFixed(2)}% of ${hr.fromBytes(audioTotal)} at ${speedInMBps.toFixed(2)} MB/s ETA ${secondsToTime(remainingTime.toFixed(0))}`)
|
ws.send(`[audio] ${(progress * 100).toFixed(2)}% of ${hr.fromBytes(audioTotal)} at ${speedInMBps.toFixed(2)} MB/s ETA ${secondsToTime(remainingTime.toFixed(0))}`)
|
||||||
}
|
}
|
||||||
|
@ -229,6 +229,56 @@ function mergeIt(audioPath, videoPath, outputPath) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function switchIps() {
|
||||||
|
const currentIp = await (await fetch('http://localhost:8000/v1/publicip/ip', {
|
||||||
|
headers: {
|
||||||
|
'X-API-Key': '64d1781e469965c1cdad611b0c05d313'
|
||||||
|
}
|
||||||
|
})).json()
|
||||||
|
const currentDate = new Date()
|
||||||
|
|
||||||
|
console.log(`starting switching ips. ${currentIp.public_ip}, ${currentIp.city}, ${currentIp.region}, ${currentIp.organization}`)
|
||||||
|
|
||||||
|
const s = await fetch('http://localhost:8000/v1/vpn/status', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'X-API-Key': '64d1781e469965c1cdad611b0c05d313',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ status: 'stopped' })
|
||||||
|
})
|
||||||
|
console.log(`stopped vpn - ${await s.text()}`)
|
||||||
|
|
||||||
|
const r = await fetch('http://localhost:8000/v1/vpn/status', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'X-API-Key': '64d1781e469965c1cdad611b0c05d313',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ status: 'running' })
|
||||||
|
})
|
||||||
|
console.log(`turned on vpn - ${await r.text()}`)
|
||||||
|
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
const intervalId = setInterval(async () => {
|
||||||
|
const newIp = await (await fetch('http://localhost:8000/v1/publicip/ip', {
|
||||||
|
headers: {
|
||||||
|
'X-API-Key': '64d1781e469965c1cdad611b0c05d313',
|
||||||
|
},
|
||||||
|
})).json();
|
||||||
|
|
||||||
|
if (newIp.public_ip !== '') {
|
||||||
|
console.log(`finished switching ips. ${newIp.public_ip}, ${newIp.city}, ${newIp.region}, ${newIp.organization}. took ${(new Date().getTime() - currentDate.getTime()) / 1000}s`)
|
||||||
|
clearInterval(intervalId);
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(switchIps, 30 * 60000) // 30 minutes
|
||||||
|
|
||||||
app.listen(8008, () => {
|
app.listen(8008, () => {
|
||||||
console.log('the metadata server is up.')
|
console.log('the metadata server is up.')
|
||||||
|
switchIps()
|
||||||
})
|
})
|
Loading…
Reference in New Issue