-
Notifications
You must be signed in to change notification settings - Fork 57
/
antiban.ts
68 lines (56 loc) · 1.77 KB
/
antiban.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import axios from 'axios';
// Replace these values with your Heroku app details
const herokuAppName = ''; //App Name // VERY
const herokuApiKey = ''; // Api Key // IMPORTANT
// Set the desired run duration in minutes
const runDurationMinutes = 60; // 1 hour
// Set the desired sleep duration in minutes
const sleepDurationMinutes = 720; // 12 hours
const herokuApiUrl = `https://api.heroku.com/apps/${herokuAppName}/dynos`;
async function startApp() {
try {
const response = await axios.post(
herokuApiUrl,
{
'attach': true,
'env': {},
'formation': 'web',
'headers': { 'Accept': 'application/vnd.heroku+json; version=3' },
'force_no_remote': true
},
{
headers: {
'Accept': 'application/vnd.heroku+json; version=3',
'Content-Type': 'application/json',
'Authorization': `Bearer ${herokuApiKey}`
}
}
);
console.log('App started successfully');
} catch (error) {
console.error('Error starting app:', error);
}
}
async function stopApp() {
try {
const response = await axios.delete(herokuApiUrl, {
headers: {
'Accept': 'application/vnd.heroku+json; version=3',
'Content-Type': 'application/json',
'Authorization': `Bearer ${herokuApiKey}`
}
});
console.log('App stopped successfully');
} catch (error) {
console.error('Error stopping app:', error);
}
}
async function runAndSleep() {
await startApp();
setTimeout(async () => {
await stopApp();
console.log(`App will sleep for ${sleepDurationMinutes} minutes`);
setTimeout(runAndSleep, sleepDurationMinutes * 60 * 1000);
}, runDurationMinutes * 60 * 1000);
}
runAndSleep();