added Docker support with env variables
This commit is contained in:
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@ -0,0 +1,18 @@
|
||||
FROM node:18-alpine
|
||||
|
||||
# Create app directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Install app dependencies
|
||||
# A wildcard is used to ensure both package.json AND package-lock.json are copied
|
||||
# where available (npm@5+)
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
# If you are building your code for production
|
||||
# RUN npm ci --omit=dev
|
||||
|
||||
# Bundle app source
|
||||
COPY . .
|
||||
|
||||
CMD [ "node", "." ]
|
73
index.js
73
index.js
@ -1,59 +1,56 @@
|
||||
const settings = require('./settings.json');
|
||||
const fetch = require('node-fetch');
|
||||
const cache = {};
|
||||
|
||||
const default_headers = {
|
||||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
||||
"accept-language": "en-US,en;q=0.9",
|
||||
"upgrade-insecure-requests": "1",
|
||||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
|
||||
}
|
||||
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
|
||||
'accept-language': 'en-US,en;q=0.9',
|
||||
'upgrade-insecure-requests': '1',
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36',
|
||||
};
|
||||
|
||||
function isFull(t) {
|
||||
return (t.includes("This beta is full.") || t.includes("This beta isn't accepting any new testers right now."));
|
||||
return (t.includes('This beta is full.') || t.includes('This beta isn\'t accepting any new testers right now.'));
|
||||
}
|
||||
|
||||
function getName(t) {
|
||||
return (t.includes("<title>Join the ") ? t.split("<title>Join the ")[1].split(" - TestFlight - Apple</title>")[0] : "App");
|
||||
return (t.includes('<title>Join the ') ? t.split('<title>Join the ')[1].split(' - TestFlight - Apple</title>')[0] : 'App');
|
||||
}
|
||||
|
||||
async function do_request(a, h, m = "GET", d = null) {
|
||||
let r = await fetch(a, {
|
||||
async function do_request(a, h, m = 'GET', d = null) {
|
||||
const r = await fetch(a, {
|
||||
headers: Object.assign(h),
|
||||
method: m,
|
||||
redirect: "manual",
|
||||
body: m == 'POST' ? JSON.stringify(d) : null
|
||||
redirect: 'manual',
|
||||
body: m == 'POST' ? JSON.stringify(d) : null,
|
||||
});
|
||||
return (await r.text());
|
||||
}
|
||||
|
||||
(async() => {
|
||||
console.log(`Watching over ${settings.programs.length} programs`);
|
||||
|
||||
setInterval(() => {
|
||||
console.log("Refreshing now.")
|
||||
settings.programs.forEach(async p => {
|
||||
let r = await do_request("https://testflight.apple.com/join/" + p.id, default_headers);
|
||||
if (!isFull(r)) {
|
||||
if (!cache[p.id]) {
|
||||
let message = getName(r) + " is available at https://testflight.apple.com/join/" + p.id;
|
||||
if (p.url) {
|
||||
await do_request(
|
||||
p.url,
|
||||
Object.assign(default_headers, { "Content-Type": "application/json" }),
|
||||
"POST", {
|
||||
"content": message
|
||||
}
|
||||
)
|
||||
}
|
||||
console.log(message);
|
||||
(async () => {
|
||||
setInterval(async () => {
|
||||
console.log('Refreshing now.');
|
||||
const p = {
|
||||
id: process.env.TESTFLIGHT_ID,
|
||||
url: process.env.DISCORD_WEBHOOK_URL,
|
||||
};
|
||||
const r = await do_request('https://testflight.apple.com/join/' + p.id, default_headers);
|
||||
if (!isFull(r)) {
|
||||
if (!cache[p.id]) {
|
||||
const message = getName(r) + ' is available at https://testflight.apple.com/join/' + p.id;
|
||||
if (p.url) {
|
||||
await do_request(
|
||||
p.url,
|
||||
Object.assign(default_headers, { 'Content-Type': 'application/json' }),
|
||||
'POST', { 'content': message },
|
||||
);
|
||||
}
|
||||
cache[p.id] = true;
|
||||
} else {
|
||||
delete cache[p.id];
|
||||
console.log(getName(r) + " is still full.")
|
||||
console.log(message);
|
||||
}
|
||||
});
|
||||
}, 30000)
|
||||
cache[p.id] = true;
|
||||
} else {
|
||||
delete cache[p.id];
|
||||
console.log(getName(r) + ' is still full.');
|
||||
}
|
||||
}, 30000);
|
||||
|
||||
})();
|
Reference in New Issue
Block a user